Remove padding to the left in TreeSelectionEditor if the tree doesn't have grand children.

This commit is contained in:
Gaute Lindkvist
2018-09-28 15:50:16 +02:00
parent ac8c6edafa
commit fcda0b9755
4 changed files with 27 additions and 3 deletions

View File

@@ -76,6 +76,18 @@ public:
return m_childItems.value(row);
}
bool hasGrandChildren() const
{
for (auto child : m_childItems)
{
if (child->childCount() != 0)
{
return true;
}
}
return false;
}
int childCount() const
{
return m_childItems.count();

View File

@@ -332,6 +332,8 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName)
}
}
}
// If the tree doesn't have grand children we treat this as a straight list
m_treeView->setRootIsDecorated(m_model->hasGrandChildren());
m_model->resetUiValueCache();
}

View File

@@ -218,6 +218,14 @@ bool caf::PdmUiTreeSelectionQModel::isChecked(const QModelIndex& index) const
return data(index, Qt::CheckStateRole).toBool();
}
//--------------------------------------------------------------------------------------------------
/// Checks if this is a real tree with grand children or just a list of children.
//--------------------------------------------------------------------------------------------------
bool caf::PdmUiTreeSelectionQModel::hasGrandChildren() const
{
return m_tree && m_tree->hasGrandChildren();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -74,6 +74,8 @@ public:
bool isReadOnly(const QModelIndex& index) const;
bool isChecked(const QModelIndex& index) const;
bool hasGrandChildren() const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
@@ -83,8 +85,8 @@ public:
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
// Consider moving these functions to PdmUiFieldHandle
static bool isSingleValueField(const QVariant& fieldValue);
static bool isMultipleValueField(const QVariant& fieldValue);
static bool isSingleValueField(const QVariant& fieldValue);
static bool isMultipleValueField(const QVariant& fieldValue);
private:
typedef caf::UiTreeItem<int> TreeItemType;