QGIS API Documentation 3.39.0-Master (d85f3c2a281)
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
66 bool isEmpty();
67 QString archiveName() const { return mArchiveName; }
68 static void initArchives( bool loadAll = false );
69 static void initArchive( const QString &archiveName, const QString &archiveBaseDir );
70 static void initDefaultArchive();
71 static void clearArchives();
72 static QgsCptCityArchive *defaultArchive();
73 static QMap< QString, QgsCptCityArchive * > archiveRegistry();
74
75 // items
76 QVector< QgsCptCityDataItem * > rootItems() const { return mRootItems; }
77 QVector< QgsCptCityDataItem * > selectionItems() const { return mSelectionItems; }
78
79 private:
80
81 QString mArchiveName;
82 QString mBaseDir;
83 // root items, namely directories at root of archive
84 QVector< QgsCptCityDataItem * > mRootItems;
85 QVector<QgsCptCityDataItem *> mSelectionItems;
86
87 private:
88#ifdef SIP_RUN
90#endif
91
92};
93
98class CORE_EXPORT QgsCptCityDataItem : public QObject
99{
100 Q_OBJECT
101 public:
110
112 const QString &name, const QString &path );
113
114 bool hasChildren();
115
116 int rowCount();
117
121 virtual int leafCount() const;
122
123 //
124
125 virtual void refresh();
126
130 virtual QVector<QgsCptCityDataItem *> createChildren();
131
135 virtual void populate();
136
140 bool isPopulated() { return mPopulated; }
141
147 virtual void addChildItem( QgsCptCityDataItem *child SIP_TRANSFER, bool refresh = false );
148
152 virtual void deleteChildItem( QgsCptCityDataItem *child );
153
159 virtual QgsCptCityDataItem *removeChildItem( QgsCptCityDataItem *child ) SIP_TRANSFERBACK;
160
164 virtual bool equal( const QgsCptCityDataItem *other );
165
169 Q_DECL_DEPRECATED virtual QWidget *paramWidget() SIP_DEPRECATED { return nullptr; }
170
176 Q_DECL_DEPRECATED virtual bool acceptDrop() SIP_DEPRECATED { return false; }
177
183 Q_DECL_DEPRECATED virtual bool handleDrop( const QMimeData *data, Qt::DropAction action ) SIP_DEPRECATED { Q_UNUSED( data ); Q_UNUSED( action ); return false; }
184
185 // static methods
186
190 static int findItem( QVector<QgsCptCityDataItem *> items, QgsCptCityDataItem *item );
191
192 // members
193
194 Type type() const { return mType; }
195 QgsCptCityDataItem *parent() const { return mParent; }
196 void setParent( QgsCptCityDataItem *parent ) { mParent = parent; }
197 QVector<QgsCptCityDataItem *> children() const { return mChildren; }
198 virtual QIcon icon() { return mIcon; }
199 virtual QIcon icon( QSize size ) { Q_UNUSED( size ) return icon(); }
200 QString name() const { return mName; }
201 QString path() const { return mPath; }
202 QString info() const { return mInfo; }
203 QString shortInfo() const { return mShortInfo; }
204
205 void setIcon( const QIcon &icon ) { mIcon = icon; }
206
207 void setToolTip( const QString &msg ) { mToolTip = msg; }
208 QString toolTip() const { return mToolTip; }
209
210 bool isValid() { return mValid; }
211
212 protected:
213
215 QgsCptCityDataItem *mParent = nullptr;
216 QVector<QgsCptCityDataItem *> mChildren; // easier to have it always
218 QString mName;
219 QString mPath; // it is also used to identify item in tree
220 QString mInfo;
221 QString mShortInfo;
222 QString mToolTip;
223 QIcon mIcon;
224 bool mValid;
225
226 signals:
227
239 void beginInsertItems( QgsCptCityDataItem *parent, int first, int last );
240
249
261 void beginRemoveItems( QgsCptCityDataItem *parent, int first, int last );
262
271};
272
278{
279 Q_OBJECT
280 public:
282 const QString &name, const QString &path,
283 const QString &variantName = QString(),
284 bool initialize = false );
286 const QString &name, const QString &path,
287 const QStringList &variantList,
288 bool initialize = false );
289
290 // --- reimplemented from QgsCptCityDataItem ---
291
292 bool equal( const QgsCptCityDataItem *other ) override;
293 int leafCount() const override { return 1; }
294
295 // --- New virtual methods for layer item derived classes ---
296 const QgsCptCityColorRamp &ramp() const { return mRamp; }
297 QIcon icon() override;
298 QIcon icon( QSize size ) override;
299 void init();
300
301 protected:
302
305 QList< QIcon > mIcons;
306};
307
308
314{
315 Q_OBJECT
316 public:
318 const QString &name, const QString &path );
319 ~QgsCptCityCollectionItem() override;
320
321 void setPopulated() { mPopulated = true; }
322 void addChild( QgsCptCityDataItem *item SIP_TRANSFER ) { mChildren.append( item ); }
323 QVector<QgsCptCityDataItem *> childrenRamps( bool recursive );
324
325 protected:
327};
328
334{
335 Q_OBJECT
336 public:
338 const QString &name, const QString &path );
339
340 QVector<QgsCptCityDataItem *> createChildren() override;
341
342 bool equal( const QgsCptCityDataItem *other ) override;
343
344 static QgsCptCityDataItem *dataItem( QgsCptCityDataItem *parent,
345 const QString &name, const QString &path );
346
347 protected:
348 QMap< QString, QStringList > rampsMap();
349 QStringList dirEntries() const;
350 QMap< QString, QStringList > mRampsMap;
351};
352
359{
360 Q_OBJECT
361 public:
362 QgsCptCitySelectionItem( QgsCptCityDataItem *parent, const QString &name, const QString &path );
363
364 QVector<QgsCptCityDataItem *> createChildren() override;
365
366 bool equal( const QgsCptCityDataItem *other ) override;
367
368 QStringList selectionsList() const { return mSelectionsList; }
369
370 protected:
371 void parseXml();
372 QStringList mSelectionsList;
373};
374
380{
381 Q_OBJECT
382 public:
383 QgsCptCityAllRampsItem( QgsCptCityDataItem *parent, const QString &name,
384 const QVector<QgsCptCityDataItem *> &items );
385
386 QVector<QgsCptCityDataItem *> createChildren() override;
387
388 protected:
389 QVector<QgsCptCityDataItem *> mItems;
390};
391
397class CORE_EXPORT QgsCptCityBrowserModel : public QAbstractItemModel
398{
399 Q_OBJECT
400
401 public:
402
404 {
405 Authors = 0,
406 Selections = 1,
407 List = 2 // not used anymore
408 };
409
410 QgsCptCityBrowserModel( QObject *parent SIP_TRANSFERTHIS = nullptr,
412 ViewType Type = Authors );
413 ~QgsCptCityBrowserModel() override;
414
415 // implemented methods from QAbstractItemModel for read-only access
416 Qt::ItemFlags flags( const QModelIndex &index ) const override;
417 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
418 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
419 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
420 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
421 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
422
423 QModelIndex findItem( QgsCptCityDataItem *item, QgsCptCityDataItem *parent = nullptr ) const;
424
425 QModelIndex parent( const QModelIndex &index ) const override;
426
430 QgsCptCityDataItem *dataItem( const QModelIndex &idx ) const;
431
432 bool hasChildren( const QModelIndex &parent = QModelIndex() ) const override;
433
435 void reload();
436
438 void refresh( const QString &path );
439
441 void refresh( const QModelIndex &index = QModelIndex() );
442
444 QModelIndex findPath( const QString &path );
445
446 void connectItem( QgsCptCityDataItem *item );
447
448 bool canFetchMore( const QModelIndex &parent ) const override;
449 void fetchMore( const QModelIndex &parent ) override;
450
451 public slots:
452
453 void beginInsertItems( QgsCptCityDataItem *parent, int first, int last );
454 void endInsertItems();
455 void beginRemoveItems( QgsCptCityDataItem *parent, int first, int last );
456 void endRemoveItems();
457
458 protected:
459
460 // populates the model
461 void addRootItems();
462 void removeRootItems();
463
464 QVector<QgsCptCityDataItem *> mRootItems;
465 QgsCptCityArchive *mArchive = nullptr;
468};
469
470// clazy:excludeall=qstring-allocations
471
472#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