aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-02-02 13:48:23 +0100
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-02-09 08:47:23 +0000
commit59a9c7c3d9edeb9420bf17c5913484daaf5b1ff5 (patch)
tree9af91cd68db17148a95f7e1cd32f7ec7d895d954 /src
parente4cfd64ed2458c45fe13e5fed611952632d69156 (diff)
QQmlDelegateModel: add support for row and column (revision 2.12)
Add support for setting row and column count directly on QQmlDelegateModel. Change-Id: If171e52764795f98b43753c9524a6740d9c944cf Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/types/qqmldelegatemodel.cpp119
-rw-r--r--src/qml/types/qqmldelegatemodel_p.h12
-rw-r--r--src/qml/types/qqmldelegatemodel_p_p.h3
-rw-r--r--src/qml/types/qqmlmodelsmodule.cpp1
4 files changed, 135 insertions, 0 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp
index 3892ce1356..98b34a980d 100644
--- a/src/qml/types/qqmldelegatemodel.cpp
+++ b/src/qml/types/qqmldelegatemodel.cpp
@@ -487,6 +487,125 @@ void QQmlDelegateModel::setRootIndex(const QVariant &root)
}
/*!
+ \qmlproperty int QtQml.Models::DelegateModel::rows
+
+ Contains the number of rows in the model. If the model
+ is a list of items, it will be equal to the number of items
+ in the list.
+
+ \since QtQml.Models 2.12
+*/
+int QQmlDelegateModel::rows() const
+{
+ Q_D(const QQmlDelegateModel);
+ return d->m_adaptorModel.rowCount();
+}
+
+void QQmlDelegateModelPrivate::setRows(int rows)
+{
+ Q_Q(QQmlDelegateModel);
+ const bool changed = m_adaptorModel.rowCount() != rows;
+
+ if (changed || !m_adaptorModel.isValid()) {
+ const int oldCount = m_count;
+
+ if (rows > 0)
+ m_adaptorModel.rows = rows;
+ else
+ m_adaptorModel.rows.invalidate();
+
+ // Check if the previous layout was invalidated, and if so, reconnect the model
+ if (!m_adaptorModel.isValid() && m_adaptorModel.aim())
+ m_adaptorModel.setModel(m_adaptorModel.list.list(), q, m_context->engine());
+
+ if (m_adaptorModel.canFetchMore())
+ m_adaptorModel.fetchMore();
+
+ if (m_complete) {
+ const int newCount = m_adaptorModel.count();
+ if (oldCount)
+ q->_q_itemsRemoved(0, oldCount);
+ if (newCount)
+ q->_q_itemsInserted(0, newCount);
+ }
+
+ if (changed)
+ emit q->rowsChanged();
+ }
+}
+
+void QQmlDelegateModel::setRows(int rows)
+{
+ Q_D(QQmlDelegateModel);
+ d->setRows(rows);
+}
+
+void QQmlDelegateModel::resetRows()
+{
+ Q_D(QQmlDelegateModel);
+ d->setRows(-1);
+}
+
+/*!
+ \qmlproperty int QtQml.Models::DelegateModel::columns
+
+ Contains the number of columns in the model. If the model
+ is a list of items, it will be equal to \c 1.
+
+ \since QtQml.Models 2.12
+*/
+int QQmlDelegateModel::columns() const
+{
+ Q_D(const QQmlDelegateModel);
+ return d->m_adaptorModel.columnCount();
+}
+
+void QQmlDelegateModelPrivate::setColumns(int columns)
+{
+ Q_Q(QQmlDelegateModel);
+ const bool changed = m_adaptorModel.columnCount() != columns;
+
+ if (changed || !m_adaptorModel.isValid()) {
+ const int oldCount = m_count;
+
+ if (columns > 1)
+ m_adaptorModel.columns = columns;
+ else
+ m_adaptorModel.columns.invalidate();
+
+ // Check if the previous layout was invalidated, and if so, reconnect the model
+ if (!m_adaptorModel.isValid() && m_adaptorModel.aim())
+ m_adaptorModel.setModel(m_adaptorModel.list.list(), q, m_context->engine());
+
+ if (m_adaptorModel.canFetchMore())
+ m_adaptorModel.fetchMore();
+
+ if (m_complete) {
+ const int newCount = m_adaptorModel.count();
+ if (oldCount)
+ q->_q_itemsRemoved(0, oldCount);
+ if (newCount)
+ q->_q_itemsInserted(0, newCount);
+ }
+
+ if (changed)
+ emit q->columnsChanged();
+ }
+}
+
+void QQmlDelegateModel::setColumns(int columns)
+{
+ Q_D(QQmlDelegateModel);
+ d->setColumns(columns);
+}
+
+void QQmlDelegateModel::resetColumns()
+{
+ Q_D(QQmlDelegateModel);
+ d->setColumns(-1);
+}
+
+/*!
\qmlmethod QModelIndex QtQml.Models::DelegateModel::modelIndex(int index)
QAbstractItemModel provides a hierarchical tree of data, whereas
diff --git a/src/qml/types/qqmldelegatemodel_p.h b/src/qml/types/qqmldelegatemodel_p.h
index 71179fd8be..244108d082 100644
--- a/src/qml/types/qqmldelegatemodel_p.h
+++ b/src/qml/types/qqmldelegatemodel_p.h
@@ -86,6 +86,8 @@ class Q_QML_PRIVATE_EXPORT QQmlDelegateModel : public QQmlInstanceModel, public
Q_PROPERTY(QQmlListProperty<QQmlDelegateModelGroup> groups READ groups CONSTANT)
Q_PROPERTY(QObject *parts READ parts CONSTANT)
Q_PROPERTY(QVariant rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged)
+ Q_PROPERTY(int rows READ rows WRITE setRows RESET resetRows NOTIFY rowsChanged REVISION 12)
+ Q_PROPERTY(int columns READ columns WRITE setColumns RESET resetColumns NOTIFY columnsChanged REVISION 12)
Q_CLASSINFO("DefaultProperty", "delegate")
Q_INTERFACES(QQmlParserStatus)
public:
@@ -105,6 +107,14 @@ public:
QVariant rootIndex() const;
void setRootIndex(const QVariant &root);
+ int rows() const;
+ void setRows(int rows);
+ void resetRows();
+
+ int columns() const;
+ void setColumns(int columns);
+ void resetColumns();
+
Q_INVOKABLE QVariant modelIndex(int idx) const;
Q_INVOKABLE QVariant parentModelIndex() const;
@@ -136,6 +146,8 @@ Q_SIGNALS:
void filterGroupChanged();
void defaultGroupsChanged();
void rootIndexChanged();
+ Q_REVISION(12) void rowsChanged();
+ Q_REVISION(12) void columnsChanged();
private Q_SLOTS:
void _q_itemsChanged(int index, int count, const QVector<int> &roles);
diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h
index 7b60bcddc0..aa2a3fcd42 100644
--- a/src/qml/types/qqmldelegatemodel_p_p.h
+++ b/src/qml/types/qqmldelegatemodel_p_p.h
@@ -301,6 +301,9 @@ public:
void incubatorStatusChanged(QQDMIncubationTask *incubationTask, QQmlIncubator::Status status);
void setInitialState(QQDMIncubationTask *incubationTask, QObject *o);
+ void setRows(int rows);
+ void setColumns(int columns);
+
QQmlAdaptorModel m_adaptorModel;
QQmlListCompositor m_compositor;
QQmlComponent *m_delegate;
diff --git a/src/qml/types/qqmlmodelsmodule.cpp b/src/qml/types/qqmlmodelsmodule.cpp
index c36e26a525..a55d7af25d 100644
--- a/src/qml/types/qqmlmodelsmodule.cpp
+++ b/src/qml/types/qqmlmodelsmodule.cpp
@@ -52,6 +52,7 @@ void QQmlModelsModule::defineModule()
qmlRegisterType<QQmlListElement>(uri, 2, 1, "ListElement");
qmlRegisterCustomType<QQmlListModel>(uri, 2, 1, "ListModel", new QQmlListModelParser);
qmlRegisterType<QQmlDelegateModel>(uri, 2, 1, "DelegateModel");
+ qmlRegisterType<QQmlDelegateModel,12>(uri, 2, 9, "DelegateModel");
qmlRegisterType<QQmlDelegateModelGroup>(uri, 2, 1, "DelegateModelGroup");
qmlRegisterType<QQmlObjectModel>(uri, 2, 1, "ObjectModel");
qmlRegisterType<QQmlObjectModel,3>(uri, 2, 3, "ObjectModel");