18 #include <QApplication>
19 #include <QtConcurrentMap>
20 #include <QtConcurrentRun>
25 #include <QMouseEvent>
26 #include <QTreeWidget>
27 #include <QTreeWidgetItem>
40 #include "qgsconfig.h"
44 #include "cpl_string.h"
178 QIcon::Normal, QIcon::On );
213 , mCapabilities( NoCapabilities )
215 , mState( NotPopulated )
216 , mPopulated( false )
219 , mDeferredDelete( false )
220 , mFutureWatcher( 0 )
235 if ( mFutureWatcher && !mFutureWatcher->
isFinished() )
238 QgsDebugMsg(
"mFutureWatcher not finished (should not happen) -> waitForFinished()" );
239 mDeferredDelete =
true;
261 if ( mFutureWatcher && !mFutureWatcher->
isFinished() )
263 QgsDebugMsg(
"mFutureWatcher not finished -> schedule to delete later" );
264 mDeferredDelete =
true;
291 child->QObject::setParent( 0 );
300 return mPopulatingIcon->
icon();
368 if ( !mFutureWatcher )
403 QgsDebugMsg(
"Item was scheduled to be deleted later" );
461 if ( !mFutureWatcher )
480 if (
findItem( children, child ) >= 0 )
606 for (
int i = 0; i < items.
size(); i++ )
608 Q_ASSERT_X( items[i],
"findItem",
QString(
"item %1 is NULL" ).arg( i ).toAscii() );
610 if ( items[i]->
equal( item ) )
645 if ( !mPopulatingIcon )
669 , mProviderKey( providerKey )
671 , mLayerType( layerType )
682 default:
mIconName =
"/mIconLayer.png";
break;
739 , mFileSystemWatcher( 0 )
740 , mRefreshLater( false )
748 , mDirPath( dirPath )
749 , mFileSystemWatcher( 0 )
750 , mRefreshLater( false )
778 QStringList entries = dir.
entryList( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
779 foreach (
QString subdir, entries )
796 QStringList fileEntries = dir.
entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files, QDir::Name );
848 if ( !mFileSystemWatcher )
857 if ( mFileSystemWatcher )
859 delete mFileSystemWatcher;
860 mFileSystemWatcher = 0;
871 mRefreshLater =
true;
885 QgsDebugMsg(
"directory changed during createChidren() -> refresh() again" );
886 mRefreshLater =
false;
919 labels <<
tr(
"Name" ) <<
tr(
"Size" ) <<
tr(
"Date" ) <<
tr(
"Permissions" ) <<
tr(
"Owner" ) <<
tr(
"Group" ) <<
tr(
"Type" );
931 QStringList entries = dir.
entryList( QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
938 if ( fi.size() > 1024 )
940 size = size.
sprintf(
"%.1f KiB", fi.size() / 1024.0 );
942 else if ( fi.size() > 1.048576e6 )
944 size = size.
sprintf(
"%.1f MiB", fi.size() / 1.048576e6 );
951 texts << fi.lastModified().toString( Qt::SystemLocaleShortDate );
953 perm += fi.permission( QFile::ReadOwner ) ?
'r' :
'-';
954 perm += fi.permission( QFile::WriteOwner ) ?
'w' :
'-';
955 perm += fi.permission( QFile::ExeOwner ) ?
'x' :
'-';
957 perm += fi.permission( QFile::ReadGroup ) ?
'r' :
'-';
958 perm += fi.permission( QFile::WriteGroup ) ?
'w' :
'-';
959 perm += fi.permission( QFile::ExeGroup ) ?
'x' :
'-';
960 perm += fi.permission( QFile::ReadOther ) ?
'r' :
'-';
961 perm += fi.permission( QFile::WriteOther ) ?
'w' :
'-';
962 perm += fi.permission( QFile::ExeOther ) ?
'x' :
'-';
970 if ( fi.isDir() && fi.isSymLink() )
972 type =
tr(
"folder" );
975 else if ( fi.isDir() )
977 type =
tr(
"folder" );
978 icon = iconDirectory;
980 else if ( fi.isFile() && fi.isSymLink() )
985 else if ( fi.isFile() )
1003 foreach (
QVariant colVariant, lst )
1011 if ( event->
button() == Qt::RightButton )
1017 labels <<
tr(
"Name" ) <<
tr(
"Size" ) <<
tr(
"Date" ) <<
tr(
"Permissions" ) <<
tr(
"Owner" ) <<
tr(
"Group" ) <<
tr(
"Type" );
1018 for (
int i = 0; i < labels.
count(); i++ )
1036 int columnIndex = action->
objectName().toInt();
1047 settings.
setValue(
"/dataitem/directoryHiddenColumns", lst );
1084 foreach (
QString favDir, favDirs )
1101 favDirs.
append( favDir );
1102 settings.
setValue(
"/browser/favourites", favDirs );
1119 settings.
setValue(
"/browser/favourites", favDirs );
1146 , mFilePath( filePath )
1151 void QgsZipItem::init()
1163 keys <<
"gdal" <<
"ogr";
1166 for ( i = keys.
begin(); i != keys.
end(); ++i )
1176 if ( !dataCapabilities )
1219 char **papszOFiles = NULL;
1220 char **papszFiles1 = NULL;
1221 char **papszFiles2 = NULL;
1222 VSIStatBufL psStatBuf;
1223 CPLString osTemp1, osTemp2;
1225 int nCount1, nCount2;
1228 papszFiles1 = VSIReadDir( pszPath );
1229 if ( ! papszFiles1 )
1233 nCount1 = CSLCount( papszFiles1 );
1234 for ( i = 0; i < nCount1; i++ )
1238 osTemp1.append( pszPath );
1239 osTemp1.append(
"/" );
1240 osTemp1.append( papszFiles1[i] );
1243 if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
1244 VSI_ISREG( psStatBuf.st_mode ) )
1247 papszOFiles = CSLAddString( papszOFiles, papszFiles1[i] );
1249 else if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
1250 VSI_ISDIR( psStatBuf.st_mode ) )
1254 osTemp2.append( papszFiles1[i] );
1255 osTemp2.append(
"/" );
1257 papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() );
1263 nCount2 = CSLCount( papszFiles2 );
1264 for ( j = 0; j < nCount2; j++ )
1267 osTemp2.append( papszFiles1[i] );
1268 osTemp2.append(
"/" );
1269 osTemp2.append( papszFiles2[j] );
1271 papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() );
1273 CSLDestroy( papszFiles2 );
1277 CSLDestroy( papszFiles1 );
1295 if ( scanZipSetting ==
"no" )
1362 int zipFileCount = 0;
1367 bool populated =
false;
1369 QgsDebugMsgLevel(
QString(
"path = %1 name= %2 scanZipSetting= %3 vsiPrefix= %4" ).arg( path ).arg( name ).arg( scanZipSetting ).arg( vsiPrefix ), 3 );
1372 if ( scanZipSetting ==
"no" )
1376 if (( vsiPrefix !=
"/vsizip/" && vsiPrefix !=
"/vsitar/" ) )
1379 zipItem =
new QgsZipItem( parent, name, filePath, path );
1389 if ( path.
endsWith(
".zip", Qt::CaseInsensitive ) ||
1390 path.
endsWith(
".tar", Qt::CaseInsensitive ) )
1395 if ( zipFileList.
count() > 0 && zipFileList.
count() <= 10 )
1408 if ( zipItem && ( !populated || zipItem->
rowCount() > 1 ) )
1416 QString vsiPath = vsiPrefix + filePath;
1424 vsiPath = layerItem->
uri();
1426 zipFileCount = zipFileList.
count();
1430 QgsDebugMsgLevel(
QString(
"will try to create a normal dataItem from filePath= %2 or vsiPath = %3" ).arg( filePath ).arg( vsiPath ), 3 );
1444 item = dataItem( filePath, parent );
1447 item = dataItem( vsiPath, parent );
1469 if ( scanZipSetting ==
"no" )
1477 if ( papszSiblingFiles )
1479 for (
int i = 0; i < CSLCount( papszSiblingFiles ); i++ )
1481 tmpPath = papszSiblingFiles[i];
1484 if ( tmpPath.
right( 1 ) !=
"/" )
1487 CSLDestroy( papszSiblingFiles );
QString completeSuffix() const
const char * className() const
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
A Collection: logical collection of layers or subcollections, e.g.
void beginInsertItems(QgsDataItem *parent, int first, int last)
void removeDirectory(QgsDirectoryItem *item)
virtual void childrenCreated()
static QgsDataItemProviderRegistry * instance()
virtual void childrenCreated() override
void dataChanged(QgsDataItem *item)
static void deleteLater(QVector< QgsDataItem * > &items)
bool contains(const Key &key) const
QgsFavouritesItem(QgsDataItem *parent, QString name, QString path=QString())
static QMap< QString, QIcon > mIconMap
int localeAwareCompare(const QString &other) const
QVector< QgsDataItem * > children() const
QPixmap currentPixmap() const
void append(const T &value)
virtual Capabilities capabilities2() const
static const QIcon & iconDefault()
void disconnectFrameChanged(const QObject *receiver, const char *method)
Disconnect listener from frameChanged() signal.
virtual QgsDataItem * createDataItem(const QString &path, QgsDataItem *parentItem)=0
Create a new instance of QgsDataItem (or null) for given path and parent item.
QgsDataItem * parent() const
Get item parent.
static const QIcon & iconPoint()
static QgsDataItem * itemFromPath(QgsDataItem *parent, QString path, QString name)
static QgsProviderRegistry * instance(QString pluginPath=QString::null)
means of accessing canonical single instance
static QString iconPath(QString iconFile)
Returns path to the desired icon file.
void addPath(const QString &path)
int indexOf(const T &value, int from) const
void addDirectory(QString favIcon)
QgsDataItem(QgsDataItem::Type type, QgsDataItem *parent, QString name, QString path)
Create new data item.
QList< QVariant > toList() const
void moveToThread(QThread *targetThread)
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
static QString pathComponent(const QString &component)
Create path component replacing path separators.
static const QIcon & iconFavourites()
void insert(int i, const T &value)
virtual void setState(State state) override
Set item state.
QgsLayerItem(QgsDataItem *parent, QString name, QString path, QString uri, LayerType layerType, QString providerKey)
virtual void populate(QVector< QgsDataItem * > children)
virtual void depopulate()
Remove children recursively and set as not populated.
static const QIcon & iconPolygon()
QgsErrorItem(QgsDataItem *parent, QString error, QString path)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString iconPath(QString iconFile)
bool isColumnHidden(int column) const
char ** VSIReadDirRecursive1(const char *pszPath)
A zip file: contains layers, using GDAL/OGR VSIFILE mechanism.
virtual bool equal(const QgsDataItem *other)
void setValue(const QString &key, const QVariant &value)
static const QIcon & iconDataCollection()
QgsDirectoryItem(QgsDataItem *parent, QString name, QString path)
const char * name() const
void setPaused(bool paused)
void setFileName(const QString &fileName)
QString number(int n, int base)
int count(const T &value) const
void append(const T &value)
const QPoint & globalPos() const
int toInt(bool *ok) const
void beginRemoveItems(QgsDataItem *parent, int first, int last)
static const QIcon & iconRaster()
void connectFrameChanged(const QObject *receiver, const char *method)
Connect listener to frameChanged() signal.
#define QgsDebugMsgLevel(str, level)
static QString vsiPrefix(QString uri)
LayerType
Layers enum defining the types of layers that can be added to a map.
static const QIcon & iconDir()
void setObjectName(const QString &name)
int removeAll(const T &value)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
Children not yet created.
Creating children in separate thread (populating or refreshing)
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
void addPixmap(const QPixmap &pixmap, Mode mode, State state)
QFuture< T > run(Function function,...)
QCoreApplication * instance()
virtual int capabilities()=0
Return combination of flags from QgsDataProvider::DataCapabilities.
static QStringList mProviderNames
void setFuture(const QFuture< T > &future)
virtual bool equal(const QgsDataItem *other) override
virtual QIcon icon() override
A directory: contains subdirectories and layers.
QString right(int n) const
Base class for all items in the model.
void setColumnHidden(int column, bool hide)
QgsDataCollectionItem(QgsDataItem *parent, QString name, QString path=QString::null)
void setCacheMode(CacheMode mode)
Capabilities mCapabilities
virtual void setState(State state)
Set item state.
virtual void addChildItem(QgsDataItem *child, bool refresh=false)
void setName(const QString &name)
static QVector< dataItem_t * > mDataItemPtr
Can create children. Even items without this capability may have children, but cannot create them...
void emitBeginInsertItems(QgsDataItem *parent, int first, int last)
static const QIcon & iconTable()
QLibrary * providerLibrary(const QString &providerKey) const
QString & replace(int position, int n, QChar after)
static int findItem(QVector< QgsDataItem * > items, QgsDataItem *item)
void moveToThread(QThread *targetThread)
Move object and all its descendants to thread.
QVariant value(const QString &key, const QVariant &defaultValue) const
QgsAnimatedIcon(const QString &iconPath=QString::null)
Constructor.
virtual Q_DECL_DEPRECATED Capability capabilities()
QStringList toStringList() const
void * resolve(const char *symbol)
QVector< QgsDataItem * > createChildren() override
Create children.
QgsZipItem(QgsDataItem *parent, QString name, QString path)
QStringList entryList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
static Q_DECL_DEPRECATED QVector< QLibrary * > mLibraries
QString & sprintf(const char *cformat,...)
void setParent(QgsDataItem *parent)
Set item parent and connect / disconnect parent to / from item signals.
Animated icon is keeping an animation running if there are listeners connected to frameChanged...
int count(const T &value) const
QgsMapLayer::LayerType mapLayerType()
bool deferredDelete()
The item is scheduled to be deleted.
QString absoluteFilePath(const QString &fileName) const
static const QIcon & iconLine()
void emitEndInsertItems()
virtual QVector< QgsDataItem * > createChildren()
Create children.
QVector< QgsDataItem * > createChildren() override
Create children.
Item that represents a layer that can be opened with one of the providers.
int indexOf(const QRegExp &rx, int from) const
iterator insert(const Key &key, const T &value)
QgsDataItem * dataItem_t(QString, QgsDataItem *)
void(*)() cast_to_fptr(void *p)
virtual QgsDataItem * removeChildItem(QgsDataItem *child)
virtual void deleteChildItem(QgsDataItem *child)
QVector< QgsDataItem * > mChildren
void emitEndRemoveItems()
void emitBeginRemoveItems(QgsDataItem *parent, int first, int last)
void setRootIsDecorated(bool show)
virtual bool equal(const QgsDataItem *other) override
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *option, const QWidget *widget) const =0
static const QIcon & iconZip()
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void emitStateChanged(QgsDataItem *item, QgsDataItem::State oldState)
virtual void deleteLater()
Safely delete the item:
virtual QWidget * paramWidget() override
createChildren() is fast enough to be run in main thread when refreshing items, most root items (wms...
void setIconPath(const QString &iconPath)
QVector< QgsDataItem * > createChildren() override
Create children.
This is the interface for those who want to add custom data items to the browser tree.
void stateChanged(QgsDataItem *item, QgsDataItem::State oldState)
const QStringList & getZipFileList()
const T value(const Key &key) const
void frameChanged()
Emitted when icon changed.