From 26860aeee88a32d320974b9a12e776faca4b0eb1 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sat, 3 Jul 2021 22:41:41 +0200 Subject: [PATCH 1/5] fix virtual overrides --- commanditemmodel.h | 12 ++++++------ mylistview.h | 2 +- providers.h | 27 +++++++++++++-------------- yamlparser.cpp | 4 ---- yamlparser.h | 1 - 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/commanditemmodel.h b/commanditemmodel.h index 796bea5..e21e59d 100644 --- a/commanditemmodel.h +++ b/commanditemmodel.h @@ -41,10 +41,10 @@ class CommandSourceItemModel: public QAbstractListModel public: explicit CommandSourceItemModel(bool useHistory, QObject *parent = 0); - virtual ~CommandSourceItemModel(); + ~CommandSourceItemModel() override; - int rowCount(const QModelIndex &parent=QModelIndex()) const; - QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const; + int rowCount(const QModelIndex &parent=QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override; bool isOutDated() const; const CommandProviderItem *command(const QModelIndex &index) const; @@ -80,7 +80,7 @@ class CommandItemModel: public QSortFilterProxyModel public: explicit CommandItemModel(bool useHistory, QObject *parent = 0); - virtual ~CommandItemModel(); + ~CommandItemModel() override; bool isOutDated() const; const CommandProviderItem *command(const QModelIndex &index) const; @@ -104,8 +104,8 @@ public slots: void clearHistory(); protected: - bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; - bool lessThan(const QModelIndex &left, const QModelIndex &right) const; + bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; + bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; private: int itemType(const QModelIndex &index) const; diff --git a/mylistview.h b/mylistview.h index 9a55937..473397b 100644 --- a/mylistview.h +++ b/mylistview.h @@ -42,7 +42,7 @@ class MyListView : public QListView } protected: - virtual QSize viewportSizeHint() const override + QSize viewportSizeHint() const override { QAbstractItemModel * m = model(); if (m == nullptr) diff --git a/providers.h b/providers.h index afa02c9..96e60da 100644 --- a/providers.h +++ b/providers.h @@ -51,7 +51,6 @@ class CommandProviderItem: public QObject public: CommandProviderItem(): QObject() {} - virtual ~CommandProviderItem() {} virtual bool run() const = 0; virtual bool compare(const QRegExp ®Exp) const = 0; @@ -95,7 +94,7 @@ class CommandProvider: public QObject, public QList public: CommandProvider(); - virtual ~CommandProvider(); + ~CommandProvider() override; virtual void rebuild() {} virtual bool isOutDated() const { return false; } @@ -149,7 +148,7 @@ class AppLinkProvider: public CommandProvider public: AppLinkProvider(); - virtual ~AppLinkProvider(); + ~AppLinkProvider() override; private slots: void update(); @@ -195,7 +194,7 @@ class HistoryProvider: public CommandProvider public: HistoryProvider(); - virtual ~HistoryProvider(); + ~HistoryProvider() override; void AddCommand(const QString &command); void clearHistory(); @@ -218,14 +217,14 @@ class CustomCommandItem: public CommandProviderItem public: CustomCommandItem(CustomCommandProvider *provider); - bool run() const; - bool compare(const QRegExp ®Exp) const; + bool run() const override; + bool compare(const QRegExp ®Exp) const override; QString command() const { return mCommand; } void setCommand(const QString &command); QString exec() const { return mExec; } - virtual unsigned int rank(const QString &pattern) const; + unsigned int rank(const QString &pattern) const override; private: QString mCommand; QString mExec; //!< the expanded executable (full path) @@ -269,9 +268,9 @@ class MathItem: public CommandProviderItem MathItem(); ~MathItem(); - bool run() const; - bool compare(const QRegExp ®Exp) const; - virtual unsigned int rank(const QString &pattern) const; + bool run() const override; + bool compare(const QRegExp ®Exp) const override; + unsigned int rank(const QString &pattern) const override; private: QScopedPointer mParser; mutable QString mCachedInput; @@ -285,7 +284,7 @@ class MathProvider: public CommandProvider public: MathProvider(); - //virtual ~MathProvider(); + //~MathProvider() override; }; #endif @@ -303,9 +302,9 @@ class VirtualBoxItem: public CommandProviderItem VirtualBoxItem(const QString & MachineName , const QIcon & Icon); void setRDEPort (const QString & portNum); - bool run() const; - bool compare(const QRegExp ®Exp) const; - virtual unsigned int rank(const QString &pattern) const; + bool run() const override; + bool compare(const QRegExp ®Exp) const override; + unsigned int rank(const QString &pattern) const override; private: QString m_rdePortNum; }; diff --git a/yamlparser.cpp b/yamlparser.cpp index cf7c04a..b82e997 100644 --- a/yamlparser.cpp +++ b/yamlparser.cpp @@ -38,10 +38,6 @@ YamlParser::YamlParser() state = start; } -YamlParser::~YamlParser() -{ -} - void YamlParser::consumeLine(QString line) { static QRegExp documentStart(QSL("---\\s*(\\[\\]\\s*)?")); diff --git a/yamlparser.h b/yamlparser.h index ca9d2a9..6dedf09 100644 --- a/yamlparser.h +++ b/yamlparser.h @@ -40,7 +40,6 @@ class YamlParser : public QObject Q_OBJECT public: YamlParser(); - virtual ~YamlParser(); void consumeLine(QString line); From 285f8a074b251e5433725d83329d38dedf2029e1 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sat, 3 Jul 2021 22:47:57 +0200 Subject: [PATCH 2/5] cleanup filterAcceptsRow --- commanditemmodel.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/commanditemmodel.cpp b/commanditemmodel.cpp index 9d07e2a..8a6d47f 100644 --- a/commanditemmodel.cpp +++ b/commanditemmodel.cpp @@ -104,14 +104,11 @@ bool CommandItemModel::filterAcceptsRow(int sourceRow, const QModelIndex &source const CommandProviderItem *item = mSourceModel->command(sourceRow); - if (!item) - return false; - - bool accept = item->compare(re); + bool accept = item != nullptr && item->compare(re); if (accept) { //check if CustomCommand can be filtered out (equivalent app link is shown) - const CustomCommandItem * cust_i = qobject_cast(item); + auto cust_i = qobject_cast(item); if (nullptr != cust_i) { for (int i = mSourceModel->rowCount(sourceParent); 0 <= i; --i) From 3f260758cd0a56cbc77245c7941cb72cb4d71848 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sat, 3 Jul 2021 22:48:17 +0200 Subject: [PATCH 3/5] cleanup lessThan --- commanditemmodel.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commanditemmodel.cpp b/commanditemmodel.cpp index 8a6d47f..3bc77ad 100644 --- a/commanditemmodel.cpp +++ b/commanditemmodel.cpp @@ -141,8 +141,8 @@ bool CommandItemModel::lessThan(const QModelIndex &left, const QModelIndex &righ const auto leftItem = mSourceModel->command(left); const auto righItem = mSourceModel->command(right); - HistoryItem const * i_left = dynamic_cast(leftItem); - HistoryItem const * i_right = dynamic_cast(righItem); + auto i_left = qobject_cast(leftItem); + auto i_right = qobject_cast(righItem); if (nullptr != i_left && nullptr == i_right) return mShowHistoryFirst; if (nullptr == i_left && nullptr != i_right) @@ -151,8 +151,8 @@ bool CommandItemModel::lessThan(const QModelIndex &left, const QModelIndex &righ { QRegExp re(filterRegExp()); //Note: -1 should not be returned if the item passed the filter previously - const int pos_left = re.indexIn(i_left->command()); - const int pos_right = re.indexIn(i_right->command()); + int pos_left = re.indexIn(i_left->command()); + int pos_right = re.indexIn(i_right->command()); Q_ASSERT(-1 != pos_left && -1 != pos_right); return pos_left < pos_right || (pos_left == pos_right && QSortFilterProxyModel::lessThan(left, right)); From 8c58ca73a9275dbb9d34cd7e83740d8ac6459f14 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sat, 3 Jul 2021 22:48:33 +0200 Subject: [PATCH 4/5] cleanp itemType --- commanditemmodel.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/commanditemmodel.cpp b/commanditemmodel.cpp index 3bc77ad..206272f 100644 --- a/commanditemmodel.cpp +++ b/commanditemmodel.cpp @@ -177,10 +177,9 @@ int CommandItemModel::itemType(const QModelIndex &index) const { if (index.row() == mSourceModel->customCommandIndex().row()) return 1; - else if (index.row() < mSourceModel->externalProviderStartIndex().row()) + if (index.row() < mSourceModel->externalProviderStartIndex().row()) return 2; - else - return 3; + return 3; } From fe7d6d03fb03dfaf14b2c59fe36eefbdf3fcf193 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Sat, 3 Jul 2021 22:48:49 +0200 Subject: [PATCH 5/5] cleanup data --- commanditemmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commanditemmodel.cpp b/commanditemmodel.cpp index 206272f..1ac7397 100644 --- a/commanditemmodel.cpp +++ b/commanditemmodel.cpp @@ -327,7 +327,7 @@ QVariant CommandSourceItemModel::data(const QModelIndex &index, int role) const if (index.row() >= rowCount()) return QVariant(); - const CommandProviderItem *item = command(index); + auto item = command(index); if (!item) return QVariant();