diff options
Diffstat (limited to 'src/qml/types')
-rw-r--r-- | src/qml/types/qqmldelegatemodel.cpp | 129 | ||||
-rw-r--r-- | src/qml/types/qqmldelegatemodel_p.h | 12 | ||||
-rw-r--r-- | src/qml/types/qqmldelegatemodel_p_p.h | 5 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel_p.h | 2 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel_p_p.h | 2 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodelworkeragent_p.h | 2 | ||||
-rw-r--r-- | src/qml/types/qqmlmodelsmodule.cpp | 5 | ||||
-rw-r--r-- | src/qml/types/qqmltimer_p.h | 2 | ||||
-rw-r--r-- | src/qml/types/qquickworkerscript.cpp | 5 | ||||
-rw-r--r-- | src/qml/types/types.pri | 18 |
10 files changed, 172 insertions, 10 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 44166e4aa8..29e0baa3ac 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 @@ -1045,7 +1164,10 @@ QQmlIncubator::Status QQmlDelegateModel::incubationStatus(int index) if (!it->inCache()) return QQmlIncubator::Null; - return d->m_cache.at(it.cacheIndex)->incubationTask->status(); + if (auto incubationTask = d->m_cache.at(it.cacheIndex)->incubationTask) + return incubationTask->status(); + + return QQmlIncubator::Ready; } QString QQmlDelegateModelPrivate::stringValue(Compositor::Group group, int index, const QString &name) @@ -3193,7 +3315,10 @@ QQmlIncubator::Status QQmlPartsModel::incubationStatus(int index) if (!it->inCache()) return QQmlIncubator::Null; - return model->m_cache.at(it.cacheIndex)->incubationTask->status(); + if (auto incubationTask = model->m_cache.at(it.cacheIndex)->incubationTask) + return incubationTask->status(); + + return QQmlIncubator::Ready; } int QQmlPartsModel::indexOf(QObject *item, QObject *) const diff --git a/src/qml/types/qqmldelegatemodel_p.h b/src/qml/types/qqmldelegatemodel_p.h index b0786cd088..707aaeaa4b 100644 --- a/src/qml/types/qqmldelegatemodel_p.h +++ b/src/qml/types/qqmldelegatemodel_p.h @@ -88,6 +88,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: @@ -107,6 +109,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; @@ -138,6 +148,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 18980cfd7c..42481be34f 100644 --- a/src/qml/types/qqmldelegatemodel_p_p.h +++ b/src/qml/types/qqmldelegatemodel_p_p.h @@ -121,7 +121,7 @@ public: int groupIndex(Compositor::Group group); int modelIndex() const { return index; } - void setModelIndex(int idx) { index = idx; Q_EMIT modelIndexChanged(); } + virtual void setModelIndex(int idx) { index = idx; Q_EMIT modelIndexChanged(); } virtual QV4::ReturnedValue get() { return QV4::QObjectWrapper::wrap(v4, this); } @@ -303,6 +303,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/qqmllistmodel_p.h b/src/qml/types/qqmllistmodel_p.h index 0c0859dc80..0a9d29ac05 100644 --- a/src/qml/types/qqmllistmodel_p.h +++ b/src/qml/types/qqmllistmodel_p.h @@ -64,6 +64,8 @@ #include <private/qv4engine_p.h> #include <private/qpodvector_p.h> +QT_REQUIRE_CONFIG(qml_list_model); + QT_BEGIN_NAMESPACE diff --git a/src/qml/types/qqmllistmodel_p_p.h b/src/qml/types/qqmllistmodel_p_p.h index ad5e94c909..99e9b30aff 100644 --- a/src/qml/types/qqmllistmodel_p_p.h +++ b/src/qml/types/qqmllistmodel_p_p.h @@ -57,6 +57,8 @@ #include <private/qv4qobjectwrapper_p.h> #include <qqml.h> +QT_REQUIRE_CONFIG(qml_list_model); + QT_BEGIN_NAMESPACE diff --git a/src/qml/types/qqmllistmodelworkeragent_p.h b/src/qml/types/qqmllistmodelworkeragent_p.h index 2120f25744..ae2d4b11e0 100644 --- a/src/qml/types/qqmllistmodelworkeragent_p.h +++ b/src/qml/types/qqmllistmodelworkeragent_p.h @@ -59,6 +59,8 @@ #include <private/qv8engine_p.h> +QT_REQUIRE_CONFIG(qml_list_model); + QT_BEGIN_NAMESPACE diff --git a/src/qml/types/qqmlmodelsmodule.cpp b/src/qml/types/qqmlmodelsmodule.cpp index e217b63c6f..d9756704d1 100644 --- a/src/qml/types/qqmlmodelsmodule.cpp +++ b/src/qml/types/qqmlmodelsmodule.cpp @@ -39,7 +39,9 @@ #include "qqmlmodelsmodule_p.h" #include <QtCore/qitemselectionmodel.h> +#if QT_CONFIG(qml_list_model) #include <private/qqmllistmodel_p.h> +#endif #if QT_CONFIG(qml_delegate_model) #include <private/qqmldelegatemodel_p.h> #endif @@ -51,10 +53,13 @@ void QQmlModelsModule::defineModule() { const char uri[] = "QtQml.Models"; +#if QT_CONFIG(qml_list_model) qmlRegisterType<QQmlListElement>(uri, 2, 1, "ListElement"); qmlRegisterCustomType<QQmlListModel>(uri, 2, 1, "ListModel", new QQmlListModelParser); +#endif #if QT_CONFIG(qml_delegate_model) qmlRegisterType<QQmlDelegateModel>(uri, 2, 1, "DelegateModel"); + qmlRegisterType<QQmlDelegateModel,12>(uri, 2, 9, "DelegateModel"); qmlRegisterType<QQmlDelegateModelGroup>(uri, 2, 1, "DelegateModelGroup"); #endif qmlRegisterType<QQmlObjectModel>(uri, 2, 1, "ObjectModel"); diff --git a/src/qml/types/qqmltimer_p.h b/src/qml/types/qqmltimer_p.h index d597869994..0160e97a2f 100644 --- a/src/qml/types/qqmltimer_p.h +++ b/src/qml/types/qqmltimer_p.h @@ -57,6 +57,8 @@ #include <private/qtqmlglobal_p.h> +QT_REQUIRE_CONFIG(qml_animation); + QT_BEGIN_NAMESPACE class QQmlTimerPrivate; diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp index ef92e4108d..634e2da1c9 100644 --- a/src/qml/types/qquickworkerscript.cpp +++ b/src/qml/types/qquickworkerscript.cpp @@ -37,9 +37,12 @@ ** ****************************************************************************/ +#include "qtqmlglobal_p.h" #include "qquickworkerscript_p.h" +#if QT_CONFIG(qml_list_model) #include "qqmllistmodel_p.h" #include "qqmllistmodelworkeragent_p.h" +#endif #include <private/qqmlengine_p.h> #include <private/qqmlexpression_p.h> @@ -201,7 +204,7 @@ private: }; QQuickWorkerScriptEnginePrivate::WorkerEngine::WorkerEngine(QQuickWorkerScriptEnginePrivate *parent) - : QV8Engine(nullptr, new QV4::ExecutionEngine), p(parent) + : QV8Engine(new QV4::ExecutionEngine), p(parent) #if QT_CONFIG(qml_network) , accessManager(nullptr) #endif diff --git a/src/qml/types/types.pri b/src/qml/types/types.pri index 8bcbd6e544..5d75759281 100644 --- a/src/qml/types/types.pri +++ b/src/qml/types/types.pri @@ -1,8 +1,6 @@ SOURCES += \ $$PWD/qqmlbind.cpp \ $$PWD/qqmlconnections.cpp \ - $$PWD/qqmllistmodel.cpp \ - $$PWD/qqmllistmodelworkeragent.cpp \ $$PWD/qqmlmodelsmodule.cpp \ $$PWD/qqmlmodelindexvaluetype.cpp \ $$PWD/qqmlobjectmodel.cpp \ @@ -13,9 +11,6 @@ SOURCES += \ HEADERS += \ $$PWD/qqmlbind_p.h \ $$PWD/qqmlconnections_p.h \ - $$PWD/qqmllistmodel_p.h \ - $$PWD/qqmllistmodel_p_p.h \ - $$PWD/qqmllistmodelworkeragent_p.h \ $$PWD/qqmlmodelsmodule_p.h \ $$PWD/qqmlmodelindexvaluetype_p.h \ $$PWD/qqmlobjectmodel_p.h \ @@ -24,6 +19,17 @@ HEADERS += \ $$PWD/qqmlinstantiator_p.h \ $$PWD/qqmlinstantiator_p_p.h +qtConfig(qml-list-model) { + SOURCES += \ + $$PWD/qqmllistmodel.cpp \ + $$PWD/qqmllistmodelworkeragent.cpp + + HEADERS += \ + $$PWD/qqmllistmodel_p.h \ + $$PWD/qqmllistmodel_p_p.h \ + $$PWD/qqmllistmodelworkeragent_p.h +} + qtConfig(qml-delegate-model) { SOURCES += \ $$PWD/qqmldelegatemodel.cpp @@ -33,7 +39,7 @@ qtConfig(qml-delegate-model) { $$PWD/qqmldelegatemodel_p_p.h } -qtConfig(animation) { +qtConfig(qml-animation) { SOURCES += \ $$PWD/qqmltimer.cpp |