Skip to content

Commit 4e5d436

Browse files
committed
Add support for accessing ListView/TreeView itemDelegate (#15)
* Add support for accessing ListView/TreeView itemDelegate
1 parent d5890a5 commit 4e5d436

5 files changed

+45
-0
lines changed

src/declarativeitemviewextension.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,18 @@ QItemSelectionModel *DeclarativeItemViewExtension::selectionModel() const
7373
return extendedItemView()->selectionModel();
7474
}
7575

76+
QAbstractItemDelegate *DeclarativeItemViewExtension::itemDelegate() const
77+
{
78+
return extendedItemView()->itemDelegate();
79+
}
80+
81+
void DeclarativeItemViewExtension::setItemDelegate(QAbstractItemDelegate *itemDelegate)
82+
{
83+
if (extendedItemView()->itemDelegate() == itemDelegate)
84+
return;
85+
86+
extendedItemView()->setItemDelegate(itemDelegate);
87+
88+
emit itemDelegateChanged(itemDelegate);
89+
}
90+

src/declarativeitemviewextension_p.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ QT_BEGIN_NAMESPACE
3535
class QAbstractItemModel;
3636
class QAbstractItemView;
3737
class QItemSelectionModel;
38+
class QAbstractItemDelegate;
3839
QT_END_NAMESPACE
3940

4041
class DeclarativeItemViewPropertySignals
@@ -45,6 +46,7 @@ class DeclarativeItemViewPropertySignals
4546
// signal signatures
4647
virtual void modelChanged(QAbstractItemModel *model) = 0;
4748
virtual void selectionModelChanged(QItemSelectionModel *selectionModel) = 0;
49+
virtual void itemDelegateChanged(QAbstractItemDelegate *itemDelegate) = 0;
4850
};
4951

5052
class DeclarativeItemViewExtension : public DeclarativeWidgetExtension, protected DeclarativeItemViewPropertySignals
@@ -53,6 +55,7 @@ class DeclarativeItemViewExtension : public DeclarativeWidgetExtension, protecte
5355

5456
Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged)
5557
Q_PROPERTY(QItemSelectionModel* selectionModel READ selectionModel WRITE setSelectionModel NOTIFY selectionModelChanged)
58+
Q_PROPERTY(QAbstractItemDelegate* itemDelegate READ itemDelegate WRITE setItemDelegate NOTIFY itemDelegateChanged)
5659

5760
// repeat property declarations, qmlRegisterExtendedType doesn't see the ones from base class
5861
Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false CONSTANT)
@@ -70,9 +73,13 @@ class DeclarativeItemViewExtension : public DeclarativeWidgetExtension, protecte
7073
void setSelectionModel(QItemSelectionModel *selectionModel);
7174
QItemSelectionModel *selectionModel() const;
7275

76+
QAbstractItemDelegate *itemDelegate() const;
77+
void setItemDelegate(QAbstractItemDelegate *itemDelegate);
78+
7379
Q_SIGNALS:
7480
void modelChanged(QAbstractItemModel *model);
7581
void selectionModelChanged(QItemSelectionModel *selectionModel);
82+
void itemDelegateChanged(QAbstractItemDelegate *itemDelegate) Q_DECL_OVERRIDE;
7683
};
7784

7885
#endif

src/declarativetreeviewextension.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,18 @@ QHeaderView *DeclarativeTreeViewExtension::header() const
5555
{
5656
return extendedTreeView()->header();
5757
}
58+
59+
void DeclarativeTreeViewExtension::setItemDelegate(QAbstractItemDelegate *itemDelegate)
60+
{
61+
if (extendedTreeView()->itemDelegate() == itemDelegate)
62+
return;
63+
64+
extendedTreeView()->setItemDelegate(itemDelegate);
65+
66+
emit itemDelegateChanged(itemDelegate);
67+
}
68+
69+
QAbstractItemDelegate *DeclarativeTreeViewExtension::itemDelegate() const
70+
{
71+
return extendedTreeView()->itemDelegate();
72+
}

src/declarativetreeviewextension_p.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
QT_BEGIN_NAMESPACE
3535
class QHeaderView;
3636
class QTreeView;
37+
class QAbstractItemDelegate;
3738
QT_END_NAMESPACE
3839

3940
class DeclarativeTreeViewExtension : public DeclarativeItemViewExtension
@@ -45,6 +46,7 @@ class DeclarativeTreeViewExtension : public DeclarativeItemViewExtension
4546
// repeat property declarations, qmlRegisterExtendedType doesn't see the ones from base class
4647
Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged)
4748
Q_PROPERTY(QItemSelectionModel* selectionModel READ selectionModel WRITE setSelectionModel NOTIFY selectionModelChanged)
49+
Q_PROPERTY(QAbstractItemDelegate* itemDelegate READ itemDelegate WRITE setItemDelegate NOTIFY itemDelegateChanged)
4850

4951
Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false CONSTANT)
5052

@@ -58,9 +60,13 @@ class DeclarativeTreeViewExtension : public DeclarativeItemViewExtension
5860
void setHeader(QHeaderView *header);
5961
QHeaderView *header() const;
6062

63+
void setItemDelegate(QAbstractItemDelegate *itemDelegate);
64+
QAbstractItemDelegate *itemDelegate() const;
65+
6166
Q_SIGNALS:
6267
void modelChanged(QAbstractItemModel *model);
6368
void selectionModelChanged(QItemSelectionModel *selectionModel);
69+
void itemDelegateChanged(QAbstractItemDelegate *itemDelegate);
6470

6571
void headerChanged(QHeaderView *header);
6672
};

src/declarativewidgets_plugin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#include "toolbarwidgetcontainer_p.h"
7373
#include "declarativepushbutton_p.h"
7474

75+
#include <QAbstractItemDelegate>
7576
#include <QButtonGroup>
7677
#include <QCalendarWidget>
7778
#include <QCheckBox>
@@ -118,6 +119,7 @@ void ExtensionpluginPlugin::registerTypes(const char *uri)
118119
// uncreatable core
119120
qmlRegisterType<QAbstractItemModel>();
120121
qmlRegisterType<QItemSelectionModel>();
122+
qmlRegisterType<QAbstractItemDelegate>();
121123

122124
// uncreatable gui
123125
qmlRegisterType<QTextDocument>();

0 commit comments

Comments
 (0)