Have a working model for showing the namespaces in a tree with checkboxes.
The namespaces are currently spit into user and system. Later we might add recognizing namespaces introduced by specific modules/extensions.
This commit is contained in:
parent
4e1120647c
commit
b5254ac723
9 changed files with 414 additions and 5 deletions
126
pglab/NamespaceItemModel.h
Normal file
126
pglab/NamespaceItemModel.h
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
#ifndef NAMESPACEITEMMODEL_H
|
||||
#define NAMESPACEITEMMODEL_H
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include "PgNamespace.h"
|
||||
#include <vector>
|
||||
|
||||
class PgNamespaceContainer;
|
||||
|
||||
class NamespaceItemModel: public QAbstractItemModel {
|
||||
public:
|
||||
NamespaceItemModel(QObject *parent = 0);
|
||||
|
||||
void init(std::shared_ptr<const PgNamespaceContainer> ns);
|
||||
|
||||
virtual QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual QModelIndex parent(const QModelIndex &index) const override;
|
||||
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
//std::set<Oid> getCheckedNamespaces() const;
|
||||
|
||||
private:
|
||||
// using NsVec = std::vector<PgNamespace>;
|
||||
|
||||
// class Group {
|
||||
// public:
|
||||
// QString name;
|
||||
// NsVec namespaces;
|
||||
// };
|
||||
// using GrpVec = std::vector<Group>;
|
||||
|
||||
// //std::shared_ptr<const PgNamespaceContainer> m_namespaces;
|
||||
// GrpVec groups;
|
||||
|
||||
|
||||
class Node {
|
||||
public:
|
||||
|
||||
virtual ~Node() {}
|
||||
virtual int getRowCount() const = 0;
|
||||
virtual Qt::CheckState getCheckState() const = 0;
|
||||
|
||||
};
|
||||
class GroupNode;
|
||||
|
||||
class LeafNode: public Node {
|
||||
public:
|
||||
std::weak_ptr<GroupNode> parent;
|
||||
bool checked = false;
|
||||
|
||||
PgNamespace ns;
|
||||
LeafNode(std::weak_ptr<GroupNode> p, const PgNamespace &nspace)
|
||||
: parent(p)
|
||||
, ns(nspace)
|
||||
{}
|
||||
|
||||
virtual int getRowCount() const override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual Qt::CheckState getCheckState() const override
|
||||
{
|
||||
return checked ? Qt::Checked : Qt::Unchecked;
|
||||
}
|
||||
|
||||
bool operator < (const LeafNode &rhs) const
|
||||
{
|
||||
return ns.name < rhs.ns.name;
|
||||
}
|
||||
};
|
||||
|
||||
class GroupNode: public Node {
|
||||
public:
|
||||
using LeafVec = std::vector<std::shared_ptr<LeafNode>>;
|
||||
|
||||
QString name;
|
||||
LeafVec leaves;
|
||||
|
||||
GroupNode(QString n)
|
||||
: name(n)
|
||||
{}
|
||||
virtual int getRowCount() const override
|
||||
{
|
||||
return leaves.size();
|
||||
}
|
||||
void sortLeaves()
|
||||
{
|
||||
std::sort(leaves.begin(), leaves.end(),
|
||||
[] (auto l, auto r) -> bool { return *l < *r; });
|
||||
}
|
||||
virtual Qt::CheckState getCheckState() const override
|
||||
{
|
||||
bool some_checked = false;
|
||||
bool some_unchecked = false;
|
||||
for (auto l : leaves) {
|
||||
if (l->checked)
|
||||
some_checked = true;
|
||||
else
|
||||
some_unchecked = true;
|
||||
}
|
||||
Qt::CheckState result;
|
||||
if (some_checked && some_unchecked)
|
||||
result = Qt::PartiallyChecked;
|
||||
else if (some_checked)
|
||||
result = Qt::Checked;
|
||||
else
|
||||
result = Qt::Unchecked;
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
using GroupVec = std::vector<std::shared_ptr<GroupNode>>;
|
||||
|
||||
GroupVec groups;
|
||||
|
||||
};
|
||||
|
||||
#endif // NAMESPACEITEMMODEL_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue