• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hluk / CopyQ / #4015

17 Oct 2023 06:08AM CUT coverage: 74.296% (-0.1%) from 74.4%
#4015

push

travis-ci

web-flow
itemfakevim: fix build with qt 6.6.0 (#2508)

Reference: https://github.com/qt-creator/qt-creator/commit/e56e3b6f3

18429 of 24805 relevant lines covered (74.3%)

24531.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/gui/addcommanddialog.cpp
1
// SPDX-License-Identifier: GPL-3.0-or-later
2

3
#include "addcommanddialog.h"
4
#include "ui_addcommanddialog.h"
5

6
#include "common/command.h"
7
#include "common/mimetypes.h"
8
#include "common/predefinedcommands.h"
9
#include "common/shortcuts.h"
10
#include "common/textdata.h"
11
#include "item/itemfactory.h"
12
#include "gui/iconfactory.h"
13
#include "gui/icons.h"
14
#include "gui/windowgeometryguard.h"
15
#include "platform/platformnativeinterface.h"
16

17
#include <QAbstractListModel>
18
#include <QLocale>
19
#include <QSortFilterProxyModel>
20

21
namespace {
22

23
class CommandModel final : public QAbstractListModel {
24
public:
25
    explicit CommandModel(const QVector<Command> &commands, QObject *parent = nullptr)
×
26
        : QAbstractListModel(parent)
×
27
        , m_commands(commands)
×
28
    {
29
    }
30

31
    int rowCount(const QModelIndex &) const override
×
32
    {
33
        return m_commands.size();
×
34
    }
35

36
    QVariant data(const QModelIndex &index, int role) const override
×
37
    {
38
        if (!index.isValid())
×
39
            return QVariant();
×
40

41
        if (role == Qt::DecorationRole) {
×
42
            const QString &icon = m_commands[index.row()].icon;
×
43

44
            QVariant iconOrIconId;
×
45
            if (icon.size() == 1)
×
46
                iconOrIconId = static_cast<uint>(icon[0].unicode());
×
47
            else
48
                iconOrIconId = QIcon(icon);
×
49

50
            return getIcon(iconOrIconId);
×
51
        }
52
        if (role == Qt::DisplayRole)
×
53
            return m_commands[index.row()].name;
×
54
        if (role == Qt::UserRole)
×
55
            return QVariant::fromValue(m_commands[index.row()]);
×
56

57
        return QVariant();
×
58
    }
59

60
private:
61
    QVector<Command> m_commands;
62
};
63

64
} // namespace
65

66
AddCommandDialog::AddCommandDialog(const QVector<Command> &pluginCommands, QWidget *parent)
×
67
    : QDialog(parent)
68
    , ui(new Ui::AddCommandDialog)
×
69
    , m_filterModel(new QSortFilterProxyModel(this))
×
70
{
71
    ui->setupUi(this);
×
72

73
    connect(ui->lineEditFilter, &QLineEdit::textChanged,
×
74
            this, &AddCommandDialog::onLineEditFilterTextChanged);
75
    connect(ui->listViewCommands, &QListView::activated,
×
76
            this, &AddCommandDialog::onListViewCommandsActivated);
77

78
    QAbstractItemModel *model = new CommandModel(predefinedCommands() + pluginCommands, m_filterModel);
×
79
    m_filterModel->setSourceModel(model);
×
80
    ui->listViewCommands->setModel(m_filterModel);
×
81
    ui->listViewCommands->setCurrentIndex(m_filterModel->index(0, 0));
×
82

83
    WindowGeometryGuard::create(this);
×
84
}
85

86
AddCommandDialog::~AddCommandDialog()
×
87
{
88
    delete ui;
×
89
}
90

×
91
void AddCommandDialog::accept()
92
{
93
    const QModelIndexList indexes =
94
            ui->listViewCommands->selectionModel()->selectedIndexes();
×
95

96
    if (!indexes.isEmpty()) {
×
97
        QVector<Command> commands;
98

99
        commands.reserve( indexes.size() );
×
100
        for (const auto &index : indexes)
101
            commands.append( index.data(Qt::UserRole).value<Command>() );
102

×
103
        emit addCommands(commands);
104
    }
×
105

×
106
    QDialog::accept();
107
}
×
108

×
109
void AddCommandDialog::onLineEditFilterTextChanged(const QString &text)
×
110
{
111
#if QT_VERSION >= QT_VERSION_CHECK(5,12,0)
×
112
    const QRegularExpression re(text, QRegularExpression::CaseInsensitiveOption);
113
    m_filterModel->setFilterRegularExpression(re);
114
#else
×
115
    const QRegExp re(text, Qt::CaseInsensitive);
116
    m_filterModel->setFilterRegExp(re);
117
#endif
×
118
}
119

120
void AddCommandDialog::onListViewCommandsActivated()
×
121
{
×
122
    accept();
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc