18 #include <QApplication> 23 #include <QMouseEvent> 24 #include <QTreeWidget> 25 #include <QTreeWidgetItem> 35 #include "qgsconfig.h" 49 QgsDebugMsg(
"archiveName = " + archiveName +
" baseDir = " + baseDir );
53 Q_FOREACH (
const QString& path,
QDir(
mBaseDir ).entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name ) )
55 if ( path ==
"selections" )
73 seldir.
dirName() +
'/' + selfile );
75 if ( selItem->isValid() )
114 if ( archiveName.
isNull() )
128 baseDir = settings.
value(
"CptCity/baseDir",
141 if ( startDir ==
"" || ! startDir.
startsWith( baseDir ) )
151 if ( ! dir.
exists( target ) )
154 return dir.
path() +
'/' + target;
177 if ( QgsCptCityArchive::mCopyingInfoMap.contains( fileName ) )
179 QgsDebugMsg(
"found copying info in copyingInfoMap, file = " + fileName );
180 return QgsCptCityArchive::mCopyingInfoMap.
value( fileName );
187 if ( !f.
open( QFile::ReadOnly ) )
189 QgsDebugMsg(
"Couldn't open xml file: " + fileName );
198 QgsDebugMsg(
"Couldn't parse xml file: " + fileName );
205 if ( docElem.
tagName() !=
"copying" )
213 if ( authorsElement.
isNull() )
231 copyingMap[
"authors" ] = authors.
join(
", " );
236 if ( licenseElement.
isNull() )
250 copyingMap[
"license/url" ] = e.
attribute(
"href" );
263 copyingMap[
"src/link" ] = e.
attribute(
"href" );
267 QgsCptCityArchive::mCopyingInfoMap[ fileName ] = copyingMap;
275 QgsDebugMsg(
"description fileName = " + fileName );
278 if ( ! f.
open( QFile::ReadOnly ) )
280 QgsDebugMsg(
"description file " + fileName +
" ] does not exist" );
290 QgsDebugMsg(
"Couldn't parse file " + fileName +
" : " + errMsg );
297 if ( docElem.
tagName() !=
"description" )
326 if ( !f.
open( QFile::ReadOnly ) )
328 QgsDebugMsg(
"Couldn't open SVG file: " + fileName );
337 QgsDebugMsg(
"Couldn't parse SVG file: " + fileName );
344 if ( docElem.
tagName() !=
"svg" )
352 if ( rampsElement.
isNull() )
358 if ( rampsElement.
isNull() )
377 offset = offsetStr.
remove( offsetStr.
size() - 1, 1 ).toDouble() / 100.0;
385 int alpha = opacityStr.
toDouble() * 255;
388 colorMap[offset].second = color;
390 colorMap[offset] = qMakePair( color, color );
426 QgsDebugMsg(
"archiveName = " + archiveName +
" archiveBaseDir = " + archiveBaseDir );
443 initArchive( defArchiveName, baseDir +
'/' + defArchiveName );
453 baseDir = settings.
value(
"CptCity/baseDir",
458 QgsDebugMsg(
"baseDir= " + baseDir +
" defArchiveName= " + defArchiveName );
464 if (
QFile::exists( baseDir +
'/' + entry +
"/VERSION.xml" ) )
465 archivesMap[ entry ] = baseDir +
'/' + entry;
470 archivesMap[ defArchiveName ] = baseDir +
'/' + defArchiveName;
474 it != archivesMap.
end(); ++it )
476 if (
QDir( it.value() ).exists() )
480 QgsDebugMsg(
QString(
"not loading archive [%1] because dir %2 does not exist " ).arg( it.key(), it.value() ) );
499 , mType( type ), mParent( parent ), mPopulated( false )
500 , mName( name ), mPath( path ), mValid( true )
653 for (
int i = 0; i < items.
size(); i++ )
656 if ( items[i]->
equal( item ) )
674 if (
findItem( items, child ) >= 0 )
713 , mInitialised( false )
714 , mRamp( path, variantName, false )
772 mInfo +=
tr(
"continuous (multi)" );
829 blankPixmap.
fill( Qt::white );
830 icon =
QIcon( blankPixmap );
842 , mPopulatedRamps( false )
867 QgsDebugMsgLevel(
QString(
"child path= %1 coll= %2 ramp = %3" ).arg( childItem->
path() ).arg(
nullptr != collectionItem ).
arg(
nullptr != rampItem ), 2 );
868 if ( collectionItem && recursive )
878 rampItems << rampItem;
880 deleteItems << rampItem;
917 mPath +
'/' +
"DESC.xml";
956 children << childItem;
969 QString curName, prevName, curVariant, curSep, schemeName;
972 bool prevAdd, curAdd;
978 for (
int i = 0; i < schemeNamesAll.
count(); i++ )
981 schemeName = schemeNamesAll[i];
982 schemeName.
chop( 4 );
985 curName = schemeName;
991 (( prevName + listVariant.
last() +
'a' ) == curName ) )
994 curVariant = listVariant.
last() +
'a';
998 QRegExp rxVariant(
"^(.*[^\\d])(\\d{1,3})$" );
999 int pos = rxVariant.
indexIn( schemeName );
1002 curName = rxVariant.
cap( 1 );
1003 curVariant = rxVariant.
cap( 2 );
1007 curSep = curName.
right( 1 );
1008 if ( curSep ==
"-" || curSep ==
"_" )
1011 curVariant = curSep + curVariant;
1014 if ( prevName ==
"" )
1020 if ( curName ==
"" )
1021 curName =
"__empty__";
1023 if ( curName == prevName )
1026 if ( i == schemeNamesAll.
count() - 1 )
1028 listVariant << curVariant;
1032 if ( prevName !=
"" )
1037 if ( i == schemeNamesAll.
count() - 1 )
1050 schemeNames << prevName;
1053 else if ( listVariant.
count() <= 3 )
1056 for (
int j = 0; j < listVariant.
count(); j++ )
1059 schemeNames << prevName + listVariant[j];
1067 schemeNames << prevName;
1069 listVariant.
clear();
1073 if ( curVariant !=
"" )
1074 curName += curVariant;
1075 schemeNames << curName;
1079 if ( prevAdd || curAdd )
1082 if ( curVariant !=
"" )
1083 listVariant << curVariant;
1090 mSchemeMap[
path ] = schemeNames;
1091 schemeCount += schemeName.
count();
1092 schemeNames.
clear();
1093 listVariant.
clear();
1102 '/' +
mPath ).
entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name );
1112 return (
path() == other->
path() );
1118 QgsDebugMsg(
"name= " + name +
" path= " + path );
1122 if ( dirItem && ! dirItem->
isValid() )
1137 if ( !theDirEntries.
isEmpty() )
1148 else if ( theRampsMap.
count() == 1 )
1153 theRampsMap.
begin().key(), theRampsMap.
begin().value() );
1196 childPath.
chop( 1 );
1202 children << childItem;
1211 if ( item->isValid() )
1229 QFile f( filename );
1230 if ( ! f.
open( QFile::ReadOnly ) )
1242 QgsDebugMsg(
"Couldn't parse file " + filename +
" : " + errMsg );
1249 if ( docElem.
tagName() !=
"selection" )
1293 return (
path() == other->
path() );
1334 , mArchive( archive )
1335 , mViewType( viewType )
1338 QgsDebugMsg(
"archiveName = " + archive->
archiveName() +
" viewType=" +
static_cast< int >( viewType ) );
1394 else if ( role == Qt::DisplayRole )
1396 if ( index.
column() == 0 )
1397 return item->
name();
1398 if ( index.
column() == 1 )
1400 return item->
info();
1403 else if ( role == Qt::ToolTipRole )
1407 return item->
path() +
'\n' + item->
info();
1410 else if ( role == Qt::DecorationRole && index.
column() == 1 &&
1416 else if ( role == Qt::FontRole &&
1417 dynamic_cast< QgsCptCityCollectionItem* >( item ) )
1435 Q_UNUSED( section );
1436 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
1440 else if ( section == 1 )
1459 return item ? item->
rowCount() : 0;
1482 bool foundParent =
false, foundChild =
true;
1490 for (
int i = 0; i <
rowCount( theIndex ); i++ )
1497 itemPath = item->
path();
1499 if ( itemPath == path )
1507 while ( foundChild )
1515 for ( ; i <
rowCount( theIndex ); i++ )
1522 itemPath = item->
path();
1524 if ( itemPath == path )
1533 foundParent =
false;
1546 childPath.
chop( 1 );
1619 for (
int i = 0; i < items.
size(); i++ )
1621 if ( items[i] == item )
1647 if ( !idx.isValid() )
1661 if ( !idx.isValid() )
1716 types <<
"application/x-vnd.qgis.qgis.uri";
1728 if ( ptr->
type() != QgsCptCityDataItem::Layer )
continue;
1756 Q_ASSERT( !v || d );
const char * className() const
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
void connectItem(QgsCptCityDataItem *item)
QStringList selectionsList() const
QDomNodeList elementsByTagName(const QString &tagname) const
void beginInsertItems(QgsCptCityDataItem *parent, int first, int last)
QString descFileName(const QString &dirName) const
void fetchMore(const QModelIndex &parent) override
virtual QgsCptCityDataItem * removeChildItem(QgsCptCityDataItem *child)
void setPointSize(int pointSize)
QString cap(int nth) const
QVector< QgsCptCityDataItem * > mItems
An "All ramps item", which contains all items in a flat hierarchy.
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
Used by other components to obtain information about each item provided by the model.
void emitBeginRemoveItems(QgsCptCityDataItem *parent, int first, int last)
static QIcon colorRampPreviewIcon(QgsVectorColorRampV2 *ramp, QSize size)
QgsCptCityDataItem * dataItem(const QModelIndex &idx) const
Returns a list of mime that can describe model indexes.
~QgsCptCityCollectionItem()
bool contains(const Key &key) const
static QgsCptCityArchive * defaultArchive()
void beginRemoveItems(QgsCptCityDataItem *parent, int first, int last)
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const override
Provides the number of columns of data exposed by the model.
QVector< QgsCptCityDataItem * > children() const
QgsCptCityDirectoryItem(QgsCptCityDataItem *parent, const QString &name, const QString &path)
void append(const T &value)
void fill(const QColor &color)
static QMap< QString, QgsCptCityArchive *> mArchiveRegistry
QString attribute(const QString &name, const QString &defValue) const
const QgsCptCityColorRampV2 & ramp() const
int indexOf(const T &value, int from) const
static QString defaultBaseDir()
QgsCptCityAllRampsItem(QgsCptCityDataItem *parent, const QString &name, const QVector< QgsCptCityDataItem *> &items)
QMap< QString, QStringList > rampsMap()
virtual ~QgsCptCityDataItem()
void insert(int i, const T &value)
QString simplified() const
QDomElement nextSiblingElement(const QString &tagName) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the index of the item in the model specified by the given row, column and parent index...
Item that represents a layer that can be opened with one of the providers.
bool isDiscrete() const
Returns true if the gradient is using discrete interpolation, rather than smoothly interpolating betw...
QMap< QString, QStringList > mRampsMap
static QMimeData * encodeUriList(const UriList &layers)
QDomElement documentElement() const
QString join(const QString &separator) const
QString & remove(int position, int n)
QgsCptCitySelectionItem(QgsCptCityDataItem *parent, const QString &name, const QString &path)
QModelIndex findPath(const QString &path)
return index of a path
double toDouble(bool *ok) const
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
virtual void addChildItem(QgsCptCityDataItem *child, bool refresh=false)
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
QString tr(const char *sourceText, const char *disambiguation, int n)
QgsCptCityArchive(const QString &archiveName=DEFAULT_CPTCITY_ARCHIVE, const QString &baseDir=QString())
virtual QStringList mimeTypes() const
virtual QVector< QgsCptCityDataItem * > createChildren()
QgsCptCityArchive * mArchive
QgsCptCityDataItem(QgsCptCityDataItem::Type type, QgsCptCityDataItem *parent, const QString &name, const QString &path)
QDomElement toElement() const
void setBold(bool enable)
int indexIn(const QString &str, int offset, CaretMode caretMode) const
static void initArchives(bool loadAll=false)
QVector< QgsCptCityDataItem * > createChildren() override
virtual bool equal(const QgsCptCityDataItem *other) override
void emitBeginInsertItems(QgsCptCityDataItem *parent, int first, int last)
QVector< QgsCptCityDataItem *> selectionItems() const
QList< QSize > availableSizes(Mode mode, State state) const
virtual int count() const override
Returns number of defined colors, or -1 if undefined.
QString number(int n, int base)
int count(const T &value) const
void append(const T &value)
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Used to supply item data to views and delegates.
void setVariantName(const QString &variantName)
virtual bool handleDrop(const QMimeData *, Qt::DropAction)
virtual bool equal(const QgsCptCityDataItem *other)
#define QgsDebugMsgLevel(str, level)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
Provides the number of rows of data exposed by the model.
A directory: contains subdirectories and color ramps.
bool hasChildren(const QModelIndex &parent=QModelIndex()) const override
QgsCptCityCollectionItem(QgsCptCityDataItem *parent, const QString &name, const QString &path)
void beginRemoveRows(const QModelIndex &parent, int first, int last)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
void setOverrideCursor(const QCursor &cursor)
Base class for all items in the model.
QVector< QgsCptCityDataItem * > mSelectionItems
void restoreOverrideCursor()
void * internalPointer() const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
void beginRemoveItems(QgsCptCityDataItem *parent, int first, int last)
static QMap< QString, QString > copyingInfo(const QString &fileName)
QgsCptCityColorRampV2 mRamp
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
A Collection: logical collection of subcollections and color ramps.
static void initArchive(const QString &archiveName, const QString &archiveBaseDir)
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QVector< QgsCptCityDataItem * > mChildren
QString right(int n) const
static void initDefaultArchive()
QModelIndex createIndex(int row, int column, void *ptr) const
bool hasMultiStops() const
QString archiveName() const
static QString pkgDataPath()
Returns the common root path of all application data directories.
#define DEFAULT_CPTCITY_ARCHIVE
void emitEndInsertItems()
static void clearArchives()
void beginInsertRows(const QModelIndex &parent, int first, int last)
virtual void deleteChildItem(QgsCptCityDataItem *child)
QStringList mSelectionsList
static QMap< QString, QMap< QString, QString > > mCopyingInfoMap
~QgsCptCityBrowserModel()
~QgsCptCitySelectionItem()
const T & at(int i) const
QVariant value(const QString &key, const QVariant &defaultValue) const
void refresh(const QString &path)
virtual bool equal(const QgsCptCityDataItem *other) override
static QMap< QString, QString > description(const QString &fileName)
QVector< QgsCptCityDataItem * > createChildren() override
void setParent(QgsCptCityDataItem *parent)
QgsCptCityBrowserModel(QObject *parent=nullptr, QgsCptCityArchive *archive=QgsCptCityArchive::defaultArchive(), ViewType Type=Authors)
static QString mDefaultArchiveName
virtual bool equal(const QgsCptCityDataItem *other) override
QStringList entryList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
QDomElement firstChildElement(const QString &tagName) const
void prepend(const T &value)
void beginInsertItems(QgsCptCityDataItem *parent, int first, int last)
QVector< QgsCptCityDataItem * > mRootItems
~QgsCptCityAllRampsItem()
int count(const T &value) const
static int findItem(QVector< QgsCptCityDataItem *> items, QgsCptCityDataItem *item)
bool canFetchMore(const QModelIndex &parent) const override
QVector< QgsCptCityDataItem * > createChildren() override
Item that represents a layer that can be opened with one of the providers.
QString variantName() const
void emitEndRemoveItems()
QgsCptCityColorRampItem(QgsCptCityDataItem *parent, const QString &name, const QString &path, const QString &variantName=QString(), bool initialize=false)
static QColor parseColor(const QString &colorStr, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes...
static QMap< double, QPair< QColor, QColor > > gradientColorMap(const QString &fileName)
QVector< QgsCptCityDataItem *> rootItems() const
A selection: contains subdirectories and color ramps.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QgsCptCityDataItem * parent() const
QVector< QgsCptCityDataItem * > childrenRamps(bool recursive)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QModelIndex findItem(QgsCptCityDataItem *item, QgsCptCityDataItem *parent=nullptr) const
virtual int leafCount() const
int count(const Key &key) const
static QgsCptCityDataItem * dataItem(QgsCptCityDataItem *parent, const QString &name, const QString &path)
QVector< QgsCptCityDataItem *> mRootItems
static QString findFileName(const QString &target, const QString &startDir, const QString &baseDir)
QStringList variantList() const
QString copyingFileName(const QString &dirName) const
QStringList dirEntries() const
QDomNode at(int index) const
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
const T value(const Key &key) const
static QMap< QString, QgsCptCityArchive *> archiveRegistry()
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Provides views with information to show in their headers.
~QgsCptCityDirectoryItem()