QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgshistoryentrynode.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgshistoryentrynode.cpp
3 --------------------------
4 begin : April 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#include "qgshistoryentrynode.h"
17
18//
19// QgsHistoryEntryNode
20//
21
23
25{
26 return 0;
27}
28
30{
31 return QString();
32}
33
35{
36 return nullptr;
37}
38
40{
41 return false;
42}
43
47
48bool QgsHistoryEntryNode::matchesString( const QString &string ) const
49{
50 if ( string.isEmpty() )
51 return true;
52
53 return data( Qt::DisplayRole ).toString().contains( string, Qt::CaseInsensitive );
54}
55
56
57//
58// QgsHistoryEntryGroup
59//
60
62
64{
65 if ( !child )
66 return;
67
68 Q_ASSERT( !child->mParent );
69 child->mParent = this;
70
71 mChildren.emplace_back( child );
72}
73
75{
76 if ( !child )
77 return;
78
79 Q_ASSERT( !child->mParent );
80 child->mParent = this;
81
82 mChildren.insert( mChildren.begin() + index, std::unique_ptr<QgsHistoryEntryNode>( child ) );
83}
84
86{
87 if ( child->mParent != this )
88 return -1;
89
90 auto it = std::find_if( mChildren.begin(), mChildren.end(), [&]( const std::unique_ptr<QgsHistoryEntryNode> &p ) {
91 return p.get() == child;
92 } );
93 if ( it != mChildren.end() )
94 return static_cast<int>( std::distance( mChildren.begin(), it ) );
95 return -1;
96}
97
99{
100 if ( static_cast<std::size_t>( index ) >= mChildren.size() )
101 return nullptr;
102
103 return mChildren[index].get();
104}
105
107{
108 if ( static_cast<std::size_t>( index ) >= mChildren.size() )
109 return;
110
111 mChildren.erase( mChildren.begin() + index );
112}
113
115{
116 mChildren.clear();
117}
118
120{
121 return static_cast<int>( mChildren.size() );
122}
void addChild(QgsHistoryEntryNode *child)
Adds a child node to this node.
void removeChildAt(int index)
Removes the child at the specified index.
~QgsHistoryEntryGroup() override
int childCount() const FINAL
Returns the number of child nodes owned by this node.
QgsHistoryEntryNode * childAt(int index)
Returns the child at the specified index.
int indexOf(QgsHistoryEntryNode *child) const
Returns the index of the specified child node.
void insertChild(int index, QgsHistoryEntryNode *child)
Inserts a child node at the specified index.
void clear()
Clears the group, removing all its children.
std::deque< std::unique_ptr< QgsHistoryEntryNode > > mChildren
Base class for nodes representing a QgsHistoryEntry.
virtual QWidget * createWidget(const QgsHistoryWidgetContext &context)
Returns a new widget which should be shown to users when selecting the node.
virtual QString html(const QgsHistoryWidgetContext &context) const
Returns a HTML formatted text string which should be shown to a user when selecting the node.
virtual ~QgsHistoryEntryNode()
virtual bool matchesString(const QString &searchString) const
Returns true if the node matches the specified searchString, and should be shown in filtered results ...
virtual QVariant data(int role=Qt::DisplayRole) const =0
Returns the node's data for the specified model role.
virtual void populateContextMenu(QMenu *menu, const QgsHistoryWidgetContext &context)
Allows the node to populate a context menu before display to the user.
virtual int childCount() const
Returns the number of child nodes owned by this node.
virtual bool doubleClicked(const QgsHistoryWidgetContext &context)
Called when the node is double-clicked.
Contains settings which reflect the context in which a history widget is shown, e....