summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Bugge Monsen <mmonsen@trolltech.com>2009-06-10 16:25:48 +0200
committerMarius Bugge Monsen <mmonsen@trolltech.com>2009-06-18 13:57:46 +0200
commit602937ee29a58ffcf581d93e64549e4beb747834 (patch)
treeff65c702e8d43958a4d7ae7b2ddd9b03a2e65b14
parentbecd6694bcb181b3f636a3bfdab4c8366062d8a7 (diff)
Add QHash<int,QString> roles() const function to the model interfaces. This is used by the declarative ui to map from the role enum to the name string.
-rw-r--r--src/qdataroles_p.h58
-rw-r--r--src/qgraphicsheader.cpp1
-rw-r--r--src/qgraphicslistview.cpp87
-rw-r--r--src/qlistmodelinterface.cpp31
-rw-r--r--src/qlistmodelinterface.h3
-rw-r--r--src/qlistwidgetng.cpp26
-rw-r--r--src/qtablemodelinterface.cpp16
-rw-r--r--src/qtablemodelinterface.h1
-rw-r--r--src/qtreemodelbase.h1
-rw-r--r--src/src.pro1
-rw-r--r--tests/qgraphicstableview/tst_qgraphicstableview.cpp2
11 files changed, 162 insertions, 65 deletions
diff --git a/src/qdataroles_p.h b/src/qdataroles_p.h
new file mode 100644
index 0000000..e71c650
--- /dev/null
+++ b/src/qdataroles_p.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the Itemviews NG project on Trolltech Labs.
+**
+** This file may be used under the terms of the GNU General Public
+** License version 2.0 or 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of
+** this file. Please review the following information to ensure GNU
+** General Public Licensing requirements will be met:
+** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+****************************************************************************/
+
+#ifndef QTDATAROLES_P_H
+#define QTDATAROLES_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qmetaobject.h>
+
+QT_BEGIN_NAMESPACE
+
+struct QtDataRoles : private QObject
+{
+ static QHash<int, QString> roles() {
+ QHash<int,QString> roles;
+ const QMetaObject &staticMetaObject = static_cast<QtDataRoles*>(0)->staticQtMetaObject;
+ const int index = staticMetaObject.indexOfEnumerator("DataRoles");
+ const QMetaEnum metaEnum = staticMetaObject.enumerator(index);
+ for (int i = 0; i < metaEnum.keyCount(); ++i)
+ roles.insert(metaEnum.value(i), metaEnum.key(i));
+ return roles;
+ }
+};
+
+
+QT_END_NAMESPACE
+
+#endif//QTDATAROLES_P_H
diff --git a/src/qgraphicsheader.cpp b/src/qgraphicsheader.cpp
index 86fd514..a0137a4 100644
--- a/src/qgraphicsheader.cpp
+++ b/src/qgraphicsheader.cpp
@@ -970,7 +970,6 @@ void QtGraphicsHeader::setSectionSize(int logicalIndex, qreal size)
qreal QtGraphicsHeader::sectionPosition(int logicalIndex) const
{
Q_D(const QtGraphicsHeader);
- Q_UNUSED(logicalIndex);
return d->sectionGeometry(mapToVisualIndex(logicalIndex)).first;
}
diff --git a/src/qgraphicslistview.cpp b/src/qgraphicslistview.cpp
index 0de92b7..ab71b43 100644
--- a/src/qgraphicslistview.cpp
+++ b/src/qgraphicslistview.cpp
@@ -38,6 +38,7 @@
#include <qdebug.h>
#include <limits.h>
+
/*!
\class QtGraphicsListViewItem
@@ -60,23 +61,16 @@
The QtGraphicsListView will create and delete QtGraphicsListViewItem instances
as they are needed based on how many items are visible. It is possible for an
item to be reused. When this happens the itemChanged() method will be called
- to make the item aware of this change. The default implmentation will make sure
+ to make the item aware of this change. The default implementation will make sure
that update() will be called.
-
- The default QtGraphicsListView::itemContentsSizeHint() will first ask the model for a
- Qt::SizeHintRole and then request the effectiveSizeHint() from the item to
- find an optimal size. To change the individual items sizes it is recommended
- to reimplement QtGraphicsListView::itemContentsSizeHint() which gives the greatest speed
- and flexibility. Changing the items minimumSize() and maxiumSize() or
- reimplementing the sizeHint() methods on the QtGraphicsListViewItem will likely
- be the easier solution.
*/
+
QtGraphicsListViewItem::QtGraphicsListViewItem(int index, QtGraphicsListView *view)
: QGraphicsWidget(view, 0), d_ptr(new QtGraphicsListViewItemPrivate)
{
Q_D(QtGraphicsListViewItem);
Q_ASSERT(view);
- //setCacheMode(QGraphicsItem::ItemCoordinateCache); // ### items are sometimes not repainted when we call update()
+ setCacheMode(QGraphicsItem::ItemCoordinateCache);
d->q_ptr = this;
d->view = view;
d->index = index;
@@ -206,6 +200,11 @@ QtGraphicsListView *QtGraphicsListViewItem::view() const
*/
/*!
+ \class QtGraphicsListViewItemCreator
+ \brief an easy to use factory class to create QtGraphicsListViewItem instances for the QtGraphicsListView
+ */
+
+/*!
Destructor.
*/
QtGraphicsListViewItemCreatorBase::~QtGraphicsListViewItemCreatorBase()
@@ -236,16 +235,9 @@ void QtGraphicsListViewItemCreatorBase::recycle(QtGraphicsListViewItem *item)
/*!
\fn QtGraphicsListViewItem *QtGraphicsListViewItemCreatorBase::create(int index, QtGraphicsListView *view)
- The view will call the create() method for every visible item it needs to display on screen.
- This is a factory method to create the item, or reuse a previously recycled one after which
- the ownership of the item lies with the caller.
+ The view will call the create() method for every visible item.
- The item will be initialized to belong to \a view and will get the \a index set to it
- allowing it to show the correct content.
-*/
-
-/*!
- \class QtGraphicsListViewItemCreator
+ The item will be a child of the given \a view and will display the data referred to by the given \a index.
*/
// QtGraphicsListViewPrivate
@@ -482,6 +474,7 @@ QSizeF QtGraphicsListViewPrivate::itemSizeHint(const QStyleOptionViewItemV4 *opt
*/
/*!
+ Constructs a QtGraphicsListView with the given \a orientation, \a parent and \a wFlags.
*/
QtGraphicsListView::QtGraphicsListView(Qt::Orientation orientation, QGraphicsWidget *parent, Qt::WindowFlags wFlags)
: QGraphicsWidget(parent, wFlags), d_ptr(new QtGraphicsListViewPrivate)
@@ -492,6 +485,7 @@ QtGraphicsListView::QtGraphicsListView(Qt::Orientation orientation, QGraphicsWid
}
/*!
+ \internal
*/
QtGraphicsListView::QtGraphicsListView(QtGraphicsListViewPrivate &dd, Qt::Orientation orientation, QGraphicsWidget *parent, Qt::WindowFlags wFlags)
: QGraphicsWidget(parent, wFlags), d_ptr(&dd)
@@ -502,6 +496,9 @@ QtGraphicsListView::QtGraphicsListView(QtGraphicsListViewPrivate &dd, Qt::Orient
}
/*!
+ Returns a pointer to the controller for the view.
+
+ \sa setController()
*/
QtListController *QtGraphicsListView::controller() const
{
@@ -510,6 +507,9 @@ QtListController *QtGraphicsListView::controller() const
}
/*!
+ Sets the controller for the view to be the given \a controller.
+
+ \sa controller()
*/
void QtGraphicsListView::setController(QtListController *controller)
{
@@ -526,6 +526,9 @@ void QtGraphicsListView::setController(QtListController *controller)
}
/*!
+ Returns a pointer to the model for the view.
+
+ \sa setModel()
*/
QtListModelInterface *QtGraphicsListView::model() const
{
@@ -534,6 +537,9 @@ QtListModelInterface *QtGraphicsListView::model() const
}
/*!
+ Sets the model for the view to be the given \a model.
+
+ \sa model()
*/
void QtGraphicsListView::setModel(QtListModelInterface *model)
{
@@ -556,6 +562,9 @@ void QtGraphicsListView::setModel(QtListModelInterface *model)
}
/*!
+ Returns a pointer to the selection manager for the view.
+
+ \sa setSelectionManager()
*/
QtListSelectionManager *QtGraphicsListView::selectionManager() const
{
@@ -564,6 +573,9 @@ QtListSelectionManager *QtGraphicsListView::selectionManager() const
}
/*!
+ Sets the selectionManager for the view to be the given \a selectionManager.
+
+ \sa selectionManager()
*/
void QtGraphicsListView::setSelectionManager(QtListSelectionManager *selectionManager)
{
@@ -642,11 +654,9 @@ QtGraphicsListView::~QtGraphicsListView()
}
/*!
- Returns the geometry given to the item
- referred to by the given \a index.
+ Returns the geometry given to the item referred to by the given \a index.
- Note that this function is potentially slow
- for non-visible items.
+ Note that this function is potentially slow for non-visible items.
\sa updateLayout()
*/
@@ -684,8 +694,7 @@ QRectF QtGraphicsListView::itemGeometry(int index) const
}
/*!
- Returns the index of the item at the
- given \a position.
+ Returns the index of the item at the given \a position.
\sa updateLayout()
*/
@@ -1154,15 +1163,17 @@ void QtGraphicsListView::initStyleOption(QStyleOptionViewItemV4 *option, int ind
}
/*!
+ Copies style option state information from the
+ given \a source to the given \a destination
*/
-void QtGraphicsListView::copyStyleOptionState(const QStyleOptionGraphicsItem *source, QStyleOptionViewItemV4 *dest)
-{
- if (source && dest) {
- dest->state = source->state;
- dest->direction = source->direction;
- dest->rect = source->rect;
- dest->fontMetrics = source->fontMetrics;
- dest->palette = source->palette;
+void QtGraphicsListView::copyStyleOptionState(const QStyleOptionGraphicsItem *source, QStyleOptionViewItemV4 *destination)
+{
+ if (source && destination) {
+ destination->state = source->state;
+ destination->direction = source->direction;
+ destination->rect = source->rect;
+ destination->fontMetrics = source->fontMetrics;
+ destination->palette = source->palette;
}
}
@@ -1251,14 +1262,4 @@ void QtGraphicsListView::itemGeometryChanged(QtGraphicsListViewItem *item)
}
}
-/*!
- \class QtGraphicsListViewItemCreatorBase
- \brief a factory baseclass to create QtGraphicsListViewItem objects for the QtGraphicsListView
-*/
-
-/*!
- \class QtGraphicsListViewItemCreator
- \brief a easy to use factory class to create QtGraphicsListViewItem objects for the QtGraphicsListView
-*/
-
#include "moc_qgraphicslistview.cpp"
diff --git a/src/qlistmodelinterface.cpp b/src/qlistmodelinterface.cpp
index f182478..c5b120a 100644
--- a/src/qlistmodelinterface.cpp
+++ b/src/qlistmodelinterface.cpp
@@ -22,6 +22,7 @@
****************************************************************************/
#include "qlistmodelinterface.h"
+#include "qdataroles_p.h"
/*!
\class QtListModelInterface
@@ -64,7 +65,27 @@ QtListModelInterface::~QtListModelInterface()
{
}
+/*!
+ Sets the data for the item at \a index to the given \a values. Returns true
+ if the data was set on the item; returns false otherwise.
+ The default implementation does not set the data, and will always return
+ false.
+*/
+bool QtListModelInterface::setData(int index, const QHash<int,QVariant> &values)
+{
+ Q_UNUSED(index);
+ Q_UNUSED(values);
+ return false;
+}
+
+/*!
+ Returns the supported roles for this model.
+ */
+QHash<int,QString> QtListModelInterface::roles() const
+{
+ return QtDataRoles::roles();
+}
/*!
\fn QHash<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const
@@ -79,16 +100,6 @@ QtListModelInterface::~QtListModelInterface()
*/
/*!
- \fn bool setData(int index, const QHash<int,QVariant> &values)
-
- Sets the data for the item at \a index to the given \a values. Returns true
- if the data was set on the item; returns false otherwise.
-
- The default implementation does not set the data, and will always return
- false.
-*/
-
-/*!
\fn void itemsInserted(int index, int count)
This signal is emitted when \a count number of items were inserted in the
diff --git a/src/qlistmodelinterface.h b/src/qlistmodelinterface.h
index 71d5630..d90d37b 100644
--- a/src/qlistmodelinterface.h
+++ b/src/qlistmodelinterface.h
@@ -42,7 +42,8 @@ public:
virtual int count() const = 0;
virtual QHash<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const = 0;
- virtual bool setData(int index, const QHash<int,QVariant> &values) { Q_UNUSED(index); Q_UNUSED(values); return false; }
+ virtual bool setData(int index, const QHash<int,QVariant> &values);
+ virtual QHash<int,QString> roles() const;
Q_SIGNALS:
void itemsInserted(int index, int count);
diff --git a/src/qlistwidgetng.cpp b/src/qlistwidgetng.cpp
index e9b3f5a..c44904c 100644
--- a/src/qlistwidgetng.cpp
+++ b/src/qlistwidgetng.cpp
@@ -219,10 +219,17 @@ void QtListWidgetNGPrivate::initialize()
/*!
\class QtListWidgetNG
\brief The QtListWidgetNG class provides an item-based list widget.
+
+ QtListWidgetNG is a QWidget sub-class that uses default constructed
+ QtListController, QtListDefaultModel and QtGraphicsListView instances
+ to show a list of items.
+
+ A QtListWidgetNG can be also be constructed with a custom controller,
+ view and/or model.
*/
/*!
- \brief Creates a new QtListWidgetNG.
+ Creates a new QtListWidgetNG with the given \a parent.
*/
QtListWidgetNG::QtListWidgetNG(QWidget *parent)
: QGraphicsView(parent), d_ptr(new QtListWidgetNGPrivate)
@@ -233,7 +240,7 @@ QtListWidgetNG::QtListWidgetNG(QWidget *parent)
}
/*!
- \brief Creates a new QtListWidgetNG with a specific controller.
+ Creates a new QtListWidgetNG with the given \a controller and \a parent.
*/
QtListWidgetNG::QtListWidgetNG(QtListController *controller, QWidget *parent)
: QGraphicsView(parent), d_ptr(new QtListWidgetNGPrivate)
@@ -247,6 +254,7 @@ QtListWidgetNG::QtListWidgetNG(QtListController *controller, QWidget *parent)
}
/*!
+ Destructor.
*/
QtListWidgetNG::~QtListWidgetNG()
{
@@ -254,9 +262,9 @@ QtListWidgetNG::~QtListWidgetNG()
}
/*!
- \brief returns the controller that is used for this view.
+ Returns the controller used by the widget.
- \sa itemModel()
+ \sa defaultModel()
*/
QtListController *QtListWidgetNG::controller() const
{
@@ -265,12 +273,12 @@ QtListController *QtListWidgetNG::controller() const
}
/*!
- \brief returns the default model that is created for this view.
+ Returns the default model.
- The QtListWidgetNG is created with a default item model to hold the content of the
- list as shown by this view. In case this list is created with a custom controller
- and that controller also holds a QtListDefaultModel, that one is returned.
- In all other cases null is returned.
+ The QtListWidgetNG is created with a default item model to hold the data
+ shown by this widget. If this list is created with a custom controller
+ with a QtListDefaultModel, the pointer to the custom model is returned.
+ Otherwise null is returned.
\sa controller()
*/
diff --git a/src/qtablemodelinterface.cpp b/src/qtablemodelinterface.cpp
index 7063fdc..d27c0a0 100644
--- a/src/qtablemodelinterface.cpp
+++ b/src/qtablemodelinterface.cpp
@@ -22,6 +22,8 @@
****************************************************************************/
#include "qtablemodelinterface.h"
+#include "qdataroles_p.h"
+
/*!
\class QtTableModelInterface
\brief api docs go here
@@ -41,6 +43,13 @@ QtTableModelInterface::~QtTableModelInterface()
{
}
+/*!
+ Sets the data for the cell at \a row and \a column to the given \a values.
+ Returns true if the data was set on the cell; returns false otherwise.
+
+ The default implementation does not set the data, and will always return
+ false.
+*/
bool QtTableModelInterface::setData(int row, int column, const QHash<int,QVariant> &values)
{
Q_UNUSED(row);
@@ -49,3 +58,10 @@ bool QtTableModelInterface::setData(int row, int column, const QHash<int,QVarian
return false;
}
+/*!
+ Returns the supported roles for this model.
+ */
+QHash<int,QString> QtTableModelInterface::roles() const
+{
+ return QtDataRoles::roles();
+}
diff --git a/src/qtablemodelinterface.h b/src/qtablemodelinterface.h
index cab8306..78f6dad 100644
--- a/src/qtablemodelinterface.h
+++ b/src/qtablemodelinterface.h
@@ -44,6 +44,7 @@ public:
virtual int columnCount() const = 0;
virtual QHash<int,QVariant> data(int row, int column, const QList<int> &roles = QList<int>()) const = 0;
virtual bool setData(int row, int column, const QHash<int,QVariant> &values);
+ virtual QHash<int,QString> roles() const;
// ### we may need something along the lines of cacheHint() that gives the model an idea
// ### of what can be kept, what can be thrown away and what needs to be fetched
diff --git a/src/qtreemodelbase.h b/src/qtreemodelbase.h
index 8e6d85e..c821444 100644
--- a/src/qtreemodelbase.h
+++ b/src/qtreemodelbase.h
@@ -153,6 +153,7 @@ public:
virtual ~QtTreeModelBase() {}
virtual iterator_base begin() = 0;
virtual int columnCount() const = 0;
+ // QHash<int,QString> roles() const = 0; // ### FIXME
Q_SIGNALS:
void itemsInserted(const QtTreeModelBase::iterator_base &it, int count);
diff --git a/src/src.pro b/src/src.pro
index 0edf694..f371479 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -49,6 +49,7 @@ HEADERS += qgraphicsscrollbar.h \
qtreeselectionmanager_p.h \
qtreewidgetng.h \
qtreewidgetng_p.h \
+ qdataroles_p.h \
# experimental/qlistiteminterface.h \
experimental/qgraphicsflowview.h \
experimental/qgraphicspathview.h \
diff --git a/tests/qgraphicstableview/tst_qgraphicstableview.cpp b/tests/qgraphicstableview/tst_qgraphicstableview.cpp
index a9afac7..845895a 100644
--- a/tests/qgraphicstableview/tst_qgraphicstableview.cpp
+++ b/tests/qgraphicstableview/tst_qgraphicstableview.cpp
@@ -141,7 +141,7 @@ void tst_QtGraphicsTableView::cellGeometry_data()
<< 0. << 0. // offsets
<< QList<QRectF>(); // expected geometries
- QTest::newRow("1 row, 1 column, all visible")
+ QTest::newRow("1 row, 1 column")
<< 1 << 1
<< QSizeF(100, 100)
<< 0 << 0