diff options
author | Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> | 2015-01-07 12:07:28 +0100 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> | 2015-02-13 15:27:46 +0000 |
commit | 82c7760b819f73ebc7f4ba6203fa2fc92b383236 (patch) | |
tree | f5ae4743a45c43a4a95115679d3f1690a4a6268e /src/controls/Private/qquickstyleitem.cpp | |
parent | 6f15c206b069ed0fcf48a285bfcc4ad636927df0 (diff) | |
download | qtquickcontrols-82c7760b819f73ebc7f4ba6203fa2fc92b383236.tar.gz |
Introducing TreeView
The TreeView, as currently implemented, extends the
TableView by adding support for hierarchical models. In
the broad sense, it remains a list view with columns,
like TableView.
The main architecture is based on TreeModelAdaptor, that
wraps the hierarchical model. It keeps track of which
items are expanded or collapsed, and also relays model
changes to the view. (TreeModelAdaptor is a private type
and should be considered as an implementation detail.)
The TreeView only supports QAbstractItemModels for the
time being, and, just like TableView, relies on roles to
pass the data to the view. This also means that model
columns are not supported.
Selection is supported by ItemSelectionModel which exposes
part of the API of QItemSelectionModel. For this, support
has been added for QModelIndex and related classes. This
requires importing QtQml.Models 2.2 should an actual usage
of the TreeView use selection.
In the same way, TreeViewStyle currently extends TableViewStyle
with the relevant features, like branch indicator.
[ChangeLog][QtQuick.Controls] Introducing TreeView
With-Help-From: Caroline Chao <caroline.chao@theqtcompany.com>
Change-Id: Id3dba240a732744571e4a646b7b98678ab522da6
Reviewed-by: Caroline Chao <caroline.chao@theqtcompany.com>
Diffstat (limited to 'src/controls/Private/qquickstyleitem.cpp')
-rw-r--r-- | src/controls/Private/qquickstyleitem.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/controls/Private/qquickstyleitem.cpp b/src/controls/Private/qquickstyleitem.cpp index 4cd4f52b..2ac692af 100644 --- a/src/controls/Private/qquickstyleitem.cpp +++ b/src/controls/Private/qquickstyleitem.cpp @@ -370,6 +370,19 @@ void QQuickStyleItem::initStyleOption() } } break; + case ItemBranchIndicator: { + if (!m_styleoption) + m_styleoption = new QStyleOption; + + m_styleoption->state = QStyle::State_Item; // We don't want to fully support Win 95 + if (m_properties.value("hasChildren").toBool()) + m_styleoption->state |= QStyle::State_Children; + if (m_properties.value("hasSibling").toBool()) // Even this one could go away + m_styleoption->state |= QStyle::State_Sibling; + if (m_on) + m_styleoption->state |= QStyle::State_Open; + } + break; case Header: { if (!m_styleoption) m_styleoption = new QStyleOptionHeader(); @@ -1223,6 +1236,8 @@ int QQuickStyleItem::pixelMetric(const QString &metric) return qApp->style()->pixelMetric(QStyle::PM_SplitterWidth, 0 ); else if (metric == "scrollbarspacing") return abs(qApp->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing, 0 )); + else if (metric == "treeviewindentation") + return qApp->style()->pixelMetric(QStyle::PM_TreeViewIndentation, 0 ); return 0; } @@ -1309,6 +1324,8 @@ void QQuickStyleItem::setElementType(const QString &str) } else { m_itemType = (str == "item") ? Item : ItemRow; } + } else if (str == "itembranchindicator") { + m_itemType = ItemBranchIndicator; } else if (str == "groupbox") { m_itemType = GroupBox; } else if (str == "tab") { @@ -1422,6 +1439,11 @@ QRectF QQuickStyleItem::subControlRect(const QString &subcontrolString) subcontrol); } break; + case ItemBranchIndicator: { + QStyleOption opt; + opt.rect = QRect(0, 0, implicitWidth(), implicitHeight()); + return qApp->style()->subElementRect(QStyle::SE_TreeViewDisclosureItem, &opt, 0); + } default: break; } @@ -1502,6 +1524,9 @@ void QQuickStyleItem::paint(QPainter *painter) case Item: qApp->style()->drawControl(QStyle::CE_ItemViewItem, m_styleoption, painter); break; + case ItemBranchIndicator: + qApp->style()->drawPrimitive(QStyle::PE_IndicatorBranch, m_styleoption, painter); + break; case Header: qApp->style()->drawControl(QStyle::CE_Header, m_styleoption, painter); break; |