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;
243 delete mFutureWatcher;
263 if ( mFutureWatcher && !mFutureWatcher->
isFinished() )
265 QgsDebugMsg(
"mFutureWatcher not finished -> schedule to delete later" );
266 mDeferredDelete =
true;
293 child->QObject::setParent( 0 );
302 return mPopulatingIcon->
icon();
370 if ( !mFutureWatcher )
406 QgsDebugMsg(
"Item was scheduled to be deleted later" );
464 if ( !mFutureWatcher )
483 if (
findItem( children, child ) >= 0 )
609 for (
int i = 0; i < items.
size(); i++ )
611 Q_ASSERT_X( items[i],
"findItem",
QString(
"item %1 is NULL" ).arg( i ).toAscii() );
613 if ( items[i]->
equal( item ) )
648 if ( !mPopulatingIcon )
672 , mProviderKey( providerKey )
674 , mLayerType( layerType )
685 default:
mIconName =
"/mIconLayer.png";
break;
744 , mFileSystemWatcher( 0 )
745 , mRefreshLater( false )
753 , mDirPath( dirPath )
754 , mFileSystemWatcher( 0 )
755 , mRefreshLater( false )
782 QStringList entries = dir.
entryList( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
783 Q_FOREACH (
const QString& subdir, entries )
800 QStringList fileEntries = dir.
entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files, QDir::Name );
852 if ( !mFileSystemWatcher )
861 if ( mFileSystemWatcher )
863 delete mFileSystemWatcher;
864 mFileSystemWatcher = 0;
875 mRefreshLater =
true;
889 QgsDebugMsg(
"directory changed during createChidren() -> refresh() again" );
890 mRefreshLater =
false;
923 labels <<
tr(
"Name" ) <<
tr(
"Size" ) <<
tr(
"Date" ) <<
tr(
"Permissions" ) <<
tr(
"Owner" ) <<
tr(
"Group" ) <<
tr(
"Type" );
935 QStringList entries = dir.
entryList( QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
942 if ( fi.size() > 1024 )
944 size = size.
sprintf(
"%.1f KiB", fi.size() / 1024.0 );
946 else if ( fi.size() > 1.048576e6 )
948 size = size.
sprintf(
"%.1f MiB", fi.size() / 1.048576e6 );
955 texts << fi.lastModified().toString( Qt::SystemLocaleShortDate );
957 perm += fi.permission( QFile::ReadOwner ) ?
'r' :
'-';
958 perm += fi.permission( QFile::WriteOwner ) ?
'w' :
'-';
959 perm += fi.permission( QFile::ExeOwner ) ?
'x' :
'-';
961 perm += fi.permission( QFile::ReadGroup ) ?
'r' :
'-';
962 perm += fi.permission( QFile::WriteGroup ) ?
'w' :
'-';
963 perm += fi.permission( QFile::ExeGroup ) ?
'x' :
'-';
964 perm += fi.permission( QFile::ReadOther ) ?
'r' :
'-';
965 perm += fi.permission( QFile::WriteOther ) ?
'w' :
'-';
966 perm += fi.permission( QFile::ExeOther ) ?
'x' :
'-';
974 if ( fi.isDir() && fi.isSymLink() )
976 type =
tr(
"folder" );
979 else if ( fi.isDir() )
981 type =
tr(
"folder" );
982 icon = iconDirectory;
984 else if ( fi.isFile() && fi.isSymLink() )
989 else if ( fi.isFile() )
1007 Q_FOREACH (
const QVariant& colVariant, lst )
1015 if ( event->
button() == Qt::RightButton )
1021 labels <<
tr(
"Name" ) <<
tr(
"Size" ) <<
tr(
"Date" ) <<
tr(
"Permissions" ) <<
tr(
"Owner" ) <<
tr(
"Group" ) <<
tr(
"Type" );
1022 for (
int i = 0; i < labels.
count(); i++ )
1040 int columnIndex = action->
objectName().toInt();
1051 settings.
setValue(
"/dataitem/directoryHiddenColumns", lst );
1088 Q_FOREACH (
const QString& favDir, favDirs )
1105 favDirs.
append( favDir );
1106 settings.
setValue(
"/browser/favourites", favDirs );
1123 settings.
setValue(
"/browser/favourites", favDirs );
1150 , mFilePath( filePath )
1155 void QgsZipItem::init()
1167 keys <<
"gdal" <<
"ogr";
1170 for ( i = keys.
begin(); i != keys.
end(); ++i )
1180 if ( !dataCapabilities )
1223 char **papszOFiles = NULL;
1224 char **papszFiles1 = NULL;
1225 char **papszFiles2 = NULL;
1226 VSIStatBufL psStatBuf;
1227 CPLString osTemp1, osTemp2;
1229 int nCount1, nCount2;
1232 papszFiles1 = VSIReadDir( pszPath );
1233 if ( ! papszFiles1 )
1237 nCount1 = CSLCount( papszFiles1 );
1238 for ( i = 0; i < nCount1; i++ )
1242 osTemp1.append( pszPath );
1243 osTemp1.append(
"/" );
1244 osTemp1.append( papszFiles1[i] );
1247 if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
1248 VSI_ISREG( psStatBuf.st_mode ) )
1251 papszOFiles = CSLAddString( papszOFiles, papszFiles1[i] );
1253 else if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
1254 VSI_ISDIR( psStatBuf.st_mode ) )
1258 osTemp2.append( papszFiles1[i] );
1259 osTemp2.append(
"/" );
1261 papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() );
1267 nCount2 = CSLCount( papszFiles2 );
1268 for ( j = 0; j < nCount2; j++ )
1271 osTemp2.append( papszFiles1[i] );
1272 osTemp2.append(
"/" );
1273 osTemp2.append( papszFiles2[j] );
1275 papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() );
1277 CSLDestroy( papszFiles2 );
1281 CSLDestroy( papszFiles1 );
1299 if ( scanZipSetting ==
"no" )
1366 int zipFileCount = 0;
1371 bool populated =
false;
1373 QgsDebugMsgLevel(
QString(
"path = %1 name= %2 scanZipSetting= %3 vsiPrefix= %4" ).arg( path, name, scanZipSetting, vsiPrefix ), 3 );
1376 if ( scanZipSetting ==
"no" )
1380 if (( vsiPrefix !=
"/vsizip/" && vsiPrefix !=
"/vsitar/" ) )
1383 zipItem =
new QgsZipItem( parent, name, filePath, path );
1393 if ( path.
endsWith(
".zip", Qt::CaseInsensitive ) ||
1394 path.
endsWith(
".tar", Qt::CaseInsensitive ) )
1399 if ( zipFileList.
count() > 0 && zipFileList.
count() <= 10 )
1412 if ( zipItem && ( !populated || zipItem->
rowCount() > 1 ) )
1420 QString vsiPath = vsiPrefix + filePath;
1424 if ( children.
size() == 1 )
1429 vsiPath = layerItem->
uri();
1431 zipFileCount = zipFileList.
count();
1435 QgsDebugMsgLevel(
QString(
"will try to create a normal dataItem from filePath= %2 or vsiPath = %3" ).arg( filePath, vsiPath ), 3 );
1449 item = dataItem( filePath, parent );
1452 item = dataItem( vsiPath, parent );
1474 if ( scanZipSetting ==
"no" )
1482 if ( papszSiblingFiles )
1484 for (
int i = 0; i < CSLCount( papszSiblingFiles ); i++ )
1486 tmpPath = papszSiblingFiles[i];
1489 if ( tmpPath.
right( 1 ) !=
"/" )
1492 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)
static QgsProviderRegistry * instance(const QString &pluginPath=QString::null)
Means of accessing canonical single instance.
void removeDirectory(QgsDirectoryItem *item)
virtual void childrenCreated()
static QgsDataItemProviderRegistry * instance()
virtual void childrenCreated() override
QgsErrorItem(QgsDataItem *parent, const QString &error, const QString &path)
void dataChanged(QgsDataItem *item)
static void deleteLater(QVector< QgsDataItem * > &items)
bool contains(const Key &key) const
static QMap< QString, QIcon > mIconMap
int localeAwareCompare(const QString &other) const
QVector< QgsDataItem * > children() const
LayerType
Layers enum defining the types of layers that can be added to a map.
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)
QString mProviderKey
The provider key.
void addPath(const QString &path)
int indexOf(const T &value, int from) const
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()
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
#define Q_NOWARN_DEPRECATED_PUSH
void insert(int i, const T &value)
virtual void setState(State state) override
Set item state.
virtual void depopulate()
Remove children recursively and set as not populated.
static const QIcon & iconPolygon()
QString iconPath(const QString &iconFile)
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 uri()
Returns layer uri or empty string if layer cannot be created.
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()
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)
QgsZipItem(QgsDataItem *parent, const QString &name, const QString &path)
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.
QgsDataCollectionItem(QgsDataItem *parent, const QString &name, const QString &path=QString::null)
static QStringList mProviderNames
void setFuture(const QFuture< T > &future)
virtual bool equal(const QgsDataItem *other) override
QgsDataItem(QgsDataItem::Type type, QgsDataItem *parent, const QString &name, const QString &path)
Create new data item.
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)
void setCacheMode(CacheMode mode)
void addDirectory(const QString &favIcon)
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...
QgsFavouritesItem(QgsDataItem *parent, const QString &name, const QString &path=QString())
void emitBeginInsertItems(QgsDataItem *parent, int first, int last)
static const QIcon & iconTable()
QLibrary * providerLibrary(const QString &providerKey) const
#define Q_NOWARN_DEPRECATED_POP
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()
virtual void populate(const QVector< QgsDataItem * > &children)
QStringList toStringList() const
void * resolve(const char *symbol)
QVector< QgsDataItem * > createChildren() override
Create children.
QStringList entryList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
QgsDirectoryItem(QgsDataItem *parent, const QString &name, const QString &path)
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()
Returns QgsMapLayer::LayerType.
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)
static Q_DECL_DEPRECATED QVector< QLibrary * > mLibraries
virtual void deleteChildItem(QgsDataItem *child)
QVector< QgsDataItem * > mChildren
void emitEndRemoveItems()
QgsLayerItem(QgsDataItem *parent, const QString &name, const QString &path, const QString &uri, LayerType layerType, const QString &providerKey)
void emitBeginRemoveItems(QgsDataItem *parent, int first, int last)
void setRootIsDecorated(bool show)
LayerType mLayerType
The layer type.
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)
static QString vsiPrefix(const QString &uri)
const QStringList & getZipFileList()
const T value(const Key &key) const
void frameChanged()
Emitted when icon changed.