QGIS API Documentation 3.39.0-Master (3aed037ce22)
Loading...
Searching...
No Matches
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
46 QgsCptCityArchive( const QgsCptCityArchive &rh ) = delete;
48
49 // basic dir info
50 QString baseDir() const;
51 static QString baseDir( QString archiveName );
52 static QString defaultBaseDir();
53 void setBaseDir( const QString &dirName ) { mBaseDir = dirName; }
54
55 // collection + selection info
56 QString copyingFileName( const QString &dirName ) const;
57 QString descFileName( const QString &dirName ) const;
58 static QString findFileName( const QString &target, const QString &startDir, const QString &baseDir );
59 static QMap< QString, QString > copyingInfo( const QString &fileName );
60 static QMap< QString, QString > description( const QString &fileName );
62 static QMap< double, QPair<QColor, QColor> > gradientColorMap( const QString &fileName ) SIP_SKIP;
63
64 // archive management
65 bool isEmpty();
66 QString archiveName() const { return mArchiveName; }
67 static void initArchives( bool loadAll = false );
68 static void initArchive( const QString &archiveName, const QString &archiveBaseDir );
69 static void initDefaultArchive();
70 static void clearArchives();
71 static QgsCptCityArchive *defaultArchive();
72 static QMap< QString, QgsCptCityArchive * > archiveRegistry();
73
74 // items
75 QVector< QgsCptCityDataItem * > rootItems() const { return mRootItems; }
76 QVector< QgsCptCityDataItem * > selectionItems() const { return mSelectionItems; }
77
78 private:
79
80 QString mArchiveName;
81 QString mBaseDir;
82 // root items, namely directories at root of archive
83 QVector< QgsCptCityDataItem * > mRootItems;
84 QVector<QgsCptCityDataItem *> mSelectionItems;
85
86 private:
87#ifdef SIP_RUN
89#endif
90
91};
92
97class CORE_EXPORT QgsCptCityDataItem : public QObject
98{
99 Q_OBJECT
100 public:
109
111 const QString &name, const QString &path );
112
113 bool hasChildren();
114
115 int rowCount();
116 // retrieve total count of "leaf" items (all children which are end nodes)
117 virtual int leafCount() const;
118
119 //
120
121 virtual void refresh();
122
123 // Create vector of children
124 virtual QVector<QgsCptCityDataItem *> createChildren();
125
126 // Populate children using children vector created by createChildren()
127 virtual void populate();
128 bool isPopulated() { return mPopulated; }
129
130 // Insert new child using alphabetical order based on mName, emits necessary signal to model before and after, sets parent and connects signals
131 // refresh - refresh populated item, emit signals to model
132 virtual void addChildItem( QgsCptCityDataItem *child SIP_TRANSFER, bool refresh = false );
133
134 // remove and delete child item, signals to browser are emitted
135 virtual void deleteChildItem( QgsCptCityDataItem *child );
136
137 // remove child item but don't delete it, signals to browser are emitted
138 // returns pointer to the removed item or null if no such item was found
139 virtual QgsCptCityDataItem *removeChildItem( QgsCptCityDataItem *child ) SIP_TRANSFERBACK;
140
141 virtual bool equal( const QgsCptCityDataItem *other );
142
143 virtual QWidget *paramWidget() SIP_FACTORY { return nullptr; }
144
145 // whether accepts drag&drop'd layers - e.g. for import
146 virtual bool acceptDrop() { return false; }
147
148 // try to process the data dropped on this item
149 virtual bool handleDrop( const QMimeData * /*data*/, Qt::DropAction /*action*/ ) { return false; }
150
151 // static methods
152
153 // Find child index in vector of items using '==' operator
154 static int findItem( QVector<QgsCptCityDataItem *> items, QgsCptCityDataItem *item );
155
156 // members
157
158 Type type() const { return mType; }
159 QgsCptCityDataItem *parent() const { return mParent; }
160 void setParent( QgsCptCityDataItem *parent ) { mParent = parent; }
161 QVector<QgsCptCityDataItem *> children() const { return mChildren; }
162 virtual QIcon icon() { return mIcon; }
163 virtual QIcon icon( QSize size ) { Q_UNUSED( size ) return icon(); }
164 QString name() const { return mName; }
165 QString path() const { return mPath; }
166 QString info() const { return mInfo; }
167 QString shortInfo() const { return mShortInfo; }
168
169 void setIcon( const QIcon &icon ) { mIcon = icon; }
170
171 void setToolTip( const QString &msg ) { mToolTip = msg; }
172 QString toolTip() const { return mToolTip; }
173
174 bool isValid() { return mValid; }
175
176 protected:
177
179 QgsCptCityDataItem *mParent = nullptr;
180 QVector<QgsCptCityDataItem *> mChildren; // easier to have it always
182 QString mName;
183 QString mPath; // it is also used to identify item in tree
184 QString mInfo;
185 QString mShortInfo;
186 QString mToolTip;
187 QIcon mIcon;
188 bool mValid;
189
190 signals:
191 void beginInsertItems( QgsCptCityDataItem *parent, int first, int last );
193 void beginRemoveItems( QgsCptCityDataItem *parent, int first, int last );
195};
196
202{
203 Q_OBJECT
204 public:
206 const QString &name, const QString &path,
207 const QString &variantName = QString(),
208 bool initialize = false );
210 const QString &name, const QString &path,
211 const QStringList &variantList,
212 bool initialize = false );
213
214 // --- reimplemented from QgsCptCityDataItem ---
215
216 bool equal( const QgsCptCityDataItem *other ) override;
217 int leafCount() const override { return 1; }
218
219 // --- New virtual methods for layer item derived classes ---
220 const QgsCptCityColorRamp &ramp() const { return mRamp; }
221 QIcon icon() override;
222 QIcon icon( QSize size ) override;
223 void init();
224
225 protected:
226
229 QList< QIcon > mIcons;
230};
231
232
238{
239 Q_OBJECT
240 public:
242 const QString &name, const QString &path );
243 ~QgsCptCityCollectionItem() override;
244
245 void setPopulated() { mPopulated = true; }
246 void addChild( QgsCptCityDataItem *item SIP_TRANSFER ) { mChildren.append( item ); }
247 QVector<QgsCptCityDataItem *> childrenRamps( bool recursive );
248
249 protected:
251};
252
258{
259 Q_OBJECT
260 public:
262 const QString &name, const QString &path );
263
264 QVector<QgsCptCityDataItem *> createChildren() override;
265
266 bool equal( const QgsCptCityDataItem *other ) override;
267
268 static QgsCptCityDataItem *dataItem( QgsCptCityDataItem *parent,
269 const QString &name, const QString &path );
270
271 protected:
272 QMap< QString, QStringList > rampsMap();
273 QStringList dirEntries() const;
274 QMap< QString, QStringList > mRampsMap;
275};
276
283{
284 Q_OBJECT
285 public:
286 QgsCptCitySelectionItem( QgsCptCityDataItem *parent, const QString &name, const QString &path );
287
288 QVector<QgsCptCityDataItem *> createChildren() override;
289
290 bool equal( const QgsCptCityDataItem *other ) override;
291
292 QStringList selectionsList() const { return mSelectionsList; }
293
294 protected:
295 void parseXml();
296 QStringList mSelectionsList;
297};
298
304{
305 Q_OBJECT
306 public:
307 QgsCptCityAllRampsItem( QgsCptCityDataItem *parent, const QString &name,
308 const QVector<QgsCptCityDataItem *> &items );
309
310 QVector<QgsCptCityDataItem *> createChildren() override;
311
312 protected:
313 QVector<QgsCptCityDataItem *> mItems;
314};
315
320class CORE_EXPORT QgsCptCityBrowserModel : public QAbstractItemModel
321{
322 Q_OBJECT
323
324 public:
325
327 {
328 Authors = 0,
329 Selections = 1,
330 List = 2 // not used anymore
331 };
332
333 QgsCptCityBrowserModel( QObject *parent SIP_TRANSFERTHIS = nullptr,
335 ViewType Type = Authors );
336 ~QgsCptCityBrowserModel() override;
337
338 // implemented methods from QAbstractItemModel for read-only access
339 Qt::ItemFlags flags( const QModelIndex &index ) const override;
340 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
341 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
342 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
343 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
344 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
345
346 QModelIndex findItem( QgsCptCityDataItem *item, QgsCptCityDataItem *parent = nullptr ) const;
347
348 QModelIndex parent( const QModelIndex &index ) const override;
349
351 /* virtual QStringList mimeTypes() const; */
352
354 /* virtual QMimeData * mimeData( const QModelIndexList &indexes ) const; */
355
357 /* virtual bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ); */
358
359 QgsCptCityDataItem *dataItem( const QModelIndex &idx ) const;
360
361 bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
362
363 // Reload the whole model
364 void reload();
365
366 // Refresh item specified by path
367 void refresh( const QString &path );
368
369 // Refresh item children
370 void refresh( const QModelIndex &index = QModelIndex() );
371
373 QModelIndex findPath( const QString &path );
374
375 void connectItem( QgsCptCityDataItem *item );
376
377 bool canFetchMore( const QModelIndex &parent ) const override;
378 void fetchMore( const QModelIndex &parent ) override;
379
380 signals:
381
382 public slots:
383 //void removeItems( QgsCptCityDataItem * parent, QVector<QgsCptCityDataItem *>items );
384 //void addItems( QgsCptCityDataItem * parent, QVector<QgsCptCityDataItem *>items );
385 //void refreshItems( QgsCptCityDataItem * parent, QVector<QgsCptCityDataItem *>items );
386
387 void beginInsertItems( QgsCptCityDataItem *parent, int first, int last );
388 void endInsertItems();
389 void beginRemoveItems( QgsCptCityDataItem *parent, int first, int last );
390 void endRemoveItems();
391
392 protected:
393
394 // populates the model
395 void addRootItems();
396 void removeRootItems();
397
398 QVector<QgsCptCityDataItem *> mRootItems;
399 QgsCptCityArchive *mArchive = nullptr;
402};
403
404// clazy:excludeall=qstring-allocations
405
406#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
void setBaseDir(const QString &dirName)
QVector< QgsCptCityDataItem * > selectionItems() const
QgsCptCityArchive(const QgsCptCityArchive &rh)=delete
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
virtual bool acceptDrop()
QVector< QgsCptCityDataItem * > mChildren
void setParent(QgsCptCityDataItem *parent)
virtual QIcon icon(QSize size)
void setIcon(const 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