diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-15 17:50:25 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-22 14:57:03 +0200 |
commit | b6d24bad6ce6f52624467a4fe4043caee6e59ab4 (patch) | |
tree | 25c074f37c186a3f6fe7adce4479c5f1b008647e /src/location/declarativeplaces/qdeclarativereviewmodel.cpp | |
parent | 30366d0850af1e5409d637652c53a8fab9a7ddc1 (diff) | |
download | qtlocation-b6d24bad6ce6f52624467a4fe4043caee6e59ab4.tar.gz |
Cleanup: QPlaceContent and subclasses (1/3)
QPlaceContent and subclasses are value types, and subclassing value
is a bad idea, for many reasons. Great care had been taken to work
around the slicing problem, resulting in lot of code and complexity.
Instead of the slicing problem, we now have the problem that we can
assign a QPlaceContent item to a QPlaceImage and back, but that same
QPlaceContent object can also be assigned to a QPlaceReview and a
QPlaceEditorial item. Those then end up as empty items. So while it
seems convenient to have C++ types, we replaced compile errors or
explicitly dynamic APIs, like QVariant, with implicit conversions that
require explicit type checks before, with the risk of silently losing
data.
Ironcially, applications access those different values then through
various QAbstractItemModel implementations - which return QVariants
anyway, requiring explicit type checking and coertion. And the C++
convenience is exclusively interesting for backend implementors, who
anyway need to parse data and identify types dynamically.
What we really need is a map of QVariants, and some information about
what kind of data we can get out of the map.
So as a first step in cleaning, replace the data storage with such a map
and remove all the subclass specific privates, together with all the
complexity (virtual functions, QSharedDataPointer::clone template
specializations, macros).
The subclasses themselves become very thin API wrappers. Their only
special feature is that they all can still be constructed from a
QPlaceContent instance. We need this for compatibility. With all the
convenience C++ APIs marked as deprecated, people can still use
those when using Qt 6.2-compatible Qt Location, and use the warnings
to prepare for Qt 6.5 where we can then remove those APIs entirely.
Change-Id: Id75f55d784fbe214a0db93d3c1f786209ef0a690
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/declarativeplaces/qdeclarativereviewmodel.cpp')
-rw-r--r-- | src/location/declarativeplaces/qdeclarativereviewmodel.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/location/declarativeplaces/qdeclarativereviewmodel.cpp b/src/location/declarativeplaces/qdeclarativereviewmodel.cpp index e8c597ac..2c4997ce 100644 --- a/src/location/declarativeplaces/qdeclarativereviewmodel.cpp +++ b/src/location/declarativeplaces/qdeclarativereviewmodel.cpp @@ -40,7 +40,7 @@ #include "qdeclarativereviewmodel_p.h" #include <QtCore/QDateTime> -#include <QtLocation/QPlaceReview> +#include <QtLocation/QPlaceContent> QT_BEGIN_NAMESPACE @@ -149,21 +149,21 @@ QVariant QDeclarativeReviewModel::data(const QModelIndex &index, int role) const if (index.row() >= rowCount(index.parent()) || index.row() < 0) return QVariant(); - const QPlaceReview &review = m_content.value(index.row()); + const QPlaceContent &content = m_content.value(index.row()); switch (role) { case DateTimeRole: - return review.dateTime(); + return content.value(QPlaceContent::ReviewDateTime); case TextRole: - return review.text(); + return content.value(QPlaceContent::ReviewText); case LanguageRole: - return review.language(); + return content.value(QPlaceContent::ReviewLanguage); case RatingRole: - return review.rating(); + return content.value(QPlaceContent::ReviewRating); case ReviewIdRole: - return review.reviewId(); + return content.value(QPlaceContent::ReviewId); case TitleRole: - return review.title(); + return content.value(QPlaceContent::ReviewTitle); } return QDeclarativePlaceContentModel::data(index, role); |