From 9e565e355221d38c05d19002f040d6af7ce07735 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 22 Nov 2018 08:06:07 +0100 Subject: Cleanup: make "struct dive *" and "struct dive_trip *" Qt metatypes Just as we did for pointer to struct dive_site, make pointers to struct dive and struct dive_trip "Qt metatypes". This means that they can be passed through QVariants without taking a detour via void *. Signed-off-by: Berthold Stoeger --- qt-models/divetripmodel.cpp | 4 ++-- qt-models/filtermodels.cpp | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'qt-models') diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index c2d9e62a9..51284c41d 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -51,7 +51,7 @@ QVariant DiveTripModel::tripData(const dive_trip *trip, int column, int role) bool oneDayTrip=true; if (role == TRIP_ROLE) - return QVariant::fromValue((void *)trip); // Not nice: casting away a const + return QVariant::fromValue(const_cast(trip)); // Not nice: casting away a const if (role == Qt::DisplayRole) { switch (column) { @@ -248,7 +248,7 @@ QVariant DiveTripModel::diveData(const struct dive *d, int column, int role) case STAR_ROLE: return d->rating; case DIVE_ROLE: - return QVariant::fromValue((void *)d); // Not nice: casting away a const + return QVariant::fromValue(const_cast(d)); // Not nice: casting away a const case DIVE_IDX: return get_divenr(d); case SELECTED_ROLE: diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp index d485684f3..4063ba149 100644 --- a/qt-models/filtermodels.cpp +++ b/qt-models/filtermodels.cpp @@ -619,16 +619,14 @@ bool MultiFilterSortModel::showDive(const struct dive *d) const bool MultiFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { QModelIndex index0 = sourceModel()->index(source_row, 0, source_parent); - QVariant diveVariant = sourceModel()->data(index0, DiveTripModel::DIVE_ROLE); - struct dive *d = (struct dive *)diveVariant.value(); + struct dive *d = sourceModel()->data(index0, DiveTripModel::DIVE_ROLE).value(); // For dives, simply check the hidden_by_filter flag if (d) return !d->hidden_by_filter; // Since this is not a dive, it must be a trip - QVariant tripVariant = sourceModel()->data(index0, DiveTripModel::TRIP_ROLE); - dive_trip *trip = (dive_trip *)tripVariant.value(); + dive_trip *trip = sourceModel()->data(index0, DiveTripModel::TRIP_ROLE).value(); if (!trip) return false; // Oops. Neither dive nor trip, something is seriously wrong. -- cgit v1.2.3-70-g09d2