QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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
40class CORE_EXPORT QgsCptCityArchive
41{
42 public:
43 QgsCptCityArchive( const QString &archiveName = DEFAULT_CPTCITY_ARCHIVE,
44 const QString &baseDir = QString() );
46
47 QgsCptCityArchive( const QgsCptCityArchive &rh ) = delete;
49
50 // basic dir info
51 QString baseDir() const;
52 static QString baseDir( QString archiveName );
53 static QString defaultBaseDir();
54 void setBaseDir( const QString &dirName ) { mBaseDir = dirName; }
55
56 // collection + selection info
57 QString copyingFileName( const QString &dirName ) const;
58 QString descFileName( const QString &dirName ) const;
59 static QString findFileName( const QString &target, const QString &startDir, const QString &baseDir );
60 static QMap< QString, QString > copyingInfo( const QString &fileName );
61 static QMap< QString, QString > description( const QString &fileName );
63 static QMap< double, QPair<QColor, QColor> > gradientColorMap( const QString &fileName ) SIP_SKIP;
64
65 // archive management
67 bool isEmpty() const;
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:
111
113 const QString &name, const QString &path );
114
115 bool hasChildren();
116
117 int rowCount();
118
122 virtual int leafCount() const;
123
124 //
125
126 virtual void refresh();
127
131 virtual QVector<QgsCptCityDataItem *> createChildren();
132
136 virtual void populate();
137
141 bool isPopulated() { return mPopulated; }
142
148 virtual void addChildItem( QgsCptCityDataItem *child SIP_TRANSFER, bool refresh = false );
149
153 virtual void deleteChildItem( QgsCptCityDataItem *child );
154
160 virtual QgsCptCityDataItem *removeChildItem( QgsCptCityDataItem *child ) SIP_TRANSFERBACK;
161
165 virtual bool equal( const QgsCptCityDataItem *other );
166
170 Q_DECL_DEPRECATED virtual QWidget *paramWidget() SIP_DEPRECATED { return nullptr; }
171
177 Q_DECL_DEPRECATED virtual bool acceptDrop() SIP_DEPRECATED { return false; }
178
184 Q_DECL_DEPRECATED virtual bool handleDrop( const QMimeData *data, Qt::DropAction action ) SIP_DEPRECATED { Q_UNUSED( data ); Q_UNUSED( action ); return false; }
185
186 // static methods
187
191 static int findItem( QVector<QgsCptCityDataItem *> items, QgsCptCityDataItem *item );
192
193 // members
194
195 Type type() const { return mType; }
196 QgsCptCityDataItem *parent() const { return mParent; }
197 void setParent( QgsCptCityDataItem *parent ) { mParent = parent; }
198 QVector<QgsCptCityDataItem *> children() const { return mChildren; }
199 virtual QIcon icon() { return mIcon; }
200 virtual QIcon icon( QSize size ) { Q_UNUSED( size ) return icon(); }
201 QString name() const { return mName; }
202 QString path() const { return mPath; }
203 QString info() const { return mInfo; }
204 QString shortInfo() const { return mShortInfo; }
205
206 void setIcon( const QIcon &icon ) { mIcon = icon; }
207
208 void setToolTip( const QString &msg ) { mToolTip = msg; }
209 QString toolTip() const { return mToolTip; }
210
211 bool isValid() { return mValid; }
212
213 protected:
214
216 QgsCptCityDataItem *mParent = nullptr;
217 QVector<QgsCptCityDataItem *> mChildren; // easier to have it always
219 QString mName;
220 QString mPath; // it is also used to identify item in tree
221 QString mInfo;
222 QString mShortInfo;
223 QString mToolTip;
224 QIcon mIcon;
225 bool mValid;
226
227 signals:
228
240 void beginInsertItems( QgsCptCityDataItem *parent, int first, int last );
241
250
262 void beginRemoveItems( QgsCptCityDataItem *parent, int first, int last );
263
272};
273
279{
280 Q_OBJECT
281 public:
283 const QString &name, const QString &path,
284 const QString &variantName = QString(),
285 bool initialize = false );
287 const QString &name, const QString &path,
288 const QStringList &variantList,
289 bool initialize = false );
290
291 // --- reimplemented from QgsCptCityDataItem ---
292
293 bool equal( const QgsCptCityDataItem *other ) override;
294 int leafCount() const override { return 1; }
295
296 // --- New virtual methods for layer item derived classes ---
297 const QgsCptCityColorRamp &ramp() const { return mRamp; }
298 QIcon icon() override;
299 QIcon icon( QSize size ) override;
300 void init();
301
302 protected:
303
306 QList< QIcon > mIcons;
307};
308
309
315{
316 Q_OBJECT
317 public:
319 const QString &name, const QString &path );
320 ~QgsCptCityCollectionItem() override;
321
322 void setPopulated() { mPopulated = true; }
323 void addChild( QgsCptCityDataItem *item SIP_TRANSFER ) { mChildren.append( item ); }
324 QVector<QgsCptCityDataItem *> childrenRamps( bool recursive );
325
326 protected:
328};
329
335{
336 Q_OBJECT
337 public:
339 const QString &name, const QString &path );
340
341 QVector<QgsCptCityDataItem *> createChildren() override;
342
343 bool equal( const QgsCptCityDataItem *other ) override;
344
345 static QgsCptCityDataItem *dataItem( QgsCptCityDataItem *parent,
346 const QString &name, const QString &path );
347
348 protected:
349 QMap< QString, QStringList > rampsMap();
350 QStringList dirEntries() const;
351 QMap< QString, QStringList > mRampsMap;
352};
353
360{
361 Q_OBJECT
362 public:
363 QgsCptCitySelectionItem( QgsCptCityDataItem *parent, const QString &name, const QString &path );
364
365 QVector<QgsCptCityDataItem *> createChildren() override;
366
367 bool equal( const QgsCptCityDataItem *other ) override;
368
369 QStringList selectionsList() const { return mSelectionsList; }
370
371 protected:
372 void parseXml();
373 QStringList mSelectionsList;
374};
375
381{
382 Q_OBJECT
383 public:
384 QgsCptCityAllRampsItem( QgsCptCityDataItem *parent, const QString &name,
385 const QVector<QgsCptCityDataItem *> &items );
386
387 QVector<QgsCptCityDataItem *> createChildren() override;
388
389 protected:
390 QVector<QgsCptCityDataItem *> mItems;
391};
392
398class CORE_EXPORT QgsCptCityBrowserModel : public QAbstractItemModel
399{
400 Q_OBJECT
401
402 public:
403
405 {
406 Authors = 0,
407 Selections = 1,
408 List = 2 // not used anymore
409 };
410
411 QgsCptCityBrowserModel( QObject *parent SIP_TRANSFERTHIS = nullptr,
413 ViewType Type = Authors );
414 ~QgsCptCityBrowserModel() override;
415
416 // implemented methods from QAbstractItemModel for read-only access
417 Qt::ItemFlags flags( const QModelIndex &index ) const override;
418 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
419 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
420 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
421 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
422 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
423
424 QModelIndex findItem( QgsCptCityDataItem *item, QgsCptCityDataItem *parent = nullptr ) const;
425
426 QModelIndex parent( const QModelIndex &index ) const override;
427
431 QgsCptCityDataItem *dataItem( const QModelIndex &idx ) const;
432
433 bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
434
436 void reload();
437
439 void refresh( const QString &path );
440
442 void refresh( const QModelIndex &index = QModelIndex() );
443
445 QModelIndex findPath( const QString &path );
446
447 void connectItem( QgsCptCityDataItem *item );
448
449 bool canFetchMore( const QModelIndex &parent ) const override;
450 void fetchMore( const QModelIndex &parent ) override;
451
452 public slots:
453
454 void beginInsertItems( QgsCptCityDataItem *parent, int first, int last );
455 void endInsertItems();
456 void beginRemoveItems( QgsCptCityDataItem *parent, int first, int last );
457 void endRemoveItems();
458
459 protected:
460
461 // populates the model
462 void addRootItems();
463 void removeRootItems();
464
465 QVector<QgsCptCityDataItem *> mRootItems;
466 QgsCptCityArchive *mArchive = nullptr;
469};
470
471// clazy:excludeall=qstring-allocations
472
473#endif
An "All ramps item", which contains all items in a flat hierarchy.
QVector< QgsCptCityDataItem * > mItems
Represents a CPT City color scheme.
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
A custom item model for display of CPT City color palettes.
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
Returns the total count of "leaf" items (all children which are end nodes).
QgsCptCityColorRamp mRamp
A color ramp from the CPT City collection.
Base class for all items in the model.
QgsCptCityDataItem * parent() const
QString toolTip() const
void setToolTip(const QString &msg)
void beginRemoveItems(QgsCptCityDataItem *parent, int first, int last)
Emitted before child items are removed from this data item.
QString shortInfo() const
virtual Q_DECL_DEPRECATED bool acceptDrop()
Returns true if the item accepts drag & dropped layers - e.g.
virtual Q_DECL_DEPRECATED bool handleDrop(const QMimeData *data, Qt::DropAction action)
Tries to process the data dropped on this item.
void endRemoveItems()
Emitted after child items have been removed from this data item.
bool isPopulated()
Returns true if the item is already populated.
QVector< QgsCptCityDataItem * > mChildren
void endInsertItems()
Emitted after child items have been added to this data item.
void setParent(QgsCptCityDataItem *parent)
virtual Q_DECL_DEPRECATED QWidget * paramWidget()
virtual QIcon icon(QSize size)
void setIcon(const QIcon &icon)
QVector< QgsCptCityDataItem * > children() const
void beginInsertItems(QgsCptCityDataItem *parent, int first, int last)
Emitted before child items are added to this item.
A directory: contains subdirectories and color ramps.
QMap< QString, QStringList > mRampsMap
A selection: contains subdirectories and color ramps.
QStringList selectionsList() const
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#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 DEFAULT_CPTCITY_ARCHIVE