18 #include <QApplication>    19 #include <QtConcurrentMap>    20 #include <QtConcurrentRun>    25 #include <QMouseEvent>    26 #include <QTreeWidget>    27 #include <QTreeWidgetItem>    40 #include "qgsconfig.h"    43 #define CPL_SUPRESS_CPLUSPLUS    45 #include "cpl_string.h"   179                     QIcon::Normal, QIcon::On );
   212     , mCapabilities( NoCapabilities )
   214     , mState( NotPopulated )
   215     , mPopulated( false )
   218     , mDeferredDelete( false )
   219     , mFutureWatcher( nullptr )
   234   if ( mFutureWatcher && !mFutureWatcher->
isFinished() )
   237     QgsDebugMsg( 
"mFutureWatcher not finished (should not happen) -> waitForFinished()" );
   238     mDeferredDelete = 
true;
   242   delete mFutureWatcher;
   262   if ( mFutureWatcher && !mFutureWatcher->
isFinished() )
   264     QgsDebugMsg( 
"mFutureWatcher not finished -> schedule to delete later" );
   265     mDeferredDelete = 
true;
   292     child->QObject::setParent( 
nullptr ); 
   301     return mPopulatingIcon->
icon();
   369     if ( !mFutureWatcher )
   405     QgsDebugMsg( 
"Item was scheduled to be deleted later" );
   463     if ( !mFutureWatcher )
   482     if ( 
findItem( children, child ) >= 0 )
   615   for ( 
int i = 0; i < items.
size(); i++ )
   617     Q_ASSERT_X( items[i], 
"findItem", 
QString( 
"item %1 is nullptr" ).arg( i ).toAscii() );
   619     if ( items[i]->
equal( item ) )
   654     if ( !mPopulatingIcon )
   680     , mProviderKey( providerKey )
   682     , mLayerType( layerType )
   766     , mFileSystemWatcher( nullptr )
   767     , mRefreshLater( false )
   776     , mFileSystemWatcher( nullptr )
   777     , mRefreshLater( false )
   804   QStringList entries = dir.
entryList( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
   805   Q_FOREACH ( 
const QString& subdir, entries )
   826   QStringList fileEntries = dir.
entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files, QDir::Name );
   838     if ( fileInfo.
suffix() == 
"qgs" )
   884     if ( !mFileSystemWatcher )
   893     if ( mFileSystemWatcher )
   895       delete mFileSystemWatcher;
   896       mFileSystemWatcher = 
nullptr;
   906     mRefreshLater = 
true;
   919   int idx = hiddenItems.
indexOf( path );
   929     QgsDebugMsgLevel( 
"directory changed during createChidren() -> refresh() again", 3 );
   930     mRefreshLater = 
false;
   963   labels << 
tr( 
"Name" ) << 
tr( 
"Size" ) << 
tr( 
"Date" ) << 
tr( 
"Permissions" ) << 
tr( 
"Owner" ) << 
tr( 
"Group" ) << 
tr( 
"Type" );
   975   QStringList entries = dir.
entryList( QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
   982     if ( fi.size() > 1024 )
   984       size = size.
sprintf( 
"%.1f KiB", fi.size() / 1024.0 );
   986     else if ( fi.size() > 1.048576e6 )
   988       size = size.
sprintf( 
"%.1f MiB", fi.size() / 1.048576e6 );
   995     texts << fi.lastModified().toString( Qt::SystemLocaleShortDate );
   997     perm += fi.permission( QFile::ReadOwner ) ? 
'r' : 
'-';
   998     perm += fi.permission( QFile::WriteOwner ) ? 
'w' : 
'-';
   999     perm += fi.permission( QFile::ExeOwner ) ? 
'x' : 
'-';
  1001     perm += fi.permission( QFile::ReadGroup ) ? 
'r' : 
'-';
  1002     perm += fi.permission( QFile::WriteGroup ) ? 
'w' : 
'-';
  1003     perm += fi.permission( QFile::ExeGroup ) ? 
'x' : 
'-';
  1004     perm += fi.permission( QFile::ReadOther ) ? 
'r' : 
'-';
  1005     perm += fi.permission( QFile::WriteOther ) ? 
'w' : 
'-';
  1006     perm += fi.permission( QFile::ExeOther ) ? 
'x' : 
'-';
  1009     texts << fi.owner();
  1010     texts << fi.group();
  1014     if ( fi.isDir() && fi.isSymLink() )
  1016       type = 
tr( 
"folder" );
  1019     else if ( fi.isDir() )
  1021       type = 
tr( 
"folder" );
  1022       icon = iconDirectory;
  1024     else if ( fi.isFile() && fi.isSymLink() )
  1026       type = 
tr( 
"file" );
  1027       icon = iconFileLink;
  1029     else if ( fi.isFile() )
  1031       type = 
tr( 
"file" );
  1047   Q_FOREACH ( 
const QVariant& colVariant, lst )
  1055   if ( event->
button() == Qt::RightButton )
  1061     labels << 
tr( 
"Name" ) << 
tr( 
"Size" ) << 
tr( 
"Date" ) << 
tr( 
"Permissions" ) << 
tr( 
"Owner" ) << 
tr( 
"Group" ) << 
tr( 
"Type" );
  1062     for ( 
int i = 0; i < labels.
count(); i++ )
  1080   int columnIndex = action->
objectName().toInt();
  1091   settings.
setValue( 
"/dataitem/directoryHiddenColumns", lst );
  1097   mIconName = 
":/images/icons/qgis-icon-16x16.png";
  1139   Q_FOREACH ( 
const QString& favDir, favDirs )
  1151   favDirs.
append( favDir );
  1152   settings.
setValue( 
"/browser/favourites", favDirs );
  1172   settings.
setValue( 
"/browser/favourites", favDirs );
  1233 void QgsZipItem::init()
  1245     keys << 
"gdal" << 
"ogr";
  1248     for ( i = keys.
begin(); i != keys.
end(); ++i )
  1258         if ( !dataCapabilities )
  1301   char **papszOFiles = 
nullptr;
  1302   char **papszFiles1 = 
nullptr;
  1303   char **papszFiles2 = 
nullptr;
  1304   VSIStatBufL psStatBuf;
  1307   int nCount1, nCount2;
  1310   papszFiles1 = VSIReadDir( pszPath );
  1311   if ( ! papszFiles1 )
  1315   nCount1 = CSLCount( papszFiles1 );
  1316   for ( i = 0; i < nCount1; i++ )
  1319     temp1 = 
QString( 
"%1/%2" ).
arg( pszPath, papszFiles1[i] );
  1322     if ( VSIStatL( temp1.
toUtf8(), &psStatBuf ) == 0 &&
  1323          VSI_ISREG( psStatBuf.st_mode ) )
  1326       papszOFiles = CSLAddString( papszOFiles, papszFiles1[i] );
  1328     else if ( VSIStatL( temp1.
toUtf8(), &psStatBuf ) == 0 &&
  1329               VSI_ISDIR( psStatBuf.st_mode ) )
  1332       temp2 = 
QString( 
"%1/" ).
arg( papszFiles1[i] );
  1335       papszOFiles = CSLAddString( papszOFiles, temp2.
toUtf8() );
  1341         nCount2 = CSLCount( papszFiles2 );
  1342         for ( j = 0; j < nCount2; j++ )
  1344           temp2 = 
QString( 
"%1/%2" ).
arg( papszFiles1[i], papszFiles2[j] );
  1347           papszOFiles = CSLAddString( papszOFiles, temp2.
toUtf8() );
  1349         CSLDestroy( papszFiles2 );
  1353   CSLDestroy( papszFiles1 );
  1371   if ( scanZipSetting == 
"no" )
  1438   int zipFileCount = 0;
  1442   bool populated = 
false;
  1444   QgsDebugMsgLevel( 
QString( 
"path = %1 name= %2 scanZipSetting= %3 vsiPrefix= %4" ).arg( path, name, scanZipSetting, vsiPrefix ), 3 );
  1447   if ( scanZipSetting == 
"no" )
  1451   if (( vsiPrefix != 
"/vsizip/" && vsiPrefix != 
"/vsitar/" ) )
  1454   zipItem = 
new QgsZipItem( parent, name, filePath, path );
  1464     if ( path.
endsWith( 
".zip", Qt::CaseInsensitive ) ||
  1465          path.
endsWith( 
".tar", Qt::CaseInsensitive ) )
  1470     if ( !zipFileList.
isEmpty() && zipFileList.
count() <= 10 )
  1483   if ( zipItem && ( !populated || zipItem->
rowCount() > 1 ) )
  1491     QString vsiPath = vsiPrefix + filePath;
  1495       if ( children.
size() == 1 )
  1500           vsiPath = layerItem->
uri();
  1502       zipFileCount = zipFileList.
count();
  1506     QgsDebugMsgLevel( 
QString( 
"will try to create a normal dataItem from filePath= %2 or vsiPath = %3" ).arg( filePath, vsiPath ), 3 );
  1520           item = dataItem( filePath, parent );
  1523           item = dataItem( vsiPath, parent );
  1545   if ( scanZipSetting == 
"no" )
  1553   if ( papszSiblingFiles )
  1555     for ( 
int i = 0; i < CSLCount( papszSiblingFiles ); i++ )
  1557       tmpPath = papszSiblingFiles[i];
  1560       if ( tmpPath.
right( 1 ) != 
"/" )
  1563     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)
 
bool contains(const Key &key) const
 
QPixmap currentPixmap() const
 
void append(const T &value)
 
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. 
 
static const QIcon & iconPoint()
 
static QgsDataItem * itemFromPath(QgsDataItem *parent, QString path, QString name)
 
QVector< QgsDataItem * > children() const
 
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. 
 
QLibrary * providerLibrary(const QString &providerKey) const
 
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
 
static void deleteLater(QVector< QgsDataItem *> &items)
 
void append(const T &value)
 
const QPoint & globalPos() const
 
QgsDataItem * parent() const
Get item parent. 
 
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()
 
#define Q_NOWARN_DEPRECATED_POP
 
QString & replace(int position, int n, QChar after)
 
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()
 
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
 
static int findItem(QVector< QgsDataItem *> items, QgsDataItem *item)
 
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()
 
virtual void populate(const QVector< QgsDataItem *> &children)
 
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()
 
QMap< QString, QIcon > mIconMap
 
virtual Capabilities capabilities2() const
 
const T value(const Key &key) const
 
void frameChanged()
Emitted when icon changed. 
 
QByteArray toUtf8() const