File indexing completed on 2024-05-05 03:49:18
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2012 Dennis Nienhüser <nienhueser@kde.org> 0004 // 0005 0006 #ifndef MARBLE_DECLARATIVE_OFFLINEDATAMODEL_H 0007 #define MARBLE_DECLARATIVE_OFFLINEDATAMODEL_H 0008 0009 #include "NewstuffModel.h" 0010 0011 #include <QSortFilterProxyModel> 0012 0013 class OfflineDataModel : public QSortFilterProxyModel 0014 { 0015 Q_OBJECT 0016 0017 Q_PROPERTY( int count READ count NOTIFY countChanged ) 0018 0019 Q_FLAGS(VehicleType VehicleTypes) 0020 0021 public: 0022 enum VehicleType { 0023 None = 0x0, 0024 Motorcar = 0x1, 0025 Bicycle = 0x2, 0026 Pedestrian = 0x4, 0027 Any = Motorcar | Bicycle | Pedestrian 0028 }; 0029 0030 Q_DECLARE_FLAGS(VehicleTypes, VehicleType) 0031 0032 explicit OfflineDataModel( QObject* parent = nullptr ); 0033 0034 /** @todo FIXME https://bugreports.qt-project.org/browse/QTCOMPONENTS-1206 */ 0035 int count() const; 0036 0037 QHash<int, QByteArray> roleNames() const override; 0038 0039 QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const override; 0040 0041 public Q_SLOTS: 0042 void setVehicleTypeFilter( VehicleTypes filter ); 0043 0044 void install( int index ); 0045 0046 void uninstall( int index ); 0047 0048 void cancel( int index ); 0049 0050 Q_SIGNALS: 0051 void countChanged(); 0052 0053 void installationProgressed( int newstuffindex, qreal progress ); 0054 0055 void installationFinished( int newstuffindex ); 0056 0057 void installationFailed( int newstuffindex, const QString &error ); 0058 0059 void uninstallationFinished( int newstuffindex ); 0060 0061 protected: 0062 bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override; 0063 0064 private Q_SLOTS: 0065 void handleInstallationProgress( int index, qreal progress ); 0066 0067 void handleInstallationFinished( int index ); 0068 0069 void handleInstallationFailed( int index, const QString &error ); 0070 0071 void handleUninstallationFinished( int index ); 0072 0073 private: 0074 int fromSource( int idx ) const; 0075 0076 int toSource( int idx ) const; 0077 0078 Marble::NewstuffModel m_newstuffModel; 0079 0080 VehicleTypes m_vehicleTypeFilter; 0081 0082 QHash<int, QByteArray> m_roleNames; 0083 }; 0084 0085 #endif