From: Kevin Krammer Date: Fri, 29 Mar 2013 13:47:32 +0000 (+0100) Subject: Add tree view extension for header property X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=d819aca56c1d9fe8c0bcf410bbe0df4a32bead3a;p=konrad%2FDeclarativeWidgets.git Add tree view extension for header property --- diff --git a/lib/declarativetreeviewextension.cpp b/lib/declarativetreeviewextension.cpp new file mode 100644 index 0000000..f36786c --- /dev/null +++ b/lib/declarativetreeviewextension.cpp @@ -0,0 +1,30 @@ +#include "declarativetreeviewextension_p.h" + +#include + +DeclarativeTreeViewExtension::DeclarativeTreeViewExtension(QObject *parent) + : DeclarativeItemViewExtension(parent) +{ +} + +QTreeView *DeclarativeTreeViewExtension::extendedTreeView() const +{ + QTreeView *treeView = qobject_cast(extendedItemView()); + Q_ASSERT(treeView); + + return treeView; +} + +void DeclarativeTreeViewExtension::setHeader(QHeaderView *header) +{ + if (header == extendedTreeView()->header()) + return; + + extendedTreeView()->setHeader(header); + emit headerChanged(header); +} + +QHeaderView *DeclarativeTreeViewExtension::header() const +{ + return extendedTreeView()->header(); +} diff --git a/lib/declarativetreeviewextension_p.h b/lib/declarativetreeviewextension_p.h new file mode 100644 index 0000000..e11c928 --- /dev/null +++ b/lib/declarativetreeviewextension_p.h @@ -0,0 +1,38 @@ +#ifndef DECLARATIVETREEVIEWEXTENSION_P_H +#define DECLARATIVETREEVIEWEXTENSION_P_H + +#include "declarativeitemviewextension_p.h" + +class QHeaderView; +class QTreeView; + +class DeclarativeTreeViewExtension : public DeclarativeItemViewExtension +{ + Q_OBJECT + + Q_PROPERTY(QHeaderView* header READ header WRITE setHeader NOTIFY headerChanged) + + // 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(QDeclarativeListProperty data READ data DESIGNABLE false) + + Q_CLASSINFO("DefaultProperty", "data") + + public: + explicit DeclarativeTreeViewExtension(QObject *parent = 0); + + QTreeView *extendedTreeView() const; + + void setHeader(QHeaderView *header); + QHeaderView *header() const; + + Q_SIGNALS: + void modelChanged(QAbstractItemModel *model); + void selectionModelChanged(QItemSelectionModel *selectionModel); + + void headerChanged(QHeaderView *header); +}; + +#endif // DECLARATIVETREEVIEWEXTENSION_P_H diff --git a/lib/declarativewidgetsdocument.cpp b/lib/declarativewidgetsdocument.cpp index b13ac75..7fa6fa7 100644 --- a/lib/declarativewidgetsdocument.cpp +++ b/lib/declarativewidgetsdocument.cpp @@ -45,6 +45,7 @@ #include "declarativetableviewextension_p.h" #include "declarativetabwidget_p.h" #include "declarativetexteditextension_p.h" +#include "declarativetreeviewextension_p.h" #include "declarativevboxlayout_p.h" #include "declarativewidgetextension.h" #include "mainwindowwidgetcontainer_p.h" @@ -180,7 +181,7 @@ DeclarativeWidgetsDocument::DeclarativeWidgetsDocument(const QUrl &url, QObject qmlRegisterExtendedType("QtGui", 1, 0, "TimeEdit"); qmlRegisterExtendedType >("QtGui", 1, 0, "ToolBar"); qmlRegisterExtendedType("QtGui", 1, 0, "ToolButton"); - qmlRegisterExtendedType("QtGui", 1, 0, "TreeView"); + qmlRegisterExtendedType("QtGui", 1, 0, "TreeView"); qmlRegisterExtendedType("QtGui", 1, 0, "WebView"); qmlRegisterExtendedType("QtGui", 1, 0, "Widget"); diff --git a/lib/lib.pro b/lib/lib.pro index 86f0f80..f260d95 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -34,6 +34,7 @@ HEADERS = \ declarativetableviewextension_p.h \ declarativetabwidget_p.h \ declarativetexteditextension_p.h \ + declarativetreeviewextension_p.h \ declarativevboxlayout_p.h \ declarativewidgetextension.h \ declarativewidgetsdocument.h \ @@ -80,6 +81,7 @@ SOURCES = \ declarativetableviewextension.cpp \ declarativetabwidget.cpp \ declarativetexteditextension.cpp \ + declarativetreeviewextension.cpp \ declarativevboxlayout.cpp \ declarativewidgetextension.cpp \ declarativewidgetsdocument.cpp \