Add tab with namespaces (schema's)
This commit is contained in:
parent
8dd13d103e
commit
1df8455af5
7 changed files with 171 additions and 18 deletions
|
|
@ -13,6 +13,7 @@ namespace NamespaceItemModel_impl {
|
|||
virtual Qt::CheckState getCheckState() const = 0;
|
||||
virtual void setChecked(NamespaceItemModel *model, const QModelIndex &index, bool checked) = 0;
|
||||
virtual QVariant data(const QModelIndex &index, int role) const = 0;
|
||||
virtual int columnCount() const = 0;
|
||||
|
||||
};
|
||||
class GroupNode;
|
||||
|
|
@ -45,16 +46,29 @@ namespace NamespaceItemModel_impl {
|
|||
emit model->dataChanged(index.parent(), index.parent());
|
||||
}
|
||||
|
||||
QVariant data(const QModelIndex &/*index*/, int role) const override
|
||||
QVariant data(const QModelIndex &index, int role) const override
|
||||
{
|
||||
QVariant v;
|
||||
if (role == Qt::DisplayRole) {
|
||||
v = ns.objectName();
|
||||
switch (index.column()) {
|
||||
case NamespaceItemModel::ColNamespaceName:
|
||||
return ns.objectName();
|
||||
case NamespaceItemModel::ColOwner:
|
||||
return ns.ownerName();
|
||||
case NamespaceItemModel::ColAcl:
|
||||
return ns.aclString();
|
||||
}
|
||||
}
|
||||
else if (role == Qt::CheckStateRole) {
|
||||
v = getCheckState();
|
||||
if (index.column() == 0)
|
||||
return getCheckState();
|
||||
}
|
||||
return v;
|
||||
return {};
|
||||
}
|
||||
|
||||
int columnCount() const override
|
||||
{
|
||||
return NamespaceItemModel::ColCount;
|
||||
}
|
||||
|
||||
bool operator < (const LeafNode &rhs) const
|
||||
|
|
@ -62,12 +76,11 @@ namespace NamespaceItemModel_impl {
|
|||
return ns.objectName() < rhs.ns.objectName();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
class GroupNode: public Node {
|
||||
public:
|
||||
using LeafVec = std::vector<std::shared_ptr<LeafNode>>;
|
||||
using LeafVec = QVector<std::shared_ptr<LeafNode>>;
|
||||
|
||||
QString name;
|
||||
LeafVec leaves;
|
||||
|
|
@ -120,16 +133,25 @@ namespace NamespaceItemModel_impl {
|
|||
emit model->dataChanged(model->index(0, 0, index), model->index(leaves.size(), 0, index));
|
||||
}
|
||||
|
||||
QVariant data(const QModelIndex &/*index*/, int role) const override
|
||||
QVariant data(const QModelIndex &index, int role) const override
|
||||
{
|
||||
QVariant v;
|
||||
if (role == Qt::DisplayRole) {
|
||||
v = name;
|
||||
switch (index.column()) {
|
||||
case NamespaceItemModel::ColNamespaceName:
|
||||
return name;
|
||||
}
|
||||
}
|
||||
else if(role == Qt::CheckStateRole) {
|
||||
v = getCheckState();
|
||||
if (index.column() == 0)
|
||||
return getCheckState();
|
||||
}
|
||||
return v;
|
||||
return {};
|
||||
}
|
||||
|
||||
int columnCount() const override
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -164,6 +186,21 @@ void NamespaceItemModel::init(std::shared_ptr<const PgNamespaceContainer> ns)
|
|||
e->checked = true;
|
||||
}
|
||||
|
||||
void NamespaceItemModel::setEnableCheckboxes(bool enable)
|
||||
{
|
||||
if (m_enableCheckboxes != enable) {
|
||||
beginResetModel();
|
||||
SCOPE_EXIT { endResetModel(); };
|
||||
m_enableCheckboxes = enable;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool NamespaceItemModel::isEnableCheckboxes() const
|
||||
{
|
||||
return m_enableCheckboxes;
|
||||
}
|
||||
|
||||
QModelIndex NamespaceItemModel::index(int row, int column,
|
||||
const QModelIndex &parent) const
|
||||
{
|
||||
|
|
@ -192,8 +229,9 @@ QModelIndex NamespaceItemModel::parent(const QModelIndex &index) const
|
|||
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
|
||||
int row = fr - groups.begin(); // calculate index ie row
|
||||
// auto fr = std::find(groups.begin(), groups.end(), grp); // find it in the list
|
||||
// int row = fr - groups.begin(); // calculate index ie row
|
||||
int row = groups.indexOf(grp);
|
||||
result = createIndex(row, 0, grp.get()); // return index
|
||||
}
|
||||
|
||||
|
|
@ -216,7 +254,11 @@ int NamespaceItemModel::rowCount(const QModelIndex &parent) const
|
|||
|
||||
int NamespaceItemModel::columnCount(const QModelIndex &/*index*/) const
|
||||
{
|
||||
return 1;
|
||||
// if (index.isValid()) {
|
||||
// auto *n = static_cast<Node*>(index.internalPointer());
|
||||
// return n->columnCount();
|
||||
// }
|
||||
return ColCount;
|
||||
}
|
||||
|
||||
QVariant NamespaceItemModel::data(const QModelIndex &index, int role) const
|
||||
|
|
@ -234,7 +276,8 @@ bool NamespaceItemModel::setData(const QModelIndex &index,
|
|||
return false;
|
||||
|
||||
auto *n = static_cast<Node*>(index.internalPointer());
|
||||
n->setChecked(this, index, value == Qt::Checked);
|
||||
if (index.column() == 0)
|
||||
n->setChecked(this, index, value == Qt::Checked);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -242,7 +285,23 @@ bool NamespaceItemModel::setData(const QModelIndex &index,
|
|||
Qt::ItemFlags NamespaceItemModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
|
||||
flags.setFlag(Qt::ItemIsUserCheckable);
|
||||
if (index.column() == 0 && m_enableCheckboxes)
|
||||
flags.setFlag(Qt::ItemIsUserCheckable);
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QVariant NamespaceItemModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal) {
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch (section) {
|
||||
case ColNamespaceName: return tr("Name");
|
||||
case ColOwner: return tr("Owner");
|
||||
case ColAcl: return tr("ACL");
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue