QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
qgsprojectstoredobjectmanagermodel.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsprojectstoredobjectmanagermodel.h
3 ------------------
4 Date : January 2017
5 Copyright : (C) 2017 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSPROJECTSTOREDOBJECTMANAGERMODEL_H
17#define QGSPROJECTSTOREDOBJECTMANAGERMODEL_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
22
23#include <QAbstractListModel>
24#include <QObject>
25#include <QSortFilterProxyModel>
26
36class CORE_EXPORT QgsProjectStoredObjectManagerModelBase : public QAbstractListModel
37{
38 Q_OBJECT
39
40 public:
41 // *INDENT-OFF*
42
46 enum class CustomRole : int
47 {
48 Object = Qt::UserRole + 1,
49 IsEmptyObject,
50 };
51 Q_ENUM( CustomRole )
52 // *INDENT-ON*
53
54
58
59 int rowCount( const QModelIndex &parent ) const override;
60 QVariant data( const QModelIndex &index, int role ) const override;
61 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
62 Qt::ItemFlags flags( const QModelIndex &index ) const override;
63
64 protected slots:
65
67#ifndef SIP_RUN
68 void objectAboutToBeAdded( const QString &name );
69 void objectAboutToBeRemoved( const QString &name );
70 void objectAdded( const QString &name );
71 void objectRemoved( const QString &name );
72#endif
74
75 protected:
77#ifndef SIP_RUN
78 virtual void objectAboutToBeAddedInternal( const QString & ) {}
79 virtual void objectAboutToBeRemovedInternal( const QString & ) {}
80 virtual void objectAddedInternal( const QString & ) {}
81 virtual void objectRemovedInternal( const QString & ) {}
82
83 virtual int rowCountInternal( const QModelIndex & ) const { return 0; }
84 virtual QVariant dataInternal( const QModelIndex &, int ) const { return QVariant(); }
85 virtual bool setDataInternal( const QModelIndex &, const QVariant &, int = Qt::EditRole ) { return false; }
86 virtual Qt::ItemFlags flagsInternal( const QModelIndex & ) const { return Qt::ItemFlags(); }
87#endif
89};
90
101{
102 public:
107
112 T *objectFromIndex( const QModelIndex &index ) const;
113
118 QModelIndex indexFromObject( T *object ) const;
119
124 void setAllowEmptyObject( bool allowEmpty );
125
130 bool allowEmptyObject() const { return mAllowEmpty; }
131
132 protected:
134 int rowCountInternal( const QModelIndex &parent ) const override;
135 QVariant dataInternal( const QModelIndex &index, int role ) const override;
136 bool setDataInternal( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
137 Qt::ItemFlags flagsInternal( const QModelIndex &index ) const override;
138
139 void objectAboutToBeAddedInternal( const QString &name ) override;
140 void objectAboutToBeRemovedInternal( const QString &name ) override;
141 void objectAddedInternal( const QString &name ) override;
142 void objectRemovedInternal( const QString &name ) override;
143 void objectRenamedInternal( T *object, const QString &newName );
144 QVariant objectToVariant( T *object ) const;
146
149
150 private:
151 bool mAllowEmpty = false;
152};
153
154
165class CORE_EXPORT QgsProjectStoredObjectManagerProxyModelBase : public QSortFilterProxyModel
166{
167 Q_OBJECT
168
169 public:
173 explicit QgsProjectStoredObjectManagerProxyModelBase( QObject *parent SIP_TRANSFERTHIS = nullptr );
174 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
175 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
176
182 QString filterString() const { return mFilterString; }
183
184 public slots:
185
192 void setFilterString( const QString &filter );
193
194 protected:
202 virtual bool filterAcceptsRowInternal( int sourceRow, const QModelIndex &sourceParent ) const;
203
206};
207
208
220{
221 public:
225 explicit QgsProjectStoredObjectManagerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
226
227 protected:
228 bool filterAcceptsRowInternal( int sourceRow, const QModelIndex &sourceParent ) const override;
229};
230
231
232#endif // QGSPROJECTSTOREDOBJECTMANAGERMODEL_H
Template class for storage of a set of objects attached to a QgsProject.
Base class for list models representing the objects available in a QgsAbstractProjectStoredObjectMana...
QgsProjectStoredObjectManagerModelBase(QObject *parent=nullptr)
Constructor for QgsProjectStoredObjectManagerModelBase, with the specified parent object.
void setAllowEmptyObject(bool allowEmpty)
Sets whether an optional empty object ("not set") option is present in the model.
QModelIndex indexFromObject(T *object) const
Returns the model index corresponding to an object.
T * objectFromIndex(const QModelIndex &index) const
Returns the object at the corresponding index.
QgsProjectStoredObjectManagerModel(QgsAbstractProjectStoredObjectManager< T > *manager, QObject *parent=nullptr)
Constructor for QgsProjectStoredObjectManagerModel, showing the objects from the specified manager.
PRIVATE QgsAbstractProjectStoredObjectManager< T > * mObjectManager
Object manager.
bool allowEmptyObject() const
Returns true if the model allows the empty object ("not set") choice.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
QString filterString() const
Returns the current filter string, if set.
QgsProjectStoredObjectManagerProxyModelBase(QObject *parent=nullptr)
Constructor for QgsProjectStoredObjectManagerProxyModelBase.
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
bool filterAcceptsRowInternal(int sourceRow, const QModelIndex &sourceParent) const override
Returns true if the proxy accepts the matching source row.
QgsProjectStoredObjectManagerProxyModel(QObject *parent=nullptr)
Constructor for QgsProjectStoredObjectManagerProxyModel.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52