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( nullptr )
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(
nullptr );
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 )
616 for (
int i = 0; i < items.
size(); i++ )
618 Q_ASSERT_X( items[i],
"findItem",
QString(
"item %1 is nullptr" ).arg( i ).toAscii() );
620 if ( items[i]->
equal( item ) )
655 if ( !mPopulatingIcon )
679 , mProviderKey( providerKey )
681 , mLayerType( layerType )
765 , mFileSystemWatcher( nullptr )
766 , mRefreshLater( false )
775 , mFileSystemWatcher( nullptr )
776 , mRefreshLater( false )
803 QStringList entries = dir.
entryList( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
804 Q_FOREACH (
const QString& subdir, entries )
825 QStringList fileEntries = dir.
entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files, QDir::Name );
837 if ( fileInfo.
suffix() ==
"qgs" )
884 if ( !mFileSystemWatcher )
893 if ( mFileSystemWatcher )
895 delete mFileSystemWatcher;
896 mFileSystemWatcher =
nullptr;
907 mRefreshLater =
true;
920 int idx = hiddenItems.
indexOf( path );
930 QgsDebugMsg(
"directory changed during createChidren() -> refresh() again" );
931 mRefreshLater =
false;
964 labels <<
tr(
"Name" ) <<
tr(
"Size" ) <<
tr(
"Date" ) <<
tr(
"Permissions" ) <<
tr(
"Owner" ) <<
tr(
"Group" ) <<
tr(
"Type" );
976 QStringList entries = dir.
entryList( QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
983 if ( fi.size() > 1024 )
985 size = size.
sprintf(
"%.1f KiB", fi.size() / 1024.0 );
987 else if ( fi.size() > 1.048576e6 )
989 size = size.
sprintf(
"%.1f MiB", fi.size() / 1.048576e6 );
996 texts << fi.lastModified().toString( Qt::SystemLocaleShortDate );
998 perm += fi.permission( QFile::ReadOwner ) ?
'r' :
'-';
999 perm += fi.permission( QFile::WriteOwner ) ?
'w' :
'-';
1000 perm += fi.permission( QFile::ExeOwner ) ?
'x' :
'-';
1002 perm += fi.permission( QFile::ReadGroup ) ?
'r' :
'-';
1003 perm += fi.permission( QFile::WriteGroup ) ?
'w' :
'-';
1004 perm += fi.permission( QFile::ExeGroup ) ?
'x' :
'-';
1005 perm += fi.permission( QFile::ReadOther ) ?
'r' :
'-';
1006 perm += fi.permission( QFile::WriteOther ) ?
'w' :
'-';
1007 perm += fi.permission( QFile::ExeOther ) ?
'x' :
'-';
1010 texts << fi.owner();
1011 texts << fi.group();
1015 if ( fi.isDir() && fi.isSymLink() )
1017 type =
tr(
"folder" );
1020 else if ( fi.isDir() )
1022 type =
tr(
"folder" );
1023 icon = iconDirectory;
1025 else if ( fi.isFile() && fi.isSymLink() )
1027 type =
tr(
"file" );
1028 icon = iconFileLink;
1030 else if ( fi.isFile() )
1032 type =
tr(
"file" );
1048 Q_FOREACH (
const QVariant& colVariant, lst )
1056 if ( event->
button() == Qt::RightButton )
1062 labels <<
tr(
"Name" ) <<
tr(
"Size" ) <<
tr(
"Date" ) <<
tr(
"Permissions" ) <<
tr(
"Owner" ) <<
tr(
"Group" ) <<
tr(
"Type" );
1063 for (
int i = 0; i < labels.
count(); i++ )
1081 int columnIndex = action->
objectName().toInt();
1092 settings.
setValue(
"/dataitem/directoryHiddenColumns", lst );
1098 mIconName =
":/images/icons/qgis-icon-16x16.png";
1140 Q_FOREACH (
const QString& favDir, favDirs )
1152 favDirs.
append( favDir );
1153 settings.
setValue(
"/browser/favourites", favDirs );
1173 settings.
setValue(
"/browser/favourites", favDirs );
1234 void QgsZipItem::init()
1246 keys <<
"gdal" <<
"ogr";
1249 for ( i = keys.
begin(); i != keys.
end(); ++i )
1259 if ( !dataCapabilities )
1302 char **papszOFiles =
nullptr;
1303 char **papszFiles1 =
nullptr;
1304 char **papszFiles2 =
nullptr;
1305 VSIStatBufL psStatBuf;
1306 CPLString osTemp1, osTemp2;
1308 int nCount1, nCount2;
1311 papszFiles1 = VSIReadDir( pszPath );
1312 if ( ! papszFiles1 )
1316 nCount1 = CSLCount( papszFiles1 );
1317 for ( i = 0; i < nCount1; i++ )
1321 osTemp1.append( pszPath );
1322 osTemp1.append(
"/" );
1323 osTemp1.append( papszFiles1[i] );
1326 if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
1327 VSI_ISREG( psStatBuf.st_mode ) )
1330 papszOFiles = CSLAddString( papszOFiles, papszFiles1[i] );
1332 else if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
1333 VSI_ISDIR( psStatBuf.st_mode ) )
1337 osTemp2.append( papszFiles1[i] );
1338 osTemp2.append(
"/" );
1340 papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() );
1346 nCount2 = CSLCount( papszFiles2 );
1347 for ( j = 0; j < nCount2; j++ )
1350 osTemp2.append( papszFiles1[i] );
1351 osTemp2.append(
"/" );
1352 osTemp2.append( papszFiles2[j] );
1354 papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() );
1356 CSLDestroy( papszFiles2 );
1360 CSLDestroy( papszFiles1 );
1378 if ( scanZipSetting ==
"no" )
1445 int zipFileCount = 0;
1450 bool populated =
false;
1452 QgsDebugMsgLevel(
QString(
"path = %1 name= %2 scanZipSetting= %3 vsiPrefix= %4" ).arg( path, name, scanZipSetting, vsiPrefix ), 3 );
1455 if ( scanZipSetting ==
"no" )
1459 if (( vsiPrefix !=
"/vsizip/" && vsiPrefix !=
"/vsitar/" ) )
1462 zipItem =
new QgsZipItem( parent, name, filePath, path );
1472 if ( path.
endsWith(
".zip", Qt::CaseInsensitive ) ||
1473 path.
endsWith(
".tar", Qt::CaseInsensitive ) )
1478 if ( !zipFileList.
isEmpty() && zipFileList.
count() <= 10 )
1491 if ( zipItem && ( !populated || zipItem->
rowCount() > 1 ) )
1499 QString vsiPath = vsiPrefix + filePath;
1503 if ( children.
size() == 1 )
1508 vsiPath = layerItem->
uri();
1510 zipFileCount = zipFileList.
count();
1514 QgsDebugMsgLevel(
QString(
"will try to create a normal dataItem from filePath= %2 or vsiPath = %3" ).arg( filePath, vsiPath ), 3 );
1528 item = dataItem( filePath, parent );
1531 item = dataItem( vsiPath, parent );
1553 if ( scanZipSetting ==
"no" )
1561 if ( papszSiblingFiles )
1563 for (
int i = 0; i < CSLCount( papszSiblingFiles ); i++ )
1565 tmpPath = papszSiblingFiles[i];
1568 if ( tmpPath.
right( 1 ) !=
"/" )
1571 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
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)
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()
const T & at(int i) const
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)
Returns true if this item is equal to another item (by testing item type and path).
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)
LayerType
Layers enum defining the types of layers that can be added to a map.
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
Returns true if this item is equal to another item (by testing item type and path).
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)
Inserts a new child item.
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.
const T & at(int i) const
QVariant value(const QString &key, const QVariant &defaultValue) const
static bool hiddenPath(QString path)
Check if the given path is hidden from the browser model.
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...
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.
QgsProjectItem(QgsDataItem *parent, const QString &name, const QString &path)
A data item holding a reference to a QGIS project file.
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)
Removes a child item and returns it without deleting it.
static Q_DECL_DEPRECATED QVector< QLibrary * > mLibraries
virtual void deleteChildItem(QgsDataItem *child)
Removes and deletes a child item, emitting relevant signals to the model.
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)
Data item that can be used to represent QGIS projects.
void setRootIsDecorated(bool show)
LayerType mLayerType
The layer type.
virtual bool equal(const QgsDataItem *other) override
Returns true if this item is equal to another item (by testing item type and path).
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.