Add tree view extension for header property
authorKevin Krammer <kevin.krammer@kdab.com>
Fri, 29 Mar 2013 13:47:32 +0000 (14:47 +0100)
committerKevin Krammer <kevin.krammer@kdab.com>
Fri, 29 Mar 2013 13:50:54 +0000 (14:50 +0100)
lib/declarativetreeviewextension.cpp [new file with mode: 0644]
lib/declarativetreeviewextension_p.h [new file with mode: 0644]
lib/declarativewidgetsdocument.cpp
lib/lib.pro

diff --git a/lib/declarativetreeviewextension.cpp b/lib/declarativetreeviewextension.cpp
new file mode 100644 (file)
index 0000000..f36786c
--- /dev/null
@@ -0,0 +1,30 @@
+#include "declarativetreeviewextension_p.h"
+
+#include <QTreeView>
+
+DeclarativeTreeViewExtension::DeclarativeTreeViewExtension(QObject *parent)
+  : DeclarativeItemViewExtension(parent)
+{
+}
+
+QTreeView *DeclarativeTreeViewExtension::extendedTreeView() const
+{
+  QTreeView *treeView = qobject_cast<QTreeView*>(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 (file)
index 0000000..e11c928
--- /dev/null
@@ -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<QObject> 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
index b13ac75..7fa6fa7 100644 (file)
@@ -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<QTimeEdit, DeclarativeWidgetExtension>("QtGui", 1, 0, "TimeEdit");
   qmlRegisterExtendedType<QToolBar, DeclarativeContainerWidgetExtension<ToolBarWidgetContainer> >("QtGui", 1, 0, "ToolBar");
   qmlRegisterExtendedType<QToolButton, DeclarativeWidgetExtension>("QtGui", 1, 0, "ToolButton");
-  qmlRegisterExtendedType<QTreeView, DeclarativeItemViewExtension>("QtGui", 1, 0, "TreeView");
+  qmlRegisterExtendedType<QTreeView, DeclarativeTreeViewExtension>("QtGui", 1, 0, "TreeView");
   qmlRegisterExtendedType<QWebView, DeclarativeWidgetExtension>("QtGui", 1, 0, "WebView");
   qmlRegisterExtendedType<QWidget, DeclarativeWidgetExtension>("QtGui", 1, 0, "Widget");
 
index 86f0f80..f260d95 100644 (file)
@@ -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 \