aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-03-05 10:42:55 +0100
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-04-12 13:42:10 +0000
commit340819e81cf36c01bd21a170fd1a932202257899 (patch)
tree26c5dda27fc30062fd778e21ca1594f7b5d9adf9 /src
parenta5d2fb468cabff8dc0702c7ddcd9f5b08993b827 (diff)
QQmlAdaptorModel: make a models row/column count read-only
This change partly revert 59a9c7c3d9edeb9, since we no longer make use of the introduced API. Being able to override the row/column count for a delegate model was a wrong step. If a view needs to operate on a row/column count that is different from what the model offers, then the mapping should be done in the view (or in a proxy model), and not in the delegate model. Change-Id: I32b0dfa977dd7cae33c399e138aac847e49aa94a Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/types/qqmldelegatemodel.cpp90
-rw-r--r--src/qml/types/qqmldelegatemodel_p.h9
-rw-r--r--src/qml/types/qqmldelegatemodel_p_p.h3
-rw-r--r--src/qml/util/qqmladaptormodel.cpp6
-rw-r--r--src/qml/util/qqmladaptormodel_p.h2
5 files changed, 3 insertions, 107 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp
index 27a84bc2f1..1acd9b982e 100644
--- a/src/qml/types/qqmldelegatemodel.cpp
+++ b/src/qml/types/qqmldelegatemodel.cpp
@@ -501,51 +501,6 @@ int QQmlDelegateModel::rows() const
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
@@ -560,51 +515,6 @@ int QQmlDelegateModel::columns() const
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)
diff --git a/src/qml/types/qqmldelegatemodel_p.h b/src/qml/types/qqmldelegatemodel_p.h
index 707aaeaa4b..0a76d884ed 100644
--- a/src/qml/types/qqmldelegatemodel_p.h
+++ b/src/qml/types/qqmldelegatemodel_p.h
@@ -88,8 +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_PROPERTY(int rows READ rows NOTIFY rowsChanged REVISION 12)
+ Q_PROPERTY(int columns READ columns NOTIFY columnsChanged REVISION 12)
Q_CLASSINFO("DefaultProperty", "delegate")
Q_INTERFACES(QQmlParserStatus)
public:
@@ -110,12 +110,7 @@ public:
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;
diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h
index 42481be34f..30401a2105 100644
--- a/src/qml/types/qqmldelegatemodel_p_p.h
+++ b/src/qml/types/qqmldelegatemodel_p_p.h
@@ -303,9 +303,6 @@ 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/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp
index f754e0e1a5..312466e46a 100644
--- a/src/qml/util/qqmladaptormodel.cpp
+++ b/src/qml/util/qqmladaptormodel.cpp
@@ -1000,7 +1000,7 @@ void QQmlAdaptorModel::invalidateModel(QQmlDelegateModel *vdm)
bool QQmlAdaptorModel::isValid() const
{
- return accessors != &qt_vdm_null_accessors || rows.isValid();
+ return accessors != &qt_vdm_null_accessors;
}
int QQmlAdaptorModel::count() const
@@ -1010,15 +1010,11 @@ int QQmlAdaptorModel::count() const
int QQmlAdaptorModel::rowCount() const
{
- if (rows.isValid())
- return rows.value;
return qMax(0, accessors->rowCount(*this));
}
int QQmlAdaptorModel::columnCount() const
{
- if (columns.isValid())
- return columns.value;
return qMax(isValid() ? 1 : 0, accessors->columnCount(*this));
}
diff --git a/src/qml/util/qqmladaptormodel_p.h b/src/qml/util/qqmladaptormodel_p.h
index 82a4ebfcf6..b706fcb5f2 100644
--- a/src/qml/util/qqmladaptormodel_p.h
+++ b/src/qml/util/qqmladaptormodel_p.h
@@ -106,8 +106,6 @@ public:
virtual void fetchMore(QQmlAdaptorModel &) const {}
};
- QQmlNullableValue<int> rows;
- QQmlNullableValue<int> columns;
const Accessors *accessors;
QPersistentModelIndex rootIndex;
QQmlListAccessor list;