QGIS API Documentation  3.8.0-Zanzibar (11aff65)
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | List of all members
QgsDataItem Class Reference

Base class for all items in the model. More...

#include <qgsdataitem.h>

Inheritance diagram for QgsDataItem:
Inheritance graph
[legend]

Public Types

enum  Capability {
  NoCapabilities = 0, SetCrs = 1 << 0, Fertile = 1 << 1, Fast = 1 << 2,
  Collapse = 1 << 3, Rename = 1 << 4, Delete = 1 << 5
}
 
enum  State { NotPopulated, Populating, Populated }
 
enum  Type {
  Collection, Directory, Layer, Error,
  Favorites, Project, Custom
}
 

Public Slots

virtual void childrenCreated ()
 
virtual void deleteLater ()
 Safely delete the item: More...
 
virtual void depopulate ()
 Remove children recursively and set as not populated. This is used when refreshing collapsed items. More...
 
virtual void populate (bool foreground=false)
 
virtual void refresh ()
 
virtual void refreshConnections ()
 Refresh connections: update GUI and emit signal. More...
 

Signals

void beginInsertItems (QgsDataItem *parent, int first, int last)
 
void beginRemoveItems (QgsDataItem *parent, int first, int last)
 
void connectionsChanged ()
 Emitted when the provider's connections of the child items have changed This signal is normally forwarded to the app in order to refresh the connection item in the provider dialogs and to refresh the connection items in the other open browsers. More...
 
void dataChanged (QgsDataItem *item)
 
void endInsertItems ()
 
void endRemoveItems ()
 
void stateChanged (QgsDataItem *item, QgsDataItem::State oldState)
 

Public Member Functions

 QgsDataItem (QgsDataItem::Type type, QgsDataItem *parent, const QString &name, const QString &path)
 Create new data item. More...
 
 ~QgsDataItem () override
 
virtual bool acceptDrop ()
 Returns whether the item accepts drag and dropped layers - e.g. More...
 
virtual QList< QAction * > actions (QWidget *parent)
 Returns the list of actions available for this item. More...
 
virtual void addChildItem (QgsDataItem *child, bool refresh=false)
 Inserts a new child item. More...
 
virtual Capabilities capabilities2 () const
 Returns the capabilities for the data item. More...
 
QVector< QgsDataItem * > children () const
 
virtual QVector< QgsDataItem * > createChildren ()
 Create children. More...
 
virtual void deleteChildItem (QgsDataItem *child)
 Removes and deletes a child item, emitting relevant signals to the model. More...
 
virtual bool equal (const QgsDataItem *other)
 Returns true if this item is equal to another item (by testing item type and path). More...
 
virtual bool handleDoubleClick ()
 Called when a user double clicks on the item. More...
 
virtual bool handleDrop (const QMimeData *, Qt::DropAction)
 Attempts to process the mime data dropped on this item. More...
 
bool hasChildren ()
 
virtual bool hasDragEnabled () const
 Returns true if the item may be dragged. More...
 
virtual QIcon icon ()
 
virtual QList< QMenu * > menus (QWidget *parent)
 Returns the list of menus available for this item. More...
 
virtual QgsMimeDataUtils::Uri mimeUri () const
 Returns mime URI for the data item. More...
 
void moveToThread (QThread *targetThread)
 Move object and all its descendants to thread. More...
 
QString name () const
 Returns the name of the item (the displayed text for the item). More...
 
virtual QWidget * paramWidget ()
 
QgsDataItemparent () const
 Gets item parent. More...
 
QString path () const
 
virtual QgsDataItemremoveChildItem (QgsDataItem *child)
 Removes a child item and returns it without deleting it. More...
 
virtual bool rename (const QString &name)
 Sets a new name for the item, and returns true if the item was successfully renamed. More...
 
int rowCount ()
 
virtual void setCapabilities (Capabilities capabilities)
 Sets the capabilities for the data item. More...
 
virtual Q_DECL_DEPRECATED bool setCrs (const QgsCoordinateReferenceSystem &crs)
 Writes the selected crs into data source. More...
 
void setIcon (const QIcon &icon)
 
void setIconName (const QString &iconName)
 
void setName (const QString &name)
 Sets the name of the item (the displayed text for the item). More...
 
void setParent (QgsDataItem *parent)
 Set item parent and connect / disconnect parent to / from item signals. More...
 
void setPath (const QString &path)
 
void setSortKey (const QVariant &key)
 Sets a custom sorting key for the item. More...
 
virtual void setState (State state)
 Set item state. More...
 
void setToolTip (const QString &msg)
 
virtual QVariant sortKey () const
 Returns the sorting key for the item. More...
 
State state () const
 
QString toolTip () const
 
Type type () const
 

Static Public Member Functions

static void deleteLater (QVector< QgsDataItem *> &items)
 
static int findItem (QVector< QgsDataItem *> items, QgsDataItem *item)
 
static QString pathComponent (const QString &component)
 Create path component replacing path separators. More...
 

Protected Slots

void updateIcon ()
 Will request a repaint of this icon. More...
 

Protected Member Functions

bool deferredDelete ()
 The item is scheduled to be deleted. More...
 
virtual void populate (const QVector< QgsDataItem *> &children)
 
virtual void refresh (const QVector< QgsDataItem *> &children)
 Refresh the items from a specified list of child items. More...
 

Protected Attributes

Capabilities mCapabilities
 
QVector< QgsDataItem * > mChildren
 
QIcon mIcon
 
QMap< QString, QIcon > mIconMap
 
QString mIconName
 
QString mName
 
QgsDataItemmParent = nullptr
 
QString mPath
 
QVariant mSortKey
 Custom sort key. If invalid, name() will be used for sorting instead. More...
 
State mState
 
QString mToolTip
 
Type mType
 

Detailed Description

Base class for all items in the model.

Parent/children hierarchy is not based on QObject.

Definition at line 49 of file qgsdataitem.h.

Member Enumeration Documentation

◆ Capability

Enumerator
NoCapabilities 
SetCrs 

Can set CRS on layer or group of layers.

Deprecated:
in QGIS 3.6 – no longer used by QGIS and will be removed in QGIS 4.0
Fertile 

Can create children. Even items without this capability may have children, but cannot create them, it means that children are created by item ancestors.

Fast 

CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,wfs,wcs,postgres...) are considered fast because they are reading data only from QgsSettings.

Collapse 

The collapse/expand status for this items children should be ignored in order to avoid undesired network connections (wms etc.)

Rename 

Item can be renamed.

Delete 

Item can be deleted.

Definition at line 207 of file qgsdataitem.h.

◆ State

Enumerator
NotPopulated 

Children not yet created.

Populating 

Creating children in separate thread (populating or refreshing)

Populated 

Children created.

Definition at line 102 of file qgsdataitem.h.

◆ Type

Enumerator
Collection 
Directory 
Layer 
Error 
Favorites 

Represents a favorite item.

Project 

Represents a QGIS project.

Custom 

Custom item type.

Definition at line 76 of file qgsdataitem.h.

Constructor & Destructor Documentation

◆ QgsDataItem()

QgsDataItem::QgsDataItem ( QgsDataItem::Type  type,
QgsDataItem parent,
const QString &  name,
const QString &  path 
)

Create new data item.

Definition at line 124 of file qgsdataitem.cpp.

◆ ~QgsDataItem()

QgsDataItem::~QgsDataItem ( )
override

Definition at line 137 of file qgsdataitem.cpp.

Member Function Documentation

◆ acceptDrop()

virtual bool QgsDataItem::acceptDrop ( )
inlinevirtual

Returns whether the item accepts drag and dropped layers - e.g.

for importing a dataset to a provider. Subclasses should override this and handleDrop() to accept dropped layers.

See also
handleDrop()

Definition at line 173 of file qgsdataitem.h.

◆ actions()

QList< QAction * > QgsDataItem::actions ( QWidget *  parent)
virtual

Returns the list of actions available for this item.

This is usually used for the popup menu on right-clicking the item. Subclasses should override this to provide actions.

Subclasses should ensure that ownership of created actions is correctly handled by parenting them to the specified parent widget.

Definition at line 550 of file qgsdataitem.cpp.

◆ addChildItem()

void QgsDataItem::addChildItem ( QgsDataItem child,
bool  refresh = false 
)
virtual

Inserts a new child item.

The child will be inserted at a position using an alphabetical order based on mName.

Parameters
childchild item to insert. Ownership is transferred, and item parent will be set and relevant connections made.
refresh- set to true to refresh populated item, emitting relevant signals to the model
See also
deleteChildItem()

Definition at line 468 of file qgsdataitem.cpp.

◆ beginInsertItems

void QgsDataItem::beginInsertItems ( QgsDataItem parent,
int  first,
int  last 
)
signal

◆ beginRemoveItems

void QgsDataItem::beginRemoveItems ( QgsDataItem parent,
int  first,
int  last 
)
signal

◆ capabilities2()

virtual Capabilities QgsDataItem::capabilities2 ( ) const
inlinevirtual

Returns the capabilities for the data item.

See also
setCapabilities()

Definition at line 249 of file qgsdataitem.h.

◆ children()

QVector<QgsDataItem *> QgsDataItem::children ( ) const
inline

Definition at line 276 of file qgsdataitem.h.

◆ childrenCreated

void QgsDataItem::childrenCreated ( )
virtualslot

Definition at line 300 of file qgsdataitem.cpp.

◆ connectionsChanged

void QgsDataItem::connectionsChanged ( )
signal

Emitted when the provider's connections of the child items have changed This signal is normally forwarded to the app in order to refresh the connection item in the provider dialogs and to refresh the connection items in the other open browsers.

◆ createChildren()

QVector< QgsDataItem * > QgsDataItem::createChildren ( )
virtual

Create children.

Children are not expected to have parent set. This method MUST BE THREAD SAFE.

Reimplemented in QgsZipItem, QgsFavoritesItem, and QgsDirectoryItem.

Definition at line 248 of file qgsdataitem.cpp.

◆ dataChanged

void QgsDataItem::dataChanged ( QgsDataItem item)
signal

◆ deferredDelete()

bool QgsDataItem::deferredDelete ( )
inlineprotected

The item is scheduled to be deleted.

E.g. if deleteLater() is called when item is in Populating state (createChildren() running in another thread), the deferredDelete() returns true and item will be deleted once Populating finished. Items with slow reateChildren() (for example network or database based) may check during createChildren() if deferredDelete() returns true and return from createChildren() immediately because result will be useless.

Definition at line 348 of file qgsdataitem.h.

◆ deleteChildItem()

void QgsDataItem::deleteChildItem ( QgsDataItem child)
virtual

Removes and deletes a child item, emitting relevant signals to the model.

Parameters
childchild to remove. Item must exist as a current child.
See also
addChildItem()

Definition at line 504 of file qgsdataitem.cpp.

◆ deleteLater() [1/2]

void QgsDataItem::deleteLater ( QVector< QgsDataItem *> &  items)
static

Definition at line 199 of file qgsdataitem.cpp.

◆ deleteLater [2/2]

void QgsDataItem::deleteLater ( )
virtualslot

Safely delete the item:

  • disconnects parent
  • unsets parent (but does not remove itself)
  • deletes all its descendants recursively
  • waits until Populating state (createChildren() in thread) finished without blocking main thread
  • calls QObject::deleteLater()

Definition at line 175 of file qgsdataitem.cpp.

◆ depopulate

void QgsDataItem::depopulate ( )
virtualslot

Remove children recursively and set as not populated. This is used when refreshing collapsed items.

Definition at line 343 of file qgsdataitem.cpp.

◆ endInsertItems

void QgsDataItem::endInsertItems ( )
signal

◆ endRemoveItems

void QgsDataItem::endRemoveItems ( )
signal

◆ equal()

bool QgsDataItem::equal ( const QgsDataItem other)
virtual

Returns true if this item is equal to another item (by testing item type and path).

Reimplemented in QgsDirectoryItem, and QgsLayerItem.

Definition at line 544 of file qgsdataitem.cpp.

◆ findItem()

int QgsDataItem::findItem ( QVector< QgsDataItem *>  items,
QgsDataItem item 
)
static

Definition at line 532 of file qgsdataitem.cpp.

◆ handleDoubleClick()

bool QgsDataItem::handleDoubleClick ( )
virtual

Called when a user double clicks on the item.

Subclasses should return true if they have implemented a double-click handler and do not want the default double-click behavior for items.

Since
QGIS 3.0

Definition at line 556 of file qgsdataitem.cpp.

◆ handleDrop()

virtual bool QgsDataItem::handleDrop ( const QMimeData *  ,
Qt::DropAction   
)
inlinevirtual

Attempts to process the mime data dropped on this item.

Subclasses must override this and acceptDrop() if they accept dropped layers.

See also
acceptDrop()

Definition at line 180 of file qgsdataitem.h.

◆ hasChildren()

bool QgsDataItem::hasChildren ( )

Definition at line 445 of file qgsdataitem.cpp.

◆ hasDragEnabled()

virtual bool QgsDataItem::hasDragEnabled ( ) const
inlinevirtual

Returns true if the item may be dragged.

Default implementation returns false. A draggable item has to implement mimeUri() that will be used to pass data.

See also
mimeUri()
Since
QGIS 3.0

Reimplemented in QgsProjectItem, QgsDirectoryItem, and QgsLayerItem.

Definition at line 197 of file qgsdataitem.h.

◆ icon()

QIcon QgsDataItem::icon ( )
virtual

Reimplemented in QgsDirectoryItem.

Definition at line 226 of file qgsdataitem.cpp.

◆ menus()

QList< QMenu * > QgsDataItem::menus ( QWidget *  parent)
virtual

Returns the list of menus available for this item.

This is usually used for the popup menu on right-clicking the item. Subclasses should override this to provide actions. Subclasses should ensure that ownership of created menus is correctly handled by parenting them to the specified parent widget.

Parameters
parenta parent widget of the menu
Returns
list of menus
Since
QGIS 3.0

Definition at line 602 of file qgsdataitem.cpp.

◆ mimeUri()

virtual QgsMimeDataUtils::Uri QgsDataItem::mimeUri ( ) const
inlinevirtual

Returns mime URI for the data item.

Items that return valid URI will be returned in mime data when dragging a selection from browser model.

See also
hasDragEnabled()
Since
QGIS 3.0

Reimplemented in QgsProjectItem, QgsDirectoryItem, and QgsLayerItem.

Definition at line 205 of file qgsdataitem.h.

◆ moveToThread()

void QgsDataItem::moveToThread ( QThread *  targetThread)

Move object and all its descendants to thread.

Definition at line 211 of file qgsdataitem.cpp.

◆ name()

QString QgsDataItem::name ( ) const
inline

Returns the name of the item (the displayed text for the item).

See also
setName()

Definition at line 284 of file qgsdataitem.h.

◆ paramWidget()

virtual QWidget* QgsDataItem::paramWidget ( )
inlinevirtual

Reimplemented in QgsDirectoryItem.

Definition at line 147 of file qgsdataitem.h.

◆ parent()

QgsDataItem* QgsDataItem::parent ( ) const
inline

Gets item parent.

QgsDataItem maintains its own items hierarchy, it does not use QObject hierarchy.

Definition at line 270 of file qgsdataitem.h.

◆ path()

QString QgsDataItem::path ( ) const
inline

Definition at line 293 of file qgsdataitem.h.

◆ pathComponent()

QString QgsDataItem::pathComponent ( const QString &  component)
static

Create path component replacing path separators.

Definition at line 160 of file qgsdataitem.cpp.

◆ populate() [1/2]

void QgsDataItem::populate ( const QVector< QgsDataItem *> &  children)
protectedvirtual

Definition at line 328 of file qgsdataitem.cpp.

◆ populate [2/2]

void QgsDataItem::populate ( bool  foreground = false)
virtualslot

Definition at line 253 of file qgsdataitem.cpp.

◆ refresh() [1/2]

void QgsDataItem::refresh ( const QVector< QgsDataItem *> &  children)
protectedvirtual

Refresh the items from a specified list of child items.

Definition at line 394 of file qgsdataitem.cpp.

◆ refresh [2/2]

void QgsDataItem::refresh ( )
virtualslot

Definition at line 357 of file qgsdataitem.cpp.

◆ refreshConnections

void QgsDataItem::refreshConnections ( )
virtualslot

Refresh connections: update GUI and emit signal.

Definition at line 380 of file qgsdataitem.cpp.

◆ removeChildItem()

QgsDataItem * QgsDataItem::removeChildItem ( QgsDataItem child)
virtual

Removes a child item and returns it without deleting it.

Emits relevant signals to model as required.

Parameters
childchild to remove
Returns
pointer to the removed item or nullptr if no such item was found

Definition at line 515 of file qgsdataitem.cpp.

◆ rename()

bool QgsDataItem::rename ( const QString &  name)
virtual

Sets a new name for the item, and returns true if the item was successfully renamed.

Items which implement this method should return the QgsDataItem::Rename capability.

The default implementation does nothing.

Since
QGIS 3.4

Definition at line 561 of file qgsdataitem.cpp.

◆ rowCount()

int QgsDataItem::rowCount ( )

Definition at line 441 of file qgsdataitem.cpp.

◆ setCapabilities()

virtual void QgsDataItem::setCapabilities ( Capabilities  capabilities)
inlinevirtual

Sets the capabilities for the data item.

See also
capabilities2()

Definition at line 256 of file qgsdataitem.h.

◆ setCrs()

virtual Q_DECL_DEPRECATED bool QgsDataItem::setCrs ( const QgsCoordinateReferenceSystem crs)
inlinevirtual

Writes the selected crs into data source.

The original data source will be modified when calling this method.

Deprecated:
since QGIS 3.6. This method is no longer used by QGIS and will be removed in QGIS 4.0.

Definition at line 225 of file qgsdataitem.h.

◆ setIcon()

void QgsDataItem::setIcon ( const QIcon &  icon)
inline

Definition at line 321 of file qgsdataitem.h.

◆ setIconName()

void QgsDataItem::setIconName ( const QString &  iconName)
inline

Definition at line 322 of file qgsdataitem.h.

◆ setName()

void QgsDataItem::setName ( const QString &  name)

Sets the name of the item (the displayed text for the item).

See also
name()

Definition at line 242 of file qgsdataitem.cpp.

◆ setParent()

void QgsDataItem::setParent ( QgsDataItem parent)

Set item parent and connect / disconnect parent to / from item signals.

It does not add itself to parents children (mChildren)

Definition at line 450 of file qgsdataitem.cpp.

◆ setPath()

void QgsDataItem::setPath ( const QString &  path)
inline

Definition at line 294 of file qgsdataitem.h.

◆ setSortKey()

void QgsDataItem::setSortKey ( const QVariant &  key)

Sets a custom sorting key for the item.

See also
sortKey()
Since
QGIS 3.0

Definition at line 170 of file qgsdataitem.cpp.

◆ setState()

void QgsDataItem::setState ( State  state)
virtual

Set item state.

It also take care about starting/stopping loading icon animation.

Parameters
state
Since
QGIS 2.8

Reimplemented in QgsDirectoryItem.

Definition at line 571 of file qgsdataitem.cpp.

◆ setToolTip()

void QgsDataItem::setToolTip ( const QString &  msg)
inline

Definition at line 324 of file qgsdataitem.h.

◆ sortKey()

QVariant QgsDataItem::sortKey ( ) const
virtual

Returns the sorting key for the item.

By default name() is returned, but setSortKey() can be used to set a custom sort key for the item.

Alternatively subclasses can override this method to return a custom sort key.

See also
setSortKey()
Since
QGIS 3.0

Reimplemented in QgsFavoritesItem.

Definition at line 165 of file qgsdataitem.cpp.

◆ state()

QgsDataItem::State QgsDataItem::state ( ) const
Since
QGIS 2.8

Definition at line 566 of file qgsdataitem.cpp.

◆ stateChanged

void QgsDataItem::stateChanged ( QgsDataItem item,
QgsDataItem::State  oldState 
)
signal

◆ toolTip()

QString QgsDataItem::toolTip ( ) const
inline

Definition at line 325 of file qgsdataitem.h.

◆ type()

Type QgsDataItem::type ( ) const
inline

Definition at line 265 of file qgsdataitem.h.

◆ updateIcon

void QgsDataItem::updateIcon ( )
protectedslot

Will request a repaint of this icon.

Since
QGIS 3.0

Definition at line 323 of file qgsdataitem.cpp.

Member Data Documentation

◆ mCapabilities

Capabilities QgsDataItem::mCapabilities
protected

Definition at line 351 of file qgsdataitem.h.

◆ mChildren

QVector<QgsDataItem *> QgsDataItem::mChildren
protected

Definition at line 353 of file qgsdataitem.h.

◆ mIcon

QIcon QgsDataItem::mIcon
protected

Definition at line 363 of file qgsdataitem.h.

◆ mIconMap

QMap<QString, QIcon> QgsDataItem::mIconMap
protected

Definition at line 364 of file qgsdataitem.h.

◆ mIconName

QString QgsDataItem::mIconName
protected

Definition at line 362 of file qgsdataitem.h.

◆ mName

QString QgsDataItem::mName
protected

Definition at line 355 of file qgsdataitem.h.

◆ mParent

QgsDataItem* QgsDataItem::mParent = nullptr
protected

Definition at line 352 of file qgsdataitem.h.

◆ mPath

QString QgsDataItem::mPath
protected

Definition at line 360 of file qgsdataitem.h.

◆ mSortKey

QVariant QgsDataItem::mSortKey
protected

Custom sort key. If invalid, name() will be used for sorting instead.

Definition at line 367 of file qgsdataitem.h.

◆ mState

State QgsDataItem::mState
protected

Definition at line 354 of file qgsdataitem.h.

◆ mToolTip

QString QgsDataItem::mToolTip
protected

Definition at line 361 of file qgsdataitem.h.

◆ mType

Type QgsDataItem::mType
protected

Definition at line 350 of file qgsdataitem.h.


The documentation for this class was generated from the following files: