aboutsummaryrefslogtreecommitdiffstats
path: root/src/labs/models
diff options
context:
space:
mode:
Diffstat (limited to 'src/labs/models')
-rw-r--r--src/labs/models/CMakeLists.txt4
-rw-r--r--src/labs/models/doc/src/qmllabsmodels.qdoc4
-rw-r--r--src/labs/models/qqmldelegatecomponent.cpp26
-rw-r--r--src/labs/models/qqmldelegatecomponent_p.h23
-rw-r--r--src/labs/models/qqmlmodelsglobal_p.h2
-rw-r--r--src/labs/models/qqmltablemodel.cpp2
-rw-r--r--src/labs/models/qqmltablemodel_p.h11
-rw-r--r--src/labs/models/qqmltablemodelcolumn.cpp82
-rw-r--r--src/labs/models/qqmltablemodelcolumn_p.h6
9 files changed, 90 insertions, 70 deletions
diff --git a/src/labs/models/CMakeLists.txt b/src/labs/models/CMakeLists.txt
index 3ff03fb0cd..0ae2d7d16e 100644
--- a/src/labs/models/CMakeLists.txt
+++ b/src/labs/models/CMakeLists.txt
@@ -15,9 +15,7 @@ qt_internal_add_qml_module(LabsQmlModels
Qt::QmlPrivate
DEPENDENCIES
QtQml.Models/auto
- GENERATE_CPP_EXPORTS
- GENERATE_PRIVATE_CPP_EXPORTS
-)
+ )
qt_internal_extend_target(LabsQmlModels CONDITION QT_FEATURE_qml_table_model
SOURCES
diff --git a/src/labs/models/doc/src/qmllabsmodels.qdoc b/src/labs/models/doc/src/qmllabsmodels.qdoc
index f5e18792ab..8c4fbb17b7 100644
--- a/src/labs/models/doc/src/qmllabsmodels.qdoc
+++ b/src/labs/models/doc/src/qmllabsmodels.qdoc
@@ -12,7 +12,7 @@
To use the types in this module, import the module with the following line:
- \code
+ \qml
import Qt.labs.qmlmodels
- \endcode
+ \endqml
*/
diff --git a/src/labs/models/qqmldelegatecomponent.cpp b/src/labs/models/qqmldelegatecomponent.cpp
index 3a9bb647c6..01dbe7e81f 100644
--- a/src/labs/models/qqmldelegatecomponent.cpp
+++ b/src/labs/models/qqmldelegatecomponent.cpp
@@ -21,7 +21,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \qmlproperty variant QtQml.Models::DelegateChoice::roleValue
+ \qmlproperty variant Qt.labs.qmlmodels::DelegateChoice::roleValue
This property holds the value used to match the role data for the role provided by \l DelegateChooser::role.
*/
QVariant QQmlDelegateChoice::roleValue() const
@@ -39,7 +39,7 @@ void QQmlDelegateChoice::setRoleValue(const QVariant &value)
}
/*!
- \qmlproperty int QtQml.Models::DelegateChoice::row
+ \qmlproperty int Qt.labs.qmlmodels::DelegateChoice::row
This property holds the value used to match the row value of model elements.
With models that have only the index property (and thus only one column), this property
should be intended as an index, and set to the desired index value.
@@ -51,7 +51,7 @@ void QQmlDelegateChoice::setRoleValue(const QVariant &value)
*/
/*!
- \qmlproperty int QtQml.Models::DelegateChoice::index
+ \qmlproperty int Qt.labs.qmlmodels::DelegateChoice::index
This property holds the value used to match the index value of model elements.
This is effectively an alias for \l row.
@@ -73,7 +73,7 @@ void QQmlDelegateChoice::setRow(int r)
}
/*!
- \qmlproperty int QtQml.Models::DelegateChoice::column
+ \qmlproperty int Qt.labs.qmlmodels::DelegateChoice::column
This property holds the value used to match the column value of model elements.
*/
int QQmlDelegateChoice::column() const
@@ -96,7 +96,7 @@ QQmlComponent *QQmlDelegateChoice::delegate() const
}
/*!
- \qmlproperty Component QtQml.Models::DelegateChoice::delegate
+ \qmlproperty Component Qt.labs.qmlmodels::DelegateChoice::delegate
This property holds the delegate to use if this choice matches the model item.
*/
void QQmlDelegateChoice::setDelegate(QQmlComponent *delegate)
@@ -190,9 +190,13 @@ bool QQmlDelegateChoice::match(int row, int column, const QVariant &value) const
*/
/*!
- \qmlproperty string QtQml.Models::DelegateChooser::role
+ \qmlproperty string Qt.labs.qmlmodels::DelegateChooser::role
This property holds the role or the property name used to determine the delegate for a given model item.
+ \note For \l{QAbstractItemModel} based models, including \l{ListModel}, the DelegateChooser will
+ reevaluate the choice when the model signals that the role has changed. For any other type of model,
+ this choice will only be done once when the item for a given model index is created.
+
\sa DelegateChoice
*/
void QQmlDelegateChooser::setRole(const QString &role)
@@ -204,7 +208,7 @@ void QQmlDelegateChooser::setRole(const QString &role)
}
/*!
- \qmlproperty list<DelegateChoice> QtQml.Models::DelegateChooser::choices
+ \qmlproperty list<DelegateChoice> Qt.labs.qmlmodels::DelegateChooser::choices
\qmldefault
The list of DelegateChoices for the chooser.
@@ -233,7 +237,7 @@ void QQmlDelegateChooser::choices_append(QQmlListProperty<QQmlDelegateChoice> *p
QQmlDelegateChooser *q = static_cast<QQmlDelegateChooser *>(prop->object);
q->m_choices.append(choice);
connect(choice, &QQmlDelegateChoice::changed, q, &QQmlAbstractDelegateComponent::delegateChanged);
- q->delegateChanged();
+ emit q->delegateChanged();
}
qsizetype QQmlDelegateChooser::choices_count(QQmlListProperty<QQmlDelegateChoice> *prop)
@@ -254,7 +258,7 @@ void QQmlDelegateChooser::choices_clear(QQmlListProperty<QQmlDelegateChoice> *pr
for (QQmlDelegateChoice *choice : q->m_choices)
disconnect(choice, &QQmlDelegateChoice::changed, q, &QQmlAbstractDelegateComponent::delegateChanged);
q->m_choices.clear();
- q->delegateChanged();
+ emit q->delegateChanged();
}
void QQmlDelegateChooser::choices_replace(QQmlListProperty<QQmlDelegateChoice> *prop,
@@ -266,7 +270,7 @@ void QQmlDelegateChooser::choices_replace(QQmlListProperty<QQmlDelegateChoice> *
q->m_choices[index] = choice;
connect(choice, &QQmlDelegateChoice::changed, q,
&QQmlAbstractDelegateComponent::delegateChanged);
- q->delegateChanged();
+ emit q->delegateChanged();
}
void QQmlDelegateChooser::choices_removeLast(QQmlListProperty<QQmlDelegateChoice> *prop)
@@ -274,7 +278,7 @@ void QQmlDelegateChooser::choices_removeLast(QQmlListProperty<QQmlDelegateChoice
QQmlDelegateChooser *q = static_cast<QQmlDelegateChooser *>(prop->object);
disconnect(q->m_choices.takeLast(), &QQmlDelegateChoice::changed,
q, &QQmlAbstractDelegateComponent::delegateChanged);
- q->delegateChanged();
+ emit q->delegateChanged();
}
QQmlComponent *QQmlDelegateChooser::delegate(QQmlAdaptorModel *adaptorModel, int row, int column) const
diff --git a/src/labs/models/qqmldelegatecomponent_p.h b/src/labs/models/qqmldelegatecomponent_p.h
index 254f9d0b7e..2929094fd6 100644
--- a/src/labs/models/qqmldelegatecomponent_p.h
+++ b/src/labs/models/qqmldelegatecomponent_p.h
@@ -25,14 +25,14 @@ QT_REQUIRE_CONFIG(qml_delegate_model);
QT_BEGIN_NAMESPACE
-class Q_LABSQMLMODELS_PRIVATE_EXPORT QQmlDelegateChoice : public QObject
+class Q_LABSQMLMODELS_EXPORT QQmlDelegateChoice : public QObject
{
Q_OBJECT
- Q_PROPERTY(QVariant roleValue READ roleValue WRITE setRoleValue NOTIFY roleValueChanged)
- Q_PROPERTY(int row READ row WRITE setRow NOTIFY rowChanged)
- Q_PROPERTY(int index READ row WRITE setRow NOTIFY indexChanged)
- Q_PROPERTY(int column READ column WRITE setColumn NOTIFY columnChanged)
- Q_PROPERTY(QQmlComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
+ Q_PROPERTY(QVariant roleValue READ roleValue WRITE setRoleValue NOTIFY roleValueChanged FINAL)
+ Q_PROPERTY(int row READ row WRITE setRow NOTIFY rowChanged FINAL)
+ Q_PROPERTY(int index READ row WRITE setRow NOTIFY indexChanged FINAL)
+ Q_PROPERTY(int column READ column WRITE setColumn NOTIFY columnChanged FINAL)
+ Q_PROPERTY(QQmlComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL)
Q_CLASSINFO("DefaultProperty", "delegate")
QML_NAMED_ELEMENT(DelegateChoice)
QML_ADDED_IN_VERSION(1, 0)
@@ -67,17 +67,17 @@ private:
QQmlComponent *m_delegate = nullptr;
};
-class Q_LABSQMLMODELS_PRIVATE_EXPORT QQmlDelegateChooser : public QQmlAbstractDelegateComponent
+class Q_LABSQMLMODELS_EXPORT QQmlDelegateChooser : public QQmlAbstractDelegateComponent
{
Q_OBJECT
- Q_PROPERTY(QString role READ role WRITE setRole NOTIFY roleChanged)
- Q_PROPERTY(QQmlListProperty<QQmlDelegateChoice> choices READ choices CONSTANT)
+ Q_PROPERTY(QString role READ role WRITE setRole NOTIFY roleChanged FINAL)
+ Q_PROPERTY(QQmlListProperty<QQmlDelegateChoice> choices READ choices CONSTANT FINAL)
Q_CLASSINFO("DefaultProperty", "choices")
QML_NAMED_ELEMENT(DelegateChooser)
QML_ADDED_IN_VERSION(1, 0)
public:
- QString role() const { return m_role; }
+ QString role() const final { return m_role; }
void setRole(const QString &role);
virtual QQmlListProperty<QQmlDelegateChoice> choices();
@@ -101,7 +101,4 @@ private:
QT_END_NAMESPACE
-QML_DECLARE_TYPE(QQmlDelegateChoice)
-QML_DECLARE_TYPE(QQmlDelegateChooser)
-
#endif // QQMLDELEGATECOMPONENT_P_H
diff --git a/src/labs/models/qqmlmodelsglobal_p.h b/src/labs/models/qqmlmodelsglobal_p.h
index 9f1e325e6e..72efdfa4b5 100644
--- a/src/labs/models/qqmlmodelsglobal_p.h
+++ b/src/labs/models/qqmlmodelsglobal_p.h
@@ -17,6 +17,6 @@
// We mean it.
//
-#include <QtLabsQmlModels/private/qtlabsqmlmodelsexports_p.h>
+#include <QtLabsQmlModels/qtlabsqmlmodelsexports.h>
#endif // QTLABSQMLMODELSGLOBAL_P_H
diff --git a/src/labs/models/qqmltablemodel.cpp b/src/labs/models/qqmltablemodel.cpp
index 6b14eeaaef..adf187f225 100644
--- a/src/labs/models/qqmltablemodel.cpp
+++ b/src/labs/models/qqmltablemodel.cpp
@@ -9,7 +9,7 @@
QT_BEGIN_NAMESPACE
-Q_LOGGING_CATEGORY(lcTableModel, "qt.qml.tablemodel")
+Q_STATIC_LOGGING_CATEGORY(lcTableModel, "qt.qml.tablemodel")
/*!
\qmltype TableModel
diff --git a/src/labs/models/qqmltablemodel_p.h b/src/labs/models/qqmltablemodel_p.h
index 2df813dfcd..9157c989d3 100644
--- a/src/labs/models/qqmltablemodel_p.h
+++ b/src/labs/models/qqmltablemodel_p.h
@@ -30,7 +30,7 @@ QT_REQUIRE_CONFIG(qml_table_model);
QT_BEGIN_NAMESPACE
-class Q_LABSQMLMODELS_PRIVATE_EXPORT QQmlTableModel : public QAbstractTableModel, public QQmlParserStatus
+class Q_LABSQMLMODELS_EXPORT QQmlTableModel : public QAbstractTableModel, public QQmlParserStatus
{
Q_OBJECT
Q_PROPERTY(int columnCount READ columnCount NOTIFY columnCountChanged FINAL)
@@ -81,6 +81,10 @@ Q_SIGNALS:
void rowCountChanged();
void rowsChanged();
+protected:
+ void classBegin() override;
+ void componentComplete() override;
+
private:
class ColumnRoleMetadata
{
@@ -122,9 +126,6 @@ private:
void doInsert(int rowIndex, const QVariant &row);
- void classBegin() override;
- void componentComplete() override;
-
bool componentCompleted = false;
QVariantList mRows;
QList<QQmlTableModelColumn *> mColumns;
@@ -139,6 +140,4 @@ private:
QT_END_NAMESPACE
-QML_DECLARE_TYPE(QQmlTableModel)
-
#endif // QQMLTABLEMODEL_P_H
diff --git a/src/labs/models/qqmltablemodelcolumn.cpp b/src/labs/models/qqmltablemodelcolumn.cpp
index f2e6d65f87..356cad476f 100644
--- a/src/labs/models/qqmltablemodelcolumn.cpp
+++ b/src/labs/models/qqmltablemodelcolumn.cpp
@@ -18,27 +18,50 @@ QT_BEGIN_NAMESPACE
TableModelColumn supports all of \l {Qt::ItemDataRole}{Qt's roles},
with the exception of \c Qt::InitialSortOrderRole.
+ Roles can be accessed by as listed below, e.g.
+ \code
+ text: display
+
+ required property string display
+ \endcode
+
+ \table
+ \row \li Qt::DisplayRole \li display
+ \row \li Qt::DecorationRole \li decoration
+ \row \li Qt::EditRole \li edit
+ \row \li Qt::ToolTipRole \li toolTip
+ \row \li Qt::StatusTipRole \li statusTip
+ \row \li Qt::WhatsThisRole \li whatsThis
+ \row \li Qt::FontRole \li font
+ \row \li Qt::TextAlignmentRole \li textAlignment
+ \row \li Qt::BackgroundRole \li background
+ \row \li Qt::ForegroundRole \li foreground
+ \row \li Qt::CheckStateRole \li checkState
+ \row \li Qt::AccessibleTextRole \li accessibleText
+ \row \li Qt::AccessibleDescriptionRole \li accessibleDescription
+ \row \li Qt::SizeHintRole \li sizeHintRoleNam
+ \endtable
\sa TableModel, TableView
*/
-static const QString displayRoleName = QStringLiteral("display");
-static const QString decorationRoleName = QStringLiteral("decoration");
-static const QString editRoleName = QStringLiteral("edit");
-static const QString toolTipRoleName = QStringLiteral("toolTip");
-static const QString statusTipRoleName = QStringLiteral("statusTip");
-static const QString whatsThisRoleName = QStringLiteral("whatsThis");
+static constexpr QLatin1StringView displayRoleName("display");
+static constexpr QLatin1StringView decorationRoleName("decoration");
+static constexpr QLatin1StringView editRoleName("edit");
+static constexpr QLatin1StringView toolTipRoleName("toolTip");
+static constexpr QLatin1StringView statusTipRoleName("statusTip");
+static constexpr QLatin1StringView whatsThisRoleName("whatsThis");
-static const QString fontRoleName = QStringLiteral("font");
-static const QString textAlignmentRoleName = QStringLiteral("textAlignment");
-static const QString backgroundRoleName = QStringLiteral("background");
-static const QString foregroundRoleName = QStringLiteral("foreground");
-static const QString checkStateRoleName = QStringLiteral("checkState");
+static constexpr QLatin1StringView fontRoleName("font");
+static constexpr QLatin1StringView textAlignmentRoleName("textAlignment");
+static constexpr QLatin1StringView backgroundRoleName("background");
+static constexpr QLatin1StringView foregroundRoleName("foreground");
+static constexpr QLatin1StringView checkStateRoleName("checkState");
-static const QString accessibleTextRoleName = QStringLiteral("accessibleText");
-static const QString accessibleDescriptionRoleName = QStringLiteral("accessibleDescription");
+static constexpr QLatin1StringView accessibleTextRoleName("accessibleText");
+static constexpr QLatin1StringView accessibleDescriptionRoleName("accessibleDescription");
-static const QString sizeHintRoleName = QStringLiteral("sizeHint");
+static constexpr QLatin1StringView sizeHintRoleName("sizeHint");
QQmlTableModelColumn::QQmlTableModelColumn(QObject *parent)
@@ -143,21 +166,22 @@ const QHash<QString, QJSValue> QQmlTableModelColumn::getters() const
const QHash<int, QString> QQmlTableModelColumn::supportedRoleNames()
{
- QHash<int, QString> names;
- names[Qt::DisplayRole] = QLatin1String("display");
- names[Qt::DecorationRole] = QLatin1String("decoration");
- names[Qt::EditRole] = QLatin1String("edit");
- names[Qt::ToolTipRole] = QLatin1String("toolTip");
- names[Qt::StatusTipRole] = QLatin1String("statusTip");
- names[Qt::WhatsThisRole] = QLatin1String("whatsThis");
- names[Qt::FontRole] = QLatin1String("font");
- names[Qt::TextAlignmentRole] = QLatin1String("textAlignment");
- names[Qt::BackgroundRole] = QLatin1String("background");
- names[Qt::ForegroundRole] = QLatin1String("foreground");
- names[Qt::CheckStateRole] = QLatin1String("checkState");
- names[Qt::AccessibleTextRole] = QLatin1String("accessibleText");
- names[Qt::AccessibleDescriptionRole] = QLatin1String("accessibleDescription");
- names[Qt::SizeHintRole] = QLatin1String("sizeHint");
+ static const QHash<int, QString> names {
+ {Qt::DisplayRole, displayRoleName},
+ {Qt::DecorationRole, decorationRoleName},
+ {Qt::EditRole, editRoleName},
+ {Qt::ToolTipRole, toolTipRoleName},
+ {Qt::StatusTipRole, statusTipRoleName},
+ {Qt::WhatsThisRole, whatsThisRoleName},
+ {Qt::FontRole, fontRoleName},
+ {Qt::TextAlignmentRole, textAlignmentRoleName},
+ {Qt::BackgroundRole, backgroundRoleName},
+ {Qt::ForegroundRole, foregroundRoleName},
+ {Qt::CheckStateRole, checkStateRoleName},
+ {Qt::AccessibleTextRole, accessibleTextRoleName},
+ {Qt::AccessibleDescriptionRole, accessibleDescriptionRoleName},
+ {Qt::SizeHintRole, sizeHintRoleName}
+ };
return names;
}
diff --git a/src/labs/models/qqmltablemodelcolumn_p.h b/src/labs/models/qqmltablemodelcolumn_p.h
index 04ced79d16..d095343fe6 100644
--- a/src/labs/models/qqmltablemodelcolumn_p.h
+++ b/src/labs/models/qqmltablemodelcolumn_p.h
@@ -27,11 +27,11 @@ QT_REQUIRE_CONFIG(qml_table_model);
QT_BEGIN_NAMESPACE
-class Q_LABSQMLMODELS_PRIVATE_EXPORT QQmlTableModelColumn : public QObject
+class Q_LABSQMLMODELS_EXPORT QQmlTableModelColumn : public QObject
{
Q_OBJECT
Q_PROPERTY(QJSValue display READ display WRITE setDisplay NOTIFY displayChanged FINAL)
- Q_PROPERTY(QJSValue setDisplay READ getSetDisplay WRITE setSetDisplay NOTIFY setDisplayChanged)
+ Q_PROPERTY(QJSValue setDisplay READ getSetDisplay WRITE setSetDisplay NOTIFY setDisplayChanged FINAL)
Q_PROPERTY(QJSValue decoration READ decoration WRITE setDecoration NOTIFY decorationChanged FINAL)
Q_PROPERTY(QJSValue setDecoration READ getSetDecoration WRITE setSetDecoration NOTIFY setDecorationChanged FINAL)
Q_PROPERTY(QJSValue edit READ edit WRITE setEdit NOTIFY editChanged FINAL)
@@ -188,6 +188,4 @@ private:
QT_END_NAMESPACE
-QML_DECLARE_TYPE(QQmlTableModelColumn)
-
#endif // QQMLTABLEMODELCOLUMN_P_H