18 #include <QApplication>
23 #include <QMouseEvent>
24 #include <QTreeWidget>
25 #include <QTreeWidgetItem>
35 #include "qgsconfig.h"
46 : mArchiveName( archiveName )
49 QgsDebugMsg(
"archiveName = " + archiveName +
" baseDir = " + baseDir );
53 foreach (
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() ).arg( it.value() ) );
501 , mType( type ), mParent( parent ), mPopulated( false )
502 , mName( name ), mPath( path ), mValid( true )
655 for (
int i = 0; i < items.
size(); i++ )
658 if ( items[i]->
equal( item ) )
676 if (
findItem( items, child ) >= 0 )
715 , mInitialised( false )
716 , mRamp( path, variantName, false )
727 , mInitialised( false )
728 , mRamp( path, variantList,
QString(), false )
774 mInfo +=
tr(
"continuous (multi)" );
831 blankPixmap.
fill( Qt::white );
832 icon =
QIcon( blankPixmap );
844 , mPopulatedRamps( false )
871 if ( collectionItem && recursive )
881 rampItems << rampItem;
883 deleteItems << rampItem;
920 mPath +
"/" +
"DESC.xml";
959 children << childItem;
972 QString curName, prevName, prevPath, curVariant, curSep, schemeName;
975 bool prevAdd, curAdd;
981 for (
int i = 0; i < schemeNamesAll.
count(); i++ )
984 schemeName = schemeNamesAll[i];
985 schemeName.
chop( 4 );
988 curName = schemeName;
994 (( prevName + listVariant.
last() +
"a" ) == curName ) )
997 curVariant = listVariant.
last() +
"a";
1001 QRegExp rxVariant(
"^(.*[^\\d])(\\d{1,3})$" );
1002 int pos = rxVariant.
indexIn( schemeName );
1005 curName = rxVariant.
cap( 1 );
1006 curVariant = rxVariant.
cap( 2 );
1010 curSep = curName.
right( 1 );
1011 if ( curSep ==
"-" || curSep ==
"_" )
1014 curVariant = curSep + curVariant;
1017 if ( prevName ==
"" )
1023 if ( curName ==
"" )
1024 curName =
"__empty__";
1026 if ( curName == prevName )
1029 if ( i == schemeNamesAll.
count() - 1 )
1031 listVariant << curVariant;
1035 if ( prevName !=
"" )
1040 if ( i == schemeNamesAll.
count() - 1 )
1049 if ( listVariant.
count() == 0 )
1053 schemeNames << prevName;
1056 else if ( listVariant.
count() <= 3 )
1059 for (
int j = 0; j < listVariant.
count(); j++ )
1062 schemeNames << prevName + listVariant[j];
1070 schemeNames << prevName;
1072 listVariant.
clear();
1076 if ( curVariant !=
"" )
1077 curName += curVariant;
1078 schemeNames << curName;
1082 if ( prevAdd || curAdd )
1085 if ( curVariant !=
"" )
1086 listVariant << curVariant;
1103 "/" +
mPath ).
entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name );
1113 return (
path() == other->
path() );
1119 QgsDebugMsg(
"name= " + name +
" path= " + path );
1123 if ( dirItem && ! dirItem->
isValid() )
1138 if ( theDirEntries.
count() > 0 )
1142 if ( theRampsMap.
count() == 0 )
1149 else if ( theRampsMap.
count() == 1 )
1154 theRampsMap.
begin().key(), theRampsMap.
begin().value() );
1197 childPath.
chop( 1 );
1203 children << childItem;
1212 if ( item->isValid() )
1230 QFile f( filename );
1231 if ( ! f.
open( QFile::ReadOnly ) )
1243 QgsDebugMsg(
"Couldn't parse file " + filename +
" : " + errMsg );
1250 if ( docElem.
tagName() !=
"selection" )
1294 return (
path() == other->
path() );
1392 else if ( role == Qt::DisplayRole )
1394 if ( index.
column() == 0 )
1395 return item->
name();
1396 if ( index.
column() == 1 )
1398 return item->
info();
1401 else if ( role == Qt::ToolTipRole )
1405 return item->
path() +
"\n" + item->
info();
1408 else if ( role == Qt::DecorationRole && index.
column() == 1 &&
1414 else if ( role == Qt::FontRole &&
1415 ( dynamic_cast< QgsCptCityCollectionItem* >( item ) != 0 ) )
1433 Q_UNUSED( section );
1434 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
1438 else if ( section == 1 )
1457 return item ? item->
rowCount() : 0;
1480 bool foundParent =
false, foundChild =
true;
1488 for (
int i = 0; i <
rowCount( theIndex ); i++ )
1495 itemPath = item->
path();
1497 if ( itemPath == path )
1505 while ( foundChild )
1513 for ( ; i <
rowCount( theIndex ); i++ )
1520 itemPath = item->
path();
1522 if ( itemPath == path )
1531 foundParent =
false;
1544 childPath.
chop( 1 );
1617 for (
int i = 0; i < items.
size(); i++ )
1619 if ( items[i] == item )
1645 if ( !idx.isValid() )
1660 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)
static void initArchive(QString archiveName, QString archiveBaseDir)
QVector< QgsCptCityDataItem * > children() const
static const QString pkgDataPath()
Returns the common root path of all application data directories.
QDomNodeList elementsByTagName(const QString &tagname) const
void beginInsertItems(QgsCptCityDataItem *parent, int first, int last)
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)
~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.
int localeAwareCompare(const QString &other) const
void append(const T &value)
void fill(const QColor &color)
QString attribute(const QString &name, const QString &defValue) const
int indexOf(const T &value, int from) const
static QString defaultBaseDir()
QString archiveName() const
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...
QgsCptCityDataItem * parent() const
Item that represents a layer that can be opened with one of the providers.
QgsCptCityAllRampsItem(QgsCptCityDataItem *parent, QString name, QVector< QgsCptCityDataItem * > items)
QgsCptCityDataItem * dataItem(const QModelIndex &idx) const
Returns a list of mime that can describe model indexes.
QMap< QString, QStringList > mRampsMap
QDomElement documentElement() const
QgsCptCityDirectoryItem(QgsCptCityDataItem *parent, QString name, QString path)
QString join(const QString &separator) const
static QgsCptCityDataItem * dataItem(QgsCptCityDataItem *parent, QString name, QString path)
QString & remove(int position, int n)
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)
virtual QStringList mimeTypes() const
QgsCptCityArchive(QString archiveName=DEFAULT_CPTCITY_ARCHIVE, QString baseDir=QString())
bool hasMultiStops() const
virtual QVector< QgsCptCityDataItem * > createChildren()
QgsCptCityArchive * mArchive
QDomElement toElement() const
void setBold(bool enable)
QVector< QgsCptCityDataItem * > rootItems() const
int indexIn(const QString &str, int offset, CaretMode caretMode) const
void refresh(QString path)
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)
QList< QSize > availableSizes(Mode mode, State state) const
virtual int count() const override
Returns number of defined colors, or -1 if undefined.
static QMap< QString, QgsCptCityArchive * > mArchiveRegistry
QModelIndex findPath(QString path)
return index of a path
QString variantName() const
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.
QStringList variantList() const
QString copyingFileName(const QString &dirName) const
virtual bool handleDrop(const QMimeData *, Qt::DropAction)
QStringList selectionsList() const
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.
void setVariantName(QString variantName)
bool hasChildren(const QModelIndex &parent=QModelIndex()) const override
void beginRemoveRows(const QModelIndex &parent, int first, int last)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
void setOverrideCursor(const QCursor &cursor)
QStringList dirEntries() const
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.
QString descFileName(const QString &dirName) const
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QVector< QgsCptCityDataItem * > mChildren
QModelIndex findItem(QgsCptCityDataItem *item, QgsCptCityDataItem *parent=0) const
QString right(int n) const
static void initDefaultArchive()
QModelIndex createIndex(int row, int column, void *ptr) const
static QMimeData * encodeUriList(UriList layers)
#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()
QgsCptCityCollectionItem(QgsCptCityDataItem *parent, QString name, QString path)
~QgsCptCitySelectionItem()
QVariant value(const QString &key, const QVariant &defaultValue) const
virtual int leafCount() const
virtual bool equal(const QgsCptCityDataItem *other) override
static QMap< QString, QString > description(const QString &fileName)
QVector< QgsCptCityDataItem * > createChildren() override
void setParent(QgsCptCityDataItem *parent)
QgsCptCityColorRampItem(QgsCptCityDataItem *parent, QString name, QString path, QString variantName=QString(), bool initialize=false)
QgsCptCitySelectionItem(QgsCptCityDataItem *parent, QString name, QString path)
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
bool canFetchMore(const QModelIndex &parent) const override
static int findItem(QVector< QgsCptCityDataItem * > items, QgsCptCityDataItem *item)
QVector< QgsCptCityDataItem * > createChildren() override
Item that represents a layer that can be opened with one of the providers.
void emitEndRemoveItems()
QgsCptCityBrowserModel(QObject *parent=0, QgsCptCityArchive *archive=QgsCptCityArchive::defaultArchive(), ViewType Type=Authors)
static QMap< double, QPair< QColor, QColor > > gradientColorMap(const QString &fileName)
note not available in python bindings
QVector< QgsCptCityDataItem * > childrenRamps(bool recursive)
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(QgsCptCityDataItem::Type type, QgsCptCityDataItem *parent, QString name, QString path)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
static QMap< QString, QgsCptCityArchive * > archiveRegistry()
int count(const Key &key) const
QVector< QgsCptCityDataItem * > mRootItems
const QgsCptCityColorRampV2 & ramp() const
static QString findFileName(const QString &target, const QString &startDir, const QString &baseDir)
QVector< QgsCptCityDataItem * > selectionItems() const
static QColor parseColor(QString colorStr, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes...
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
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Provides views with information to show in their headers.
~QgsCptCityDirectoryItem()