QGIS API Documentation 3.29.0-Master (006c3c0232)
qgscptcityarchive.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscptcityarchive.h
3 ---------------------
4 begin : August 2012
5 copyright : (C) 2009 by Martin Dobias
6 copyright : (C) 2012 by Etienne Tourigny
7 email : etourigny.dev at gmail.com
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#ifndef QGSCPTCITYARCHIVE_H
18#define QGSCPTCITYARCHIVE_H
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
22#include "qgis.h"
23#include "qgscolorrampimpl.h"
24
25#include <QAbstractItemModel>
26#include <QIcon>
27#include <QMimeData>
28
32
33#define DEFAULT_CPTCITY_ARCHIVE "cpt-city-qgis-min"
34
39class CORE_EXPORT QgsCptCityArchive
40{
41 public:
42 QgsCptCityArchive( const QString &archiveName = DEFAULT_CPTCITY_ARCHIVE,
43 const QString &baseDir = QString() );
45
47 QgsCptCityArchive( const QgsCptCityArchive &rh ) = delete;
50
51 // basic dir info
52 QString baseDir() const;
53 static QString baseDir( QString archiveName );
54 static QString defaultBaseDir();
55 void setBaseDir( const QString &dirName ) { mBaseDir = dirName; }
56
57 // collection + selection info
58 QString copyingFileName( const QString &dirName ) const;
59 QString descFileName( const QString &dirName ) const;
60 static QString findFileName( const QString &target, const QString &startDir, const QString &baseDir );
61 static QMap< QString, QString > copyingInfo( const QString &fileName );
62 static QMap< QString, QString > description( const QString &fileName );
64 static QMap< double, QPair<QColor, QColor> > gradientColorMap( const QString &fileName ) SIP_SKIP;
65
66 // archive management
67 bool isEmpty();
68 QString archiveName() const { return mArchiveName; }
69 static void initArchives( bool loadAll = false );
70 static void initArchive( const QString &archiveName, const QString &archiveBaseDir );
71 static void initDefaultArchive();
72 static void clearArchives();
73 static QgsCptCityArchive *defaultArchive();
74 static QMap< QString, QgsCptCityArchive * > archiveRegistry();
75
76 // items
77 QVector< QgsCptCityDataItem * > rootItems() const { return mRootItems; }
78 QVector< QgsCptCityDataItem * > selectionItems() const { return mSelectionItems; }
79
80 private:
81
82 QString mArchiveName;
83 QString mBaseDir;
84 // root items, namely directories at root of archive
85 QVector< QgsCptCityDataItem * > mRootItems;
86 QVector<QgsCptCityDataItem *> mSelectionItems;
87
88 private:
89#ifdef SIP_RUN
91#endif
92
93};
94
99class CORE_EXPORT QgsCptCityDataItem : public QObject
100{
101 Q_OBJECT
102 public:
103 enum Type
104 {
109 AllRamps
110 };
111
113 const QString &name, const QString &path );
114
115 bool hasChildren();
116
117 int rowCount();
118 // retrieve total count of "leaf" items (all children which are end nodes)
119 virtual int leafCount() const;
120
121 //
122
123 virtual void refresh();
124
125 // Create vector of children
126 virtual QVector<QgsCptCityDataItem *> createChildren();
127
128 // Populate children using children vector created by createChildren()
129 virtual void populate();
130 bool isPopulated() { return mPopulated; }
131
132 // Insert new child using alphabetical order based on mName, emits necessary signal to model before and after, sets parent and connects signals
133 // refresh - refresh populated item, emit signals to model
134 virtual void addChildItem( QgsCptCityDataItem *child SIP_TRANSFER, bool refresh = false );
135
136 // remove and delete child item, signals to browser are emitted
137 virtual void deleteChildItem( QgsCptCityDataItem *child );
138
139 // remove child item but don't delete it, signals to browser are emitted
140 // returns pointer to the removed item or null if no such item was found
141 virtual QgsCptCityDataItem *removeChildItem( QgsCptCityDataItem *child ) SIP_TRANSFERBACK;
142
143 virtual bool equal( const QgsCptCityDataItem *other );
144
145 virtual QWidget *paramWidget() SIP_FACTORY { return nullptr; }
146
147 // whether accepts drag&drop'd layers - e.g. for import
148 virtual bool acceptDrop() { return false; }
149
150 // try to process the data dropped on this item
151 virtual bool handleDrop( const QMimeData * /*data*/, Qt::DropAction /*action*/ ) { return false; }
152
153 // static methods
154
155 // Find child index in vector of items using '==' operator
156 static int findItem( QVector<QgsCptCityDataItem *> items, QgsCptCityDataItem *item );
157
158 // members
159
160 Type type() const { return mType; }
161 QgsCptCityDataItem *parent() const { return mParent; }
162 void setParent( QgsCptCityDataItem *parent ) { mParent = parent; }
163 QVector<QgsCptCityDataItem *> children() const { return mChildren; }
164 virtual QIcon icon() { return mIcon; }
165 virtual QIcon icon( QSize size ) { Q_UNUSED( size ) return icon(); }
166 QString name() const { return mName; }
167 QString path() const { return mPath; }
168 QString info() const { return mInfo; }
169 QString shortInfo() const { return mShortInfo; }
170
171 void setIcon( const QIcon &icon ) { mIcon = icon; }
172
173 void setToolTip( const QString &msg ) { mToolTip = msg; }
174 QString toolTip() const { return mToolTip; }
175
176 bool isValid() { return mValid; }
177
178 protected:
179
181 QgsCptCityDataItem *mParent = nullptr;
182 QVector<QgsCptCityDataItem *> mChildren; // easier to have it always
184 QString mName;
185 QString mPath; // it is also used to identify item in tree
186 QString mInfo;
187 QString mShortInfo;
188 QString mToolTip;
189 QIcon mIcon;
190 bool mValid;
191
192 signals:
193 void beginInsertItems( QgsCptCityDataItem *parent, int first, int last );
195 void beginRemoveItems( QgsCptCityDataItem *parent, int first, int last );
197};
198
204{
205 Q_OBJECT
206 public:
208 const QString &name, const QString &path,
209 const QString &variantName = QString(),
210 bool initialize = false );
212 const QString &name, const QString &path,
213 const QStringList &variantList,
214 bool initialize = false );
215
216 // --- reimplemented from QgsCptCityDataItem ---
217
218 bool equal( const QgsCptCityDataItem *other ) override;
219 int leafCount() const override { return 1; }
220
221 // --- New virtual methods for layer item derived classes ---
222 const QgsCptCityColorRamp &ramp() const { return mRamp; }
223 QIcon icon() override;
224 QIcon icon( QSize size ) override;
225 void init();
226
227 protected:
228
231 QList< QIcon > mIcons;
232};
233
234
240{
241 Q_OBJECT
242 public:
244 const QString &name, const QString &path );
245 ~QgsCptCityCollectionItem() override;
246
247 void setPopulated() { mPopulated = true; }
248 void addChild( QgsCptCityDataItem *item SIP_TRANSFER ) { mChildren.append( item ); }
249 QVector<QgsCptCityDataItem *> childrenRamps( bool recursive );
250
251 protected:
253};
254
260{
261 Q_OBJECT
262 public:
264 const QString &name, const QString &path );
265
266 QVector<QgsCptCityDataItem *> createChildren() override;
267
268 bool equal( const QgsCptCityDataItem *other ) override;
269
270 static QgsCptCityDataItem *dataItem( QgsCptCityDataItem *parent,
271 const QString &name, const QString &path );
272
273 protected:
274 QMap< QString, QStringList > rampsMap();
275 QStringList dirEntries() const;
276 QMap< QString, QStringList > mRampsMap;
277};
278
285{
286 Q_OBJECT
287 public:
288 QgsCptCitySelectionItem( QgsCptCityDataItem *parent, const QString &name, const QString &path );
289
290 QVector<QgsCptCityDataItem *> createChildren() override;
291
292 bool equal( const QgsCptCityDataItem *other ) override;
293
294 QStringList selectionsList() const { return mSelectionsList; }
295
296 protected:
297 void parseXml();
298 QStringList mSelectionsList;
299};
300
306{
307 Q_OBJECT
308 public:
309 QgsCptCityAllRampsItem( QgsCptCityDataItem *parent, const QString &name,
310 const QVector<QgsCptCityDataItem *> &items );
311
312 QVector<QgsCptCityDataItem *> createChildren() override;
313
314 protected:
315 QVector<QgsCptCityDataItem *> mItems;
316};
317
322class CORE_EXPORT QgsCptCityBrowserModel : public QAbstractItemModel
323{
324 Q_OBJECT
325
326 public:
327
329 {
330 Authors = 0,
331 Selections = 1,
332 List = 2 // not used anymore
333 };
334
335 QgsCptCityBrowserModel( QObject *parent SIP_TRANSFERTHIS = nullptr,
337 ViewType Type = Authors );
338 ~QgsCptCityBrowserModel() override;
339
340 // implemented methods from QAbstractItemModel for read-only access
341 Qt::ItemFlags flags( const QModelIndex &index ) const override;
342 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
343 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
344 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
345 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
346 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
347
348 QModelIndex findItem( QgsCptCityDataItem *item, QgsCptCityDataItem *parent = nullptr ) const;
349
350 QModelIndex parent( const QModelIndex &index ) const override;
351
353 /* virtual QStringList mimeTypes() const; */
354
356 /* virtual QMimeData * mimeData( const QModelIndexList &indexes ) const; */
357
359 /* virtual bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ); */
360
361 QgsCptCityDataItem *dataItem( const QModelIndex &idx ) const;
362
363 bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
364
365 // Reload the whole model
366 void reload();
367
368 // Refresh item specified by path
369 void refresh( const QString &path );
370
371 // Refresh item children
372 void refresh( const QModelIndex &index = QModelIndex() );
373
375 QModelIndex findPath( const QString &path );
376
377 void connectItem( QgsCptCityDataItem *item );
378
379 bool canFetchMore( const QModelIndex &parent ) const override;
380 void fetchMore( const QModelIndex &parent ) override;
381
382 signals:
383
384 public slots:
385 //void removeItems( QgsCptCityDataItem * parent, QVector<QgsCptCityDataItem *>items );
386 //void addItems( QgsCptCityDataItem * parent, QVector<QgsCptCityDataItem *>items );
387 //void refreshItems( QgsCptCityDataItem * parent, QVector<QgsCptCityDataItem *>items );
388
389 void beginInsertItems( QgsCptCityDataItem *parent, int first, int last );
390 void endInsertItems();
391 void beginRemoveItems( QgsCptCityDataItem *parent, int first, int last );
392 void endRemoveItems();
393
394 protected:
395
396 // populates the model
397 void addRootItems();
398 void removeRootItems();
399
400 QVector<QgsCptCityDataItem *> mRootItems;
401 QgsCptCityArchive *mArchive = nullptr;
404};
405
406// clazy:excludeall=qstring-allocations
407
408#endif
An "All ramps item", which contains all items in a flat hierarchy.
QVector< QgsCptCityDataItem * > mItems
QVector< QgsCptCityDataItem * > rootItems() const
QString archiveName() const
static QgsCptCityArchive * defaultArchive()
QgsCptCityArchive & operator=(const QgsCptCityArchive &rh)=delete
QgsCptCityArchive cannot be copied.
void setBaseDir(const QString &dirName)
QVector< QgsCptCityDataItem * > selectionItems() const
QgsCptCityArchive(const QgsCptCityArchive &rh)=delete
QgsCptCityArchive cannot be copied.
QVector< QgsCptCityDataItem * > mRootItems
A Collection: logical collection of subcollections and color ramps.
void addChild(QgsCptCityDataItem *item)
Item that represents a layer that can be opened with one of the providers.
const QgsCptCityColorRamp & ramp() const
int leafCount() const override
QgsCptCityColorRamp mRamp
Base class for all items in the model.
QgsCptCityDataItem * parent() const
virtual QWidget * paramWidget()
QString toolTip() const
void setToolTip(const QString &msg)
void beginRemoveItems(QgsCptCityDataItem *parent, int first, int last)
QString shortInfo() const
QString info() const
virtual bool acceptDrop()
QVector< QgsCptCityDataItem * > mChildren
void setParent(QgsCptCityDataItem *parent)
QString name() const
virtual QIcon icon(QSize size)
QString path() const
void setIcon(const QIcon &icon)
virtual QIcon icon()
QVector< QgsCptCityDataItem * > children() const
void beginInsertItems(QgsCptCityDataItem *parent, int first, int last)
virtual bool handleDrop(const QMimeData *, Qt::DropAction)
A directory: contains subdirectories and color ramps.
QMap< QString, QStringList > mRampsMap
A selection: contains subdirectories and color ramps.
QStringList selectionsList() const
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_TRANSFERBACK
Definition: qgis_sip.h:48
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define DEFAULT_CPTCITY_ARCHIVE