Skip to content

Commit ac328a6

Browse files
committed
Fix QgsDataItem docs
1 parent e290280 commit ac328a6

File tree

3 files changed

+60
-17
lines changed

3 files changed

+60
-17
lines changed

python/core/qgsdataitem.sip

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,28 +94,46 @@ class QgsDataItem : QObject
9494
//! @deprecated in 2.8, use state()
9595
bool isPopulated() /Deprecated/;
9696

97-
// Insert new child using alphabetical order based on mName, emits necessary signal to model before and after, sets parent and connects signals
98-
// refresh - refresh populated item, emit signals to model
97+
/** Inserts a new child item. The child will be inserted at a position using an alphabetical order based on mName.
98+
* @param child child item to insert. Ownership is transferred, and item parent will be set and relevant connections made.
99+
* @param refresh - set to true to refresh populated item, emitting relevant signals to the model
100+
* @see deleteChildItem()
101+
*/
99102
virtual void addChildItem( QgsDataItem *child /Transfer/, bool refresh = false );
100103

101-
// remove and delete child item, signals to browser are emitted
104+
/** Removes and deletes a child item, emitting relevant signals to the model.
105+
* @param child child to remove. Item must exist as a current child.
106+
* @see addChildItem()
107+
*/
102108
virtual void deleteChildItem( QgsDataItem * child );
103109

104-
// remove child item but don't delete it, signals to browser are emitted
105-
// returns pointer to the removed item or null if no such item was found
110+
/** Removes a child item and returns it without deleting it. Emits relevant signals to model as required.
111+
* @param child child to remove
112+
* @returns pointer to the removed item or null if no such item was found
113+
*/
106114
virtual QgsDataItem *removeChildItem( QgsDataItem * child ) /TransferBack/;
107115

116+
/** Returns true if this item is equal to another item (by testing item type and path).
117+
*/
108118
virtual bool equal( const QgsDataItem *other );
109119

110120
virtual QWidget *paramWidget() /Factory/;
111121

112-
// list of actions provided by this item - usually used for popup menu on right-click
122+
/** Returns the list of actions available for this item. This is usually used for the popup menu on right-clicking
123+
* the item. Subclasses should override this to provide actions.
124+
*/
113125
virtual QList<QAction*> actions();
114126

115-
// whether accepts drag&drop'd layers - e.g. for import
127+
/** Returns whether the item accepts drag and dropped layers - e.g. for importing a dataset to a provider.
128+
* Subclasses should override this and handleDrop() to accept dropped layers.
129+
* @see handleDrop()
130+
*/
116131
virtual bool acceptDrop();
117132

118-
// try to process the data dropped on this item
133+
/** Attempts to process the mime data dropped on this item. Subclasses must override this and acceptDrop() if they
134+
* accept dropped layers.
135+
* @see acceptDrop()
136+
*/
119137
virtual bool handleDrop( const QMimeData * /*data*/, Qt::DropAction /*action*/ );
120138

121139
enum Capability

src/core/qgsdataitem.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ void QgsDataItem::addChildItem( QgsDataItem * child, bool refresh )
552552
Q_ASSERT( child );
553553
QgsDebugMsg( QString( "path = %1 add child #%2 - %3 - %4" ).arg( mPath ).arg( mChildren.size() ).arg( child->mName ).arg( child->mType ) );
554554

555+
//calculate position to insert child
555556
int i;
556557
if ( type() == Directory )
557558
{
@@ -581,6 +582,7 @@ void QgsDataItem::addChildItem( QgsDataItem * child, bool refresh )
581582
if ( refresh )
582583
emit endInsertItems();
583584
}
585+
584586
void QgsDataItem::deleteChildItem( QgsDataItem * child )
585587
{
586588
QgsDebugMsgLevel( "mName = " + child->mName, 2 );
@@ -597,10 +599,15 @@ QgsDataItem * QgsDataItem::removeChildItem( QgsDataItem * child )
597599
QgsDebugMsgLevel( "mName = " + child->mName, 2 );
598600
int i = mChildren.indexOf( child );
599601
Q_ASSERT( i >= 0 );
602+
if ( i < 0 )
603+
{
604+
child->setParent( nullptr );
605+
return nullptr;
606+
}
607+
600608
emit beginRemoveItems( this, i, i );
601609
mChildren.remove( i );
602610
emit endRemoveItems();
603-
child->setParent( nullptr );
604611
return child;
605612
}
606613

src/core/qgsdataitem.h

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,28 +119,46 @@ class CORE_EXPORT QgsDataItem : public QObject
119119
//! @deprecated in 2.8, use state()
120120
Q_DECL_DEPRECATED bool isPopulated() { return state() == Populated; }
121121

122-
// Insert new child using alphabetical order based on mName, emits necessary signal to model before and after, sets parent and connects signals
123-
// refresh - refresh populated item, emit signals to model
122+
/** Inserts a new child item. The child will be inserted at a position using an alphabetical order based on mName.
123+
* @param child child item to insert. Ownership is transferred, and item parent will be set and relevant connections made.
124+
* @param refresh - set to true to refresh populated item, emitting relevant signals to the model
125+
* @see deleteChildItem()
126+
*/
124127
virtual void addChildItem( QgsDataItem *child, bool refresh = false );
125128

126-
// remove and delete child item, signals to browser are emitted
129+
/** Removes and deletes a child item, emitting relevant signals to the model.
130+
* @param child child to remove. Item must exist as a current child.
131+
* @see addChildItem()
132+
*/
127133
virtual void deleteChildItem( QgsDataItem * child );
128134

129-
// remove child item but don't delete it, signals to browser are emitted
130-
// returns pointer to the removed item or null if no such item was found
135+
/** Removes a child item and returns it without deleting it. Emits relevant signals to model as required.
136+
* @param child child to remove
137+
* @returns pointer to the removed item or null if no such item was found
138+
*/
131139
virtual QgsDataItem *removeChildItem( QgsDataItem * child );
132140

141+
/** Returns true if this item is equal to another item (by testing item type and path).
142+
*/
133143
virtual bool equal( const QgsDataItem *other );
134144

135145
virtual QWidget *paramWidget() { return nullptr; }
136146

137-
// list of actions provided by this item - usually used for popup menu on right-click
147+
/** Returns the list of actions available for this item. This is usually used for the popup menu on right-clicking
148+
* the item. Subclasses should override this to provide actions.
149+
*/
138150
virtual QList<QAction*> actions() { return QList<QAction*>(); }
139151

140-
// whether accepts drag&drop'd layers - e.g. for import
152+
/** Returns whether the item accepts drag and dropped layers - e.g. for importing a dataset to a provider.
153+
* Subclasses should override this and handleDrop() to accept dropped layers.
154+
* @see handleDrop()
155+
*/
141156
virtual bool acceptDrop() { return false; }
142157

143-
// try to process the data dropped on this item
158+
/** Attempts to process the mime data dropped on this item. Subclasses must override this and acceptDrop() if they
159+
* accept dropped layers.
160+
* @see acceptDrop()
161+
*/
144162
virtual bool handleDrop( const QMimeData * /*data*/, Qt::DropAction /*action*/ ) { return false; }
145163

146164
enum Capability

0 commit comments

Comments
 (0)