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

@ -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<const PgNamespaceContainer> ns)
auto user = std::make_shared<GroupNode>("User");
groups = { system, user };
for (const auto e : *ns)
for (auto&& e : *ns)
if (e.isSystemCatalog())
system->leaves.push_back(std::make_shared<LeafNode>(system, e));
else
@ -160,7 +160,7 @@ void NamespaceItemModel::init(std::shared_ptr<const PgNamespaceContainer> 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<Node*>(index.internalPointer());
LeafNode *ln = dynamic_cast<LeafNode*>(n);
auto n = static_cast<Node*>(index.internalPointer());
auto ln = dynamic_cast<LeafNode*>(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