Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/declarativeitemviewextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,18 @@ QItemSelectionModel *DeclarativeItemViewExtension::selectionModel() const
return extendedItemView()->selectionModel();
}

QAbstractItemDelegate *DeclarativeItemViewExtension::itemDelegate() const
{
return extendedItemView()->itemDelegate();
}

void DeclarativeItemViewExtension::setItemDelegate(QAbstractItemDelegate *itemDelegate)
{
if (extendedItemView()->itemDelegate() == itemDelegate)
return;

extendedItemView()->setItemDelegate(itemDelegate);

emit itemDelegateChanged(itemDelegate);
}

7 changes: 7 additions & 0 deletions src/declarativeitemviewextension_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ QT_BEGIN_NAMESPACE
class QAbstractItemModel;
class QAbstractItemView;
class QItemSelectionModel;
class QAbstractItemDelegate;
QT_END_NAMESPACE

class DeclarativeItemViewPropertySignals
Expand All @@ -45,6 +46,7 @@ class DeclarativeItemViewPropertySignals
// signal signatures
virtual void modelChanged(QAbstractItemModel *model) = 0;
virtual void selectionModelChanged(QItemSelectionModel *selectionModel) = 0;
virtual void itemDelegateChanged(QAbstractItemDelegate *itemDelegate) = 0;
};

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

Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged)
Q_PROPERTY(QItemSelectionModel* selectionModel READ selectionModel WRITE setSelectionModel NOTIFY selectionModelChanged)
Q_PROPERTY(QAbstractItemDelegate* itemDelegate READ itemDelegate WRITE setItemDelegate NOTIFY itemDelegateChanged)

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

QAbstractItemDelegate *itemDelegate() const;
void setItemDelegate(QAbstractItemDelegate *itemDelegate);

Q_SIGNALS:
void modelChanged(QAbstractItemModel *model);
void selectionModelChanged(QItemSelectionModel *selectionModel);
void itemDelegateChanged(QAbstractItemDelegate *itemDelegate) Q_DECL_OVERRIDE;
};

#endif
15 changes: 15 additions & 0 deletions src/declarativetreeviewextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,18 @@ QHeaderView *DeclarativeTreeViewExtension::header() const
{
return extendedTreeView()->header();
}

void DeclarativeTreeViewExtension::setItemDelegate(QAbstractItemDelegate *itemDelegate)
{
if (extendedTreeView()->itemDelegate() == itemDelegate)
return;

extendedTreeView()->setItemDelegate(itemDelegate);

emit itemDelegateChanged(itemDelegate);
}

QAbstractItemDelegate *DeclarativeTreeViewExtension::itemDelegate() const
{
return extendedTreeView()->itemDelegate();
}
6 changes: 6 additions & 0 deletions src/declarativetreeviewextension_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
QT_BEGIN_NAMESPACE
class QHeaderView;
class QTreeView;
class QAbstractItemDelegate;
QT_END_NAMESPACE

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

Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false)

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

void setItemDelegate(QAbstractItemDelegate *itemDelegate);
QAbstractItemDelegate *itemDelegate() const;

Q_SIGNALS:
void modelChanged(QAbstractItemModel *model);
void selectionModelChanged(QItemSelectionModel *selectionModel);
void itemDelegateChanged(QAbstractItemDelegate *itemDelegate);

void headerChanged(QHeaderView *header);
};
Expand Down
2 changes: 2 additions & 0 deletions src/declarativewidgets_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "stackedwidgetwidgetcontainer_p.h"
#include "toolbarwidgetcontainer_p.h"

#include <QAbstractItemDelegate>
#include <QButtonGroup>
#include <QCalendarWidget>
#include <QCheckBox>
Expand Down Expand Up @@ -115,6 +116,7 @@ void ExtensionpluginPlugin::registerTypes(const char *uri)
// uncreatable core
qmlRegisterType<QAbstractItemModel>();
qmlRegisterType<QItemSelectionModel>();
qmlRegisterType<QAbstractItemDelegate>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QAbstractItemDelegate can not be constructed in C++, since it is abstract.
So this would need to be registered with qmlRegisterUncreatableType()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I beg to differ. It's using the qmlRegisterType overload without parameters, only to make the type known to QML.
Same thing can be seen 2 lines above for QAbstractItemModel.
Should this really be handled with qmlRegisterUncreatableType?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point.
I guess we should change that to uncreatable type registration, in a future clean up commit, and for the other uncreatables as well


// uncreatable gui
qmlRegisterType<QTextDocument>();
Expand Down