QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
26 #include "qgsconfig.h"
33 #include <QApplication>
34 #include <QtConcurrentMap>
35 #include <QtConcurrentRun>
37 #include <QElapsedTimer>
41 #include <QMouseEvent>
42 #include <QTreeWidget>
43 #include <QTreeWidgetItem>
48 #include <QRegularExpression>
51 #define CPL_SUPRESS_CPLUSPLUS //#spellok
53 #include "cpl_string.h"
62 , mProviderKey( providerKey )
79 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
82 QgsDebugMsg( QStringLiteral(
"mFutureWatcher not finished (should not happen) -> waitForFinished()" ) );
83 mDeferredDelete =
true;
84 mFutureWatcher->waitForFinished();
87 delete mFutureWatcher;
92 const thread_local QRegularExpression rx(
"[\\\\/]" );
93 return QString(
string ).replace( rx, QStringLiteral(
"|" ) );
115 child->deleteLater();
119 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
121 QgsDebugMsg( QStringLiteral(
"mFutureWatcher not finished -> schedule to delete later" ) );
122 mDeferredDelete =
true;
126 QObject::deleteLater();
132 const auto constItems = items;
151 child->QObject::setParent(
nullptr );
152 child->moveToThread( targetThread );
154 QObject::moveToThread( targetThread );
165 return sPopulatingIcon->
icon();
167 if ( !
mIcon.isNull() )
186 return QVector<QgsDataItem *>();
204 if ( !mFutureWatcher )
206 mFutureWatcher =
new QFutureWatcher< QVector <QgsDataItem *> >( this );
210 mFutureWatcher->setFuture( QtConcurrent::run( runCreateChildren,
this ) );
215 QVector<QgsDataItem *> QgsDataItem::runCreateChildren(
QgsDataItem *item )
221 QgsDebugMsgLevel( QStringLiteral(
"%1 children created in %2 ms" ).arg(
children.size() ).arg( time.elapsed() ), 3 );
223 const auto constChildren =
children;
230 child->moveToThread( qApp->thread() );
238 QgsDebugMsgLevel( QStringLiteral(
"path = %1 children.size() = %2" ).arg(
path() ).arg( mFutureWatcher->result().size() ), 3 );
242 QgsDebugMsg( QStringLiteral(
"Item was scheduled to be deleted later" ) );
243 QObject::deleteLater();
249 populate( mFutureWatcher->result() );
253 refresh( mFutureWatcher->result() );
268 const auto constChildren =
children;
307 if ( !mFutureWatcher )
309 mFutureWatcher =
new QFutureWatcher< QVector <QgsDataItem *> >( this );
312 mFutureWatcher->setFuture( QtConcurrent::run( runCreateChildren,
this ) );
336 QVector<QgsDataItem *> remove;
344 remove.append( child );
346 const auto constRemove = remove;
354 const auto constChildren =
children;
367 mChildren.value( index )->refresh( child->children() );
375 child->deleteLater();
411 disconnect(
this,
nullptr,
mParent,
nullptr );
428 QgsDebugMsgLevel( QStringLiteral(
"path = %1 add child #%2 - %3 - %4" ).arg(
mPath ).arg(
mChildren.size() ).arg( child->
mName ).arg( qgsEnumValueToKey< Qgis::BrowserItemType >( child->
mType ) ), 3 );
446 if (
mChildren.at( i )->mName.localeAwareCompare( child->
mName ) >= 0 )
464 const int i =
mChildren.indexOf( child );
475 const int i =
mChildren.indexOf( child );
491 for (
int i = 0; i < items.size(); i++ )
493 Q_ASSERT_X( items[i],
"findItem", QStringLiteral(
"item %1 is nullptr" ).arg( i ).toLatin1() );
495 if ( items[i]->
equal( item ) )
503 return ( metaObject()->className() == other->metaObject()->className() &&
510 return QList<QAction *>();
549 setCapabilities(
static_cast< Qgis::BrowserItemCapabilities
>( capabilities ) );
559 QgsDebugMsgLevel( QStringLiteral(
"item %1 set state %2 -> %3" ).arg(
path() ).arg( qgsEnumValueToKey< Qgis::BrowserItemState >( this->
state() ) ).arg( qgsEnumValueToKey< Qgis::BrowserItemState >(
state ) ), 3 );
567 if ( !sPopulatingIcon )
591 return QList<QMenu *>();
597 mIconName = QStringLiteral(
"/mIconDelete.svg" );
QString uri
Identifier of the data source recognized by its providerKey.
QMap< QString, QIcon > mIconMap
@ NotPopulated
Children not yet created.
#define QgsDebugMsgLevel(str, level)
BrowserItemState
Browser item states.
const QgsCoordinateReferenceSystem & crs
virtual QVariant sortKey() const
Returns the sorting key for the item.
Qgis::BrowserItemState state() const
void setProviderKey(const QString &value)
Sets the provider key that created this item (e.g.
QString name() const
Returns the name of the item (the displayed text for the item).
void dataChanged(QgsDataItem *item)
static void deleteLater(QVector< QgsDataItem * > &items)
virtual bool layerCollection() const
Returns true if the data item is a collection of layers The default implementation returns false,...
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
QList< QgsMimeDataUtils::Uri > UriList
QVariant mSortKey
Custom sort key. If invalid, name() will be used for sorting instead.
QgsDataItem(Qgis::BrowserItemType type, QgsDataItem *parent, const QString &name, const QString &path, const QString &providerKey=QString())
Constructor for QgsDataItem, with the specified parent item.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
void beginRemoveItems(QgsDataItem *parent, int first, int last)
virtual bool equal(const QgsDataItem *other)
Returns true if this item is equal to another item (by testing item type and path).
virtual void depopulate()
Remove children recursively and set as not populated. This is used when refreshing collapsed items.
virtual QgsAbstractDatabaseProviderConnection * databaseConnection() const
For data items that represent a DB connection or one of its children, this method returns a connectio...
static QString pathComponent(const QString &component)
Create path component replacing path separators.
virtual void refreshConnections(const QString &providerKey=QString())
Causes a data item provider to refresh all registered connections.
Qgis::BrowserItemType mType
@ ItemRepresentsFile
Item's path() directly represents a file on disk (since QGIS 3.22)
virtual Q_DECL_DEPRECATED bool rename(const QString &name)
Sets a new name for the item, and returns true if the item was successfully renamed.
QgsDataItem * parent() const
Gets item parent.
bool connectFrameChanged(const typename QtPrivate::FunctionPointer< Func1 >::Object *receiver, Func1 slot)
Connect a slot that will be notified repeatedly whenever a frame changes and which should request the...
Qgis::BrowserItemState mState
QIcon icon() const
Gets the icons representation in the current frame.
@ RefreshChildrenWhenItemIsRefreshed
When the item is refreshed, all its populated children will also be refreshed in turn (since QGIS 3....
@ Populated
Children created.
virtual Q_DECL_DEPRECATED bool setCrs(const QgsCoordinateReferenceSystem &crs)
Writes the selected crs into data source.
virtual void setState(Qgis::BrowserItemState state)
Set item state.
virtual bool handleDoubleClick()
Called when a user double clicks on the item.
QString filePath
Path to file, if uri is associated with a file.
bool disconnectFrameChanged(const typename QtPrivate::FunctionPointer< Func1 >::Object *receiver, Func1 slot)
Convenience function to disconnect the same style that the frame change connection was established.
Animated icon is keeping an animation running if there are listeners connected to frameChanged.
This class represents a coordinate reference system (CRS).
void connectionsChanged(const QString &providerKey=QString())
Emitted when the connections of the provider with the specified providerKey have changed.
void moveToThread(QThread *targetThread)
Move object and all its descendants to thread.
virtual QList< QAction * > actions(QWidget *parent)
Returns the list of actions available for this item.
void stateChanged(QgsDataItem *item, Qgis::BrowserItemState oldState)
Emitted when an item's state is changed.
void updateIcon()
Will request a repaint of this icon.
virtual Q_DECL_DEPRECATED QgsMimeDataUtils::Uri mimeUri() const
Returns mime URI for the data item.
virtual void addChildItem(QgsDataItem *child, bool refresh=false)
Inserts a new child item.
void setName(const QString &name)
Sets the name of the item (the displayed text for the item).
virtual void setCapabilities(Qgis::BrowserItemCapabilities capabilities)
Sets the capabilities for the data item.
virtual void populate(const QVector< QgsDataItem * > &children)
QVector< QgsDataItem * > mChildren
@ Populating
Creating children in separate thread (populating or refreshing)
QVector< QgsDataItem * > children() const
The Qgis class provides global constants for use throughout the application.
bool deferredDelete()
The item is scheduled to be deleted.
static int findItem(QVector< QgsDataItem * > items, QgsDataItem *item)
virtual QgsMimeDataUtils::UriList mimeUris() const
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
virtual QList< QMenu * > menus(QWidget *parent)
Returns the list of menus available for this item.
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
virtual void deleteLater()
Safely delete the item:
QString providerKey() const
Returns the provider key that created this item (e.g.
virtual QgsDataItem * removeChildItem(QgsDataItem *child)
Removes a child item and returns it without deleting it.
Base class for all items in the model.
virtual void deleteChildItem(QgsDataItem *child)
Removes and deletes a child item, emitting relevant signals to the model.
void setSortKey(const QVariant &key)
Sets a custom sorting key for the item.
void setParent(QgsDataItem *parent)
Set item parent and connect / disconnect parent to / from item signals.
QgsErrorItem(QgsDataItem *parent, const QString &error, const QString &path)
Qgis::BrowserItemType type() const
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
@ Fertile
Can create children. Even items without this capability may have children, but cannot create them,...
@ Directory
Represents a file directory.
virtual QVector< QgsDataItem * > createChildren()
Create children.
void beginInsertItems(QgsDataItem *parent, int first, int last)
BrowserItemType
Symbol layer flags.
virtual void childrenCreated()