diff --git a/core/SqlLexer.cpp b/core/SqlLexer.cpp index 66cdf35..62e3036 100644 --- a/core/SqlLexer.cpp +++ b/core/SqlLexer.cpp @@ -269,7 +269,8 @@ bool SqlLexer::parseDollarQuote(int startpos, int &length, BasicTokenType &token out = sr.toString(); return true; } - else if (c.isLetter()) { + + if (c.isLetter()) { // is this a dollar quote? while (true) { c = nextChar(); @@ -281,7 +282,8 @@ bool SqlLexer::parseDollarQuote(int startpos, int &length, BasicTokenType &token out = sr.toString(); return true; } - else if (!c.isLetter()) { + + if (!c.isLetter()) { // ERROR, unallowed character tokentype = BasicTokenType::None; length = m_pos - startpos; diff --git a/core/SqlParser.cpp b/core/SqlParser.cpp index 8ff1ddf..e14e7f0 100644 --- a/core/SqlParser.cpp +++ b/core/SqlParser.cpp @@ -4,7 +4,7 @@ using namespace SqlAst; -Keyword isKeyword(QString symbol) +Keyword isKeyword(const QString &symbol) { static std::unordered_map lookup_map = { { "as", Keyword::As }, @@ -22,8 +22,8 @@ Keyword isKeyword(QString symbol) auto res = lookup_map.find(symbol.toLower().toUtf8().data()); if (res != lookup_map.end()) return res->second; - else - return Keyword::NotAKeyword; + + return Keyword::NotAKeyword; } @@ -41,7 +41,7 @@ void SqlParser::parse() // IF NOT try_reduce(token) // THEN SHIFT // END LOOP - while (1) { + while (true) { SqlToken token = lexer.nextBasicToken(); if (token.ok) { if (token.tokenType == BasicTokenType::Symbol) { diff --git a/core/WorkManager.cpp b/core/WorkManager.cpp index 12d7a0a..05cf95d 100644 --- a/core/WorkManager.cpp +++ b/core/WorkManager.cpp @@ -1,7 +1,7 @@ #include "WorkManager.h" -#include -#include +#include +#include #include #include #include @@ -9,8 +9,8 @@ class WorkManagerImpl: public WorkManager { public: - virtual void addRunnable(QRunnable *runnable) override; - virtual void addWork(Work work) override; + void addRunnable(QRunnable *runnable) override; + void addWork(Work work) override; }; @@ -33,7 +33,7 @@ public: : work(std::move(w)) {} protected: - void run() + void run() final { work(); } diff --git a/core/WorkManager.h b/core/WorkManager.h index 28780ae..c90239d 100644 --- a/core/WorkManager.h +++ b/core/WorkManager.h @@ -12,6 +12,8 @@ public: static std::shared_ptr getWorkManager(); using Work = std::function; + + virtual ~WorkManager() = default; virtual void addRunnable(QRunnable *runnable) = 0; virtual void addWork(Work work) = 0; diff --git a/pglab/ASyncWindow.cpp b/pglab/ASyncWindow.cpp index 1a51c82..ab15bf6 100644 --- a/pglab/ASyncWindow.cpp +++ b/pglab/ASyncWindow.cpp @@ -7,7 +7,7 @@ ASyncWindow::ASyncWindow(QWidget *parent) void ASyncWindow::QueueTask(TSQueue::t_Callable c) { - m_taskQueue.add(c); + m_taskQueue.add(std::move(c)); // Theoretically this needs to be only called if the queue was empty because otherwise it already would // be busy emptying the queue. For now however I think it is safer to call it just to make sure. QMetaObject::invokeMethod(this, "processCallableQueue", Qt::QueuedConnection); // queues on main thread diff --git a/pglab/CodeEditor.cpp b/pglab/CodeEditor.cpp index 02d1c4e..5495ff6 100644 --- a/pglab/CodeEditor.cpp +++ b/pglab/CodeEditor.cpp @@ -111,7 +111,7 @@ void CodeEditor::updateExtraSelections() { QList extraSelections; extraSelections.append(currentLine); - for (auto e : errorMarkers) + for (auto&& e : errorMarkers) extraSelections.append(e); setExtraSelections(extraSelections); diff --git a/pglab/ConnectionList.cpp b/pglab/ConnectionList.cpp index 2f7b48c..a6c8a01 100644 --- a/pglab/ConnectionList.cpp +++ b/pglab/ConnectionList.cpp @@ -82,9 +82,7 @@ QString ConnectionList::iniFileName() } -ConnectionList::ConnectionList() -{ -} +ConnectionList::ConnectionList() = default; size_t ConnectionList::createNew() { @@ -104,7 +102,7 @@ void ConnectionList::remove(size_t idx, size_t count) // remove from password save } -void ConnectionList::deleteFromIni(t_Connections::iterator begin, t_Connections::iterator end) +void ConnectionList::deleteFromIni(const t_Connections::iterator &begin, const t_Connections::iterator &end) { QString file_name = iniFileName(); QSettings settings(file_name, QSettings::IniFormat); @@ -118,7 +116,7 @@ void ConnectionList::load() QString file_name = iniFileName(); QSettings settings(file_name, QSettings::IniFormat); auto groups = settings.childGroups(); - for (auto grp : groups) { + for (auto&& grp : groups) { if (grp == "c_IniGroupSecurity") { // Read security settings diff --git a/pglab/ConnectionList.h b/pglab/ConnectionList.h index 38e974e..2cd8a9c 100644 --- a/pglab/ConnectionList.h +++ b/pglab/ConnectionList.h @@ -46,7 +46,7 @@ private: using t_Connections = std::vector; t_Connections m_connections; - void deleteFromIni(t_Connections::iterator begin, t_Connections::iterator end); + void deleteFromIni(const t_Connections::iterator &begin, const t_Connections::iterator &end); static QString iniFileName(); }; diff --git a/pglab/ConnectionListModel.cpp b/pglab/ConnectionListModel.cpp index 4449609..051e661 100644 --- a/pglab/ConnectionListModel.cpp +++ b/pglab/ConnectionListModel.cpp @@ -12,9 +12,7 @@ ConnectionListModel::ConnectionListModel(ConnectionList *conns, QObject *parent) { } -ConnectionListModel::~ConnectionListModel() -{ -} +ConnectionListModel::~ConnectionListModel() = default; int ConnectionListModel::rowCount(const QModelIndex &parent) const { @@ -145,9 +143,7 @@ Expected ConnectionListModel::get(size_t row) if (row < m_connections->size()) { return m_connections->getConfigByIdx(row); } - else { - return Expected::fromException(std::out_of_range("Invalid row")); - } + return Expected::fromException(std::out_of_range("Invalid row")); } diff --git a/pglab/EditColumnTableModel.cpp b/pglab/EditColumnTableModel.cpp index 7705724..2f9d51c 100644 --- a/pglab/EditColumnTableModel.cpp +++ b/pglab/EditColumnTableModel.cpp @@ -43,7 +43,7 @@ int EditColumnTableModel::columnCount(const QModelIndex &) const QVariant EditColumnTableModel::data(const QModelIndex &index, int role) const { - size_t rij = static_cast(index.row()); + auto rij = static_cast(index.row()); auto && d = m_data.at(rij); if (role == Qt::EditRole || role == Qt::DisplayRole) { switch (index.column()) { @@ -90,7 +90,7 @@ Qt::ItemFlags EditColumnTableModel::flags(const QModelIndex &) const bool EditColumnTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { - size_t rij = static_cast(index.row()); + auto rij = static_cast(index.row()); auto && d = m_data.at(rij); if (role == Qt::EditRole) { const int col = index.column(); @@ -98,39 +98,39 @@ bool EditColumnTableModel::setData(const QModelIndex &index, const QVariant &val d.name = value.toString(); return true; } - else if (col == TypeCol) { + if (col == TypeCol) { d.type = value.toUInt(); return true; } - else if (col == LengthCol) { + if (col == LengthCol) { d.length = value.toInt(); return true; } - else if (col == ScaleCol) { + if (col == ScaleCol) { d.scale = value.toInt(); return true; } - else if (col == CollateCol) { + if (col == CollateCol) { d.collate = value.toUInt(); return true; } - else if (col == NotNullCol) { + if (col == NotNullCol) { d.notNull = value.toBool(); return true; } - else if (col == DefaultCol) { + if (col == DefaultCol) { d.def = value.toString(); return true; } - else if (col == PrimaryKeyCol) { + if (col == PrimaryKeyCol) { d.primaryKey = value.toInt(); return true; } - else if (col == UniqueCol) { + if (col == UniqueCol) { d.notNull = value.toBool(); return true; } - else if (col == CommentCol) { + if (col == CommentCol) { d.comment = value.toString(); return true; } @@ -138,7 +138,7 @@ bool EditColumnTableModel::setData(const QModelIndex &index, const QVariant &val return false; } -bool EditColumnTableModel::removeRows(int row, int count, const QModelIndex &parent) +bool EditColumnTableModel::removeRows(int , int , const QModelIndex &) { return false; } diff --git a/pglab/IconColumnDelegate.cpp b/pglab/IconColumnDelegate.cpp index c095e96..982e97e 100644 --- a/pglab/IconColumnDelegate.cpp +++ b/pglab/IconColumnDelegate.cpp @@ -15,7 +15,7 @@ void IconColumnDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op const QModelIndex &index) const { if (index.data().canConvert()) { - QString icon_name = qvariant_cast(index.data()); + auto icon_name = qvariant_cast(index.data()); QIcon* icon = IconColumnDelegate::getIcon(icon_name); @@ -51,7 +51,7 @@ QIcon* IconColumnDelegate::getIcon(const QString &name) const auto fr = m_Icons.find(name); if (fr == m_Icons.end()) { // load and insert icon - QIcon *icon = new QIcon(name); + auto icon = new QIcon(name); fr = m_Icons.emplace(name, icon).first; } return fr->second; diff --git a/pglab/Module.cpp b/pglab/Module.cpp index dcba800..58d3148 100644 --- a/pglab/Module.cpp +++ b/pglab/Module.cpp @@ -17,10 +17,7 @@ ModuleRegistry& Leon::GetModuleRegistry() return registry; } -Module::Module() -{ - -} +Module::Module() = default; ModuleInstance::ModuleInstance() { diff --git a/pglab/NamespaceItemModel.cpp b/pglab/NamespaceItemModel.cpp index 143c0fd..59e45df 100644 --- a/pglab/NamespaceItemModel.cpp +++ b/pglab/NamespaceItemModel.cpp @@ -8,7 +8,7 @@ namespace NamespaceItemModel_impl { class Node { public: - virtual ~Node() {} + virtual ~Node() = default; virtual int getRowCount() const = 0; virtual Qt::CheckState getCheckState() const = 0; virtual void setChecked(NamespaceItemModel *model, const QModelIndex &index, bool checked) = 0; @@ -28,24 +28,24 @@ namespace NamespaceItemModel_impl { , ns(nspace) {} - virtual int getRowCount() const override + int getRowCount() const override { return 0; } - virtual Qt::CheckState getCheckState() const override + Qt::CheckState getCheckState() const override { return checked ? Qt::Checked : Qt::Unchecked; } - virtual void setChecked(NamespaceItemModel *model, const QModelIndex &index, bool chk) override + void setChecked(NamespaceItemModel *model, const QModelIndex &index, bool chk) override { checked = chk; emit model->dataChanged(index, index); emit model->dataChanged(index.parent(), index.parent()); } - virtual QVariant data(const QModelIndex &/*index*/, int role) const override + QVariant data(const QModelIndex &/*index*/, int role) const override { QVariant v; if (role == Qt::DisplayRole) { @@ -76,7 +76,7 @@ namespace NamespaceItemModel_impl { : name(n) {} - virtual int getRowCount() const override + int getRowCount() const override { return leaves.size(); } @@ -87,11 +87,11 @@ namespace NamespaceItemModel_impl { [] (auto l, auto r) -> bool { return *l < *r; }); } - virtual Qt::CheckState getCheckState() const override + Qt::CheckState getCheckState() const override { bool some_checked = false; bool some_unchecked = false; - for (auto l : leaves) { + for (auto&& l : leaves) { if (l->checked) some_checked = true; else @@ -108,19 +108,19 @@ namespace NamespaceItemModel_impl { return result; } - virtual void setChecked(NamespaceItemModel *model, const QModelIndex &index, bool chk) override + void setChecked(NamespaceItemModel *model, const QModelIndex &index, bool chk) override { if (chk) - for (auto l : leaves) + for (auto&& l : leaves) l->checked = true; if (!chk) - for (auto l : leaves) + for (auto&& l : leaves) l->checked = false; emit model->dataChanged(index, index); emit model->dataChanged(model->index(0, 0, index), model->index(leaves.size(), 0, index)); } - virtual QVariant data(const QModelIndex &/*index*/, int role) const override + QVariant data(const QModelIndex &/*index*/, int role) const override { QVariant v; if (role == Qt::DisplayRole) { @@ -152,7 +152,7 @@ void NamespaceItemModel::init(std::shared_ptr ns) auto user = std::make_shared("User"); groups = { system, user }; - for (const auto e : *ns) + for (auto&& e : *ns) if (e.isSystemCatalog()) system->leaves.push_back(std::make_shared(system, e)); else @@ -160,7 +160,7 @@ void NamespaceItemModel::init(std::shared_ptr ns) system->sortLeaves(); user->sortLeaves(); - for (auto e : user->leaves) + for (auto&& e : user->leaves) e->checked = true; } @@ -188,8 +188,8 @@ QModelIndex NamespaceItemModel::parent(const QModelIndex &index) const { QModelIndex result; if (index.isValid()) { - auto *n = static_cast(index.internalPointer()); - LeafNode *ln = dynamic_cast(n); + auto n = static_cast(index.internalPointer()); + auto ln = dynamic_cast(n); if (ln) { // leafnode auto grp = ln->parent.lock(); // Get the parent group auto fr = std::find(groups.begin(), groups.end(), grp); // find it in the list diff --git a/pglab/OpenDatabase.cpp b/pglab/OpenDatabase.cpp index a942ad3..445224a 100644 --- a/pglab/OpenDatabase.cpp +++ b/pglab/OpenDatabase.cpp @@ -22,9 +22,7 @@ OpenDatabase::OpenDatabase(const ConnectionConfig& cfg) { } -OpenDatabase::~OpenDatabase() -{ -} +OpenDatabase::~OpenDatabase() = default; bool OpenDatabase::Init() { diff --git a/pglab/ParamTypeDelegate.cpp b/pglab/ParamTypeDelegate.cpp index cb8be12..b31a47f 100644 --- a/pglab/ParamTypeDelegate.cpp +++ b/pglab/ParamTypeDelegate.cpp @@ -3,11 +3,9 @@ #include #include "model/TypeSelectionItemModel.h" -ParamTypeDelegate::ParamTypeDelegate() -{} +ParamTypeDelegate::ParamTypeDelegate() = default; -ParamTypeDelegate::~ParamTypeDelegate() -{} +ParamTypeDelegate::~ParamTypeDelegate() = default; void ParamTypeDelegate::setTypeSelectionModel(TypeSelectionItemModel* model) { @@ -21,7 +19,7 @@ QWidget *ParamTypeDelegate::createEditor(QWidget *parent, { QWidget *w = nullptr; - QComboBox *cmbbx = new QComboBox(parent); + auto cmbbx = new QComboBox(parent); cmbbx->setMaxVisibleItems(32); cmbbx->setModel(m_typeSelectionModel); w = cmbbx;