Several fixes of warnings/clang tidy

This commit is contained in:
eelke 2018-12-16 15:38:32 +01:00
parent 2f527a8380
commit 880903db5f
15 changed files with 58 additions and 67 deletions

View file

@ -269,7 +269,8 @@ bool SqlLexer::parseDollarQuote(int startpos, int &length, BasicTokenType &token
out = sr.toString(); out = sr.toString();
return true; return true;
} }
else if (c.isLetter()) {
if (c.isLetter()) {
// is this a dollar quote? // is this a dollar quote?
while (true) { while (true) {
c = nextChar(); c = nextChar();
@ -281,7 +282,8 @@ bool SqlLexer::parseDollarQuote(int startpos, int &length, BasicTokenType &token
out = sr.toString(); out = sr.toString();
return true; return true;
} }
else if (!c.isLetter()) {
if (!c.isLetter()) {
// ERROR, unallowed character // ERROR, unallowed character
tokentype = BasicTokenType::None; tokentype = BasicTokenType::None;
length = m_pos - startpos; length = m_pos - startpos;

View file

@ -4,7 +4,7 @@
using namespace SqlAst; using namespace SqlAst;
Keyword isKeyword(QString symbol) Keyword isKeyword(const QString &symbol)
{ {
static std::unordered_map<std::string, Keyword> lookup_map = { static std::unordered_map<std::string, Keyword> lookup_map = {
{ "as", Keyword::As }, { "as", Keyword::As },
@ -22,7 +22,7 @@ Keyword isKeyword(QString symbol)
auto res = lookup_map.find(symbol.toLower().toUtf8().data()); auto res = lookup_map.find(symbol.toLower().toUtf8().data());
if (res != lookup_map.end()) if (res != lookup_map.end())
return res->second; return res->second;
else
return Keyword::NotAKeyword; return Keyword::NotAKeyword;
} }
@ -41,7 +41,7 @@ void SqlParser::parse()
// IF NOT try_reduce(token) // IF NOT try_reduce(token)
// THEN SHIFT // THEN SHIFT
// END LOOP // END LOOP
while (1) { while (true) {
SqlToken token = lexer.nextBasicToken(); SqlToken token = lexer.nextBasicToken();
if (token.ok) { if (token.ok) {
if (token.tokenType == BasicTokenType::Symbol) { if (token.tokenType == BasicTokenType::Symbol) {

View file

@ -1,7 +1,7 @@
#include "WorkManager.h" #include "WorkManager.h"
#include <QRunnable.h> #include <QRunnable>
#include <QThreadPool.h> #include <QThreadPool>
#include <deque> #include <deque>
#include <functional> #include <functional>
#include <mutex> #include <mutex>
@ -9,8 +9,8 @@
class WorkManagerImpl: public WorkManager { class WorkManagerImpl: public WorkManager {
public: public:
virtual void addRunnable(QRunnable *runnable) override; void addRunnable(QRunnable *runnable) override;
virtual void addWork(Work work) override; void addWork(Work work) override;
}; };
@ -33,7 +33,7 @@ public:
: work(std::move(w)) : work(std::move(w))
{} {}
protected: protected:
void run() void run() final
{ {
work(); work();
} }

View file

@ -12,6 +12,8 @@ public:
static std::shared_ptr<WorkManager> getWorkManager(); static std::shared_ptr<WorkManager> getWorkManager();
using Work = std::function<void()>; using Work = std::function<void()>;
virtual ~WorkManager() = default;
virtual void addRunnable(QRunnable *runnable) = 0; virtual void addRunnable(QRunnable *runnable) = 0;
virtual void addWork(Work work) = 0; virtual void addWork(Work work) = 0;

View file

@ -7,7 +7,7 @@ ASyncWindow::ASyncWindow(QWidget *parent)
void ASyncWindow::QueueTask(TSQueue::t_Callable c) 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 // 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. // 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 QMetaObject::invokeMethod(this, "processCallableQueue", Qt::QueuedConnection); // queues on main thread

View file

@ -111,7 +111,7 @@ void CodeEditor::updateExtraSelections()
{ {
QList<QTextEdit::ExtraSelection> extraSelections; QList<QTextEdit::ExtraSelection> extraSelections;
extraSelections.append(currentLine); extraSelections.append(currentLine);
for (auto e : errorMarkers) for (auto&& e : errorMarkers)
extraSelections.append(e); extraSelections.append(e);
setExtraSelections(extraSelections); setExtraSelections(extraSelections);

View file

@ -82,9 +82,7 @@ QString ConnectionList::iniFileName()
} }
ConnectionList::ConnectionList() ConnectionList::ConnectionList() = default;
{
}
size_t ConnectionList::createNew() size_t ConnectionList::createNew()
{ {
@ -104,7 +102,7 @@ void ConnectionList::remove(size_t idx, size_t count)
// remove from password save // 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(); QString file_name = iniFileName();
QSettings settings(file_name, QSettings::IniFormat); QSettings settings(file_name, QSettings::IniFormat);
@ -118,7 +116,7 @@ void ConnectionList::load()
QString file_name = iniFileName(); QString file_name = iniFileName();
QSettings settings(file_name, QSettings::IniFormat); QSettings settings(file_name, QSettings::IniFormat);
auto groups = settings.childGroups(); auto groups = settings.childGroups();
for (auto grp : groups) { for (auto&& grp : groups) {
if (grp == "c_IniGroupSecurity") { if (grp == "c_IniGroupSecurity") {
// Read security settings // Read security settings

View file

@ -46,7 +46,7 @@ private:
using t_Connections = std::vector<ConnectionConfig>; using t_Connections = std::vector<ConnectionConfig>;
t_Connections m_connections; 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(); static QString iniFileName();
}; };

View file

@ -12,9 +12,7 @@ ConnectionListModel::ConnectionListModel(ConnectionList *conns, QObject *parent)
{ {
} }
ConnectionListModel::~ConnectionListModel() ConnectionListModel::~ConnectionListModel() = default;
{
}
int ConnectionListModel::rowCount(const QModelIndex &parent) const int ConnectionListModel::rowCount(const QModelIndex &parent) const
{ {
@ -145,10 +143,8 @@ Expected<ConnectionConfig> ConnectionListModel::get(size_t row)
if (row < m_connections->size()) { if (row < m_connections->size()) {
return m_connections->getConfigByIdx(row); return m_connections->getConfigByIdx(row);
} }
else {
return Expected<ConnectionConfig>::fromException(std::out_of_range("Invalid row")); return Expected<ConnectionConfig>::fromException(std::out_of_range("Invalid row"));
} }
}
#include <boost/assert.hpp> #include <boost/assert.hpp>

View file

@ -43,7 +43,7 @@ int EditColumnTableModel::columnCount(const QModelIndex &) const
QVariant EditColumnTableModel::data(const QModelIndex &index, int role) const QVariant EditColumnTableModel::data(const QModelIndex &index, int role) const
{ {
size_t rij = static_cast<size_t>(index.row()); auto rij = static_cast<size_t>(index.row());
auto && d = m_data.at(rij); auto && d = m_data.at(rij);
if (role == Qt::EditRole || role == Qt::DisplayRole) { if (role == Qt::EditRole || role == Qt::DisplayRole) {
switch (index.column()) { 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) bool EditColumnTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
{ {
size_t rij = static_cast<size_t>(index.row()); auto rij = static_cast<size_t>(index.row());
auto && d = m_data.at(rij); auto && d = m_data.at(rij);
if (role == Qt::EditRole) { if (role == Qt::EditRole) {
const int col = index.column(); const int col = index.column();
@ -98,39 +98,39 @@ bool EditColumnTableModel::setData(const QModelIndex &index, const QVariant &val
d.name = value.toString(); d.name = value.toString();
return true; return true;
} }
else if (col == TypeCol) { if (col == TypeCol) {
d.type = value.toUInt(); d.type = value.toUInt();
return true; return true;
} }
else if (col == LengthCol) { if (col == LengthCol) {
d.length = value.toInt(); d.length = value.toInt();
return true; return true;
} }
else if (col == ScaleCol) { if (col == ScaleCol) {
d.scale = value.toInt(); d.scale = value.toInt();
return true; return true;
} }
else if (col == CollateCol) { if (col == CollateCol) {
d.collate = value.toUInt(); d.collate = value.toUInt();
return true; return true;
} }
else if (col == NotNullCol) { if (col == NotNullCol) {
d.notNull = value.toBool(); d.notNull = value.toBool();
return true; return true;
} }
else if (col == DefaultCol) { if (col == DefaultCol) {
d.def = value.toString(); d.def = value.toString();
return true; return true;
} }
else if (col == PrimaryKeyCol) { if (col == PrimaryKeyCol) {
d.primaryKey = value.toInt(); d.primaryKey = value.toInt();
return true; return true;
} }
else if (col == UniqueCol) { if (col == UniqueCol) {
d.notNull = value.toBool(); d.notNull = value.toBool();
return true; return true;
} }
else if (col == CommentCol) { if (col == CommentCol) {
d.comment = value.toString(); d.comment = value.toString();
return true; return true;
} }
@ -138,7 +138,7 @@ bool EditColumnTableModel::setData(const QModelIndex &index, const QVariant &val
return false; return false;
} }
bool EditColumnTableModel::removeRows(int row, int count, const QModelIndex &parent) bool EditColumnTableModel::removeRows(int , int , const QModelIndex &)
{ {
return false; return false;
} }

View file

@ -15,7 +15,7 @@ void IconColumnDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
const QModelIndex &index) const const QModelIndex &index) const
{ {
if (index.data().canConvert<QString>()) { if (index.data().canConvert<QString>()) {
QString icon_name = qvariant_cast<QString>(index.data()); auto icon_name = qvariant_cast<QString>(index.data());
QIcon* icon = IconColumnDelegate::getIcon(icon_name); QIcon* icon = IconColumnDelegate::getIcon(icon_name);
@ -51,7 +51,7 @@ QIcon* IconColumnDelegate::getIcon(const QString &name) const
auto fr = m_Icons.find(name); auto fr = m_Icons.find(name);
if (fr == m_Icons.end()) { if (fr == m_Icons.end()) {
// load and insert icon // load and insert icon
QIcon *icon = new QIcon(name); auto icon = new QIcon(name);
fr = m_Icons.emplace(name, icon).first; fr = m_Icons.emplace(name, icon).first;
} }
return fr->second; return fr->second;

View file

@ -17,10 +17,7 @@ ModuleRegistry& Leon::GetModuleRegistry()
return registry; return registry;
} }
Module::Module() Module::Module() = default;
{
}
ModuleInstance::ModuleInstance() ModuleInstance::ModuleInstance()
{ {

View file

@ -8,7 +8,7 @@ namespace NamespaceItemModel_impl {
class Node { class Node {
public: public:
virtual ~Node() {} virtual ~Node() = default;
virtual int getRowCount() const = 0; virtual int getRowCount() const = 0;
virtual Qt::CheckState getCheckState() const = 0; virtual Qt::CheckState getCheckState() const = 0;
virtual void setChecked(NamespaceItemModel *model, const QModelIndex &index, bool checked) = 0; virtual void setChecked(NamespaceItemModel *model, const QModelIndex &index, bool checked) = 0;
@ -28,24 +28,24 @@ namespace NamespaceItemModel_impl {
, ns(nspace) , ns(nspace)
{} {}
virtual int getRowCount() const override int getRowCount() const override
{ {
return 0; return 0;
} }
virtual Qt::CheckState getCheckState() const override Qt::CheckState getCheckState() const override
{ {
return checked ? Qt::Checked : Qt::Unchecked; 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; checked = chk;
emit model->dataChanged(index, index); emit model->dataChanged(index, index);
emit model->dataChanged(index.parent(), index.parent()); 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; QVariant v;
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
@ -76,7 +76,7 @@ namespace NamespaceItemModel_impl {
: name(n) : name(n)
{} {}
virtual int getRowCount() const override int getRowCount() const override
{ {
return leaves.size(); return leaves.size();
} }
@ -87,11 +87,11 @@ namespace NamespaceItemModel_impl {
[] (auto l, auto r) -> bool { return *l < *r; }); [] (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_checked = false;
bool some_unchecked = false; bool some_unchecked = false;
for (auto l : leaves) { for (auto&& l : leaves) {
if (l->checked) if (l->checked)
some_checked = true; some_checked = true;
else else
@ -108,19 +108,19 @@ namespace NamespaceItemModel_impl {
return result; 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) if (chk)
for (auto l : leaves) for (auto&& l : leaves)
l->checked = true; l->checked = true;
if (!chk) if (!chk)
for (auto l : leaves) for (auto&& l : leaves)
l->checked = false; l->checked = false;
emit model->dataChanged(index, index); emit model->dataChanged(index, index);
emit model->dataChanged(model->index(0, 0, index), model->index(leaves.size(), 0, 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; QVariant v;
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
@ -152,7 +152,7 @@ void NamespaceItemModel::init(std::shared_ptr<const PgNamespaceContainer> ns)
auto user = std::make_shared<GroupNode>("User"); auto user = std::make_shared<GroupNode>("User");
groups = { system, user }; groups = { system, user };
for (const auto e : *ns) for (auto&& e : *ns)
if (e.isSystemCatalog()) if (e.isSystemCatalog())
system->leaves.push_back(std::make_shared<LeafNode>(system, e)); system->leaves.push_back(std::make_shared<LeafNode>(system, e));
else else
@ -160,7 +160,7 @@ void NamespaceItemModel::init(std::shared_ptr<const PgNamespaceContainer> ns)
system->sortLeaves(); system->sortLeaves();
user->sortLeaves(); user->sortLeaves();
for (auto e : user->leaves) for (auto&& e : user->leaves)
e->checked = true; e->checked = true;
} }
@ -188,8 +188,8 @@ QModelIndex NamespaceItemModel::parent(const QModelIndex &index) const
{ {
QModelIndex result; QModelIndex result;
if (index.isValid()) { if (index.isValid()) {
auto *n = static_cast<Node*>(index.internalPointer()); auto n = static_cast<Node*>(index.internalPointer());
LeafNode *ln = dynamic_cast<LeafNode*>(n); auto ln = dynamic_cast<LeafNode*>(n);
if (ln) { // leafnode if (ln) { // leafnode
auto grp = ln->parent.lock(); // Get the parent group auto grp = ln->parent.lock(); // Get the parent group
auto fr = std::find(groups.begin(), groups.end(), grp); // find it in the list auto fr = std::find(groups.begin(), groups.end(), grp); // find it in the list

View file

@ -22,9 +22,7 @@ OpenDatabase::OpenDatabase(const ConnectionConfig& cfg)
{ {
} }
OpenDatabase::~OpenDatabase() OpenDatabase::~OpenDatabase() = default;
{
}
bool OpenDatabase::Init() bool OpenDatabase::Init()
{ {

View file

@ -3,11 +3,9 @@
#include <QComboBox> #include <QComboBox>
#include "model/TypeSelectionItemModel.h" #include "model/TypeSelectionItemModel.h"
ParamTypeDelegate::ParamTypeDelegate() ParamTypeDelegate::ParamTypeDelegate() = default;
{}
ParamTypeDelegate::~ParamTypeDelegate() ParamTypeDelegate::~ParamTypeDelegate() = default;
{}
void ParamTypeDelegate::setTypeSelectionModel(TypeSelectionItemModel* model) void ParamTypeDelegate::setTypeSelectionModel(TypeSelectionItemModel* model)
{ {
@ -21,7 +19,7 @@ QWidget *ParamTypeDelegate::createEditor(QWidget *parent,
{ {
QWidget *w = nullptr; QWidget *w = nullptr;
QComboBox *cmbbx = new QComboBox(parent); auto cmbbx = new QComboBox(parent);
cmbbx->setMaxVisibleItems(32); cmbbx->setMaxVisibleItems(32);
cmbbx->setModel(m_typeSelectionModel); cmbbx->setModel(m_typeSelectionModel);
w = cmbbx; w = cmbbx;