Skip to content

Commit

Permalink
Create QgsHistoryEntryNode class
Browse files Browse the repository at this point in the history
Used for representing information about of QgsHistoryEntry
in a hierarchical tree structure
  • Loading branch information
nyalldawson committed Apr 22, 2023
1 parent aa7535f commit dd25f39
Show file tree
Hide file tree
Showing 6 changed files with 447 additions and 1 deletion.
115 changes: 115 additions & 0 deletions python/gui/auto_generated/history/qgshistoryentrynode.sip.in
@@ -0,0 +1,115 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/history/qgshistoryentrynode.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsHistoryEntryNode
{
%Docstring(signature="appended")
Base class for nodes representing a :py:class:`QgsHistoryEntry`.

.. versionadded:: 3.32
%End

%TypeHeaderCode
#include "qgshistoryentrynode.h"
%End
public:

QgsHistoryEntryNode();
virtual ~QgsHistoryEntryNode();


QgsHistoryEntryGroup *parent();
%Docstring
Returns the node's parent node.

If parent is ``None``, the node is a root node
%End

virtual QVariant data( int role = Qt::DisplayRole ) const = 0;
%Docstring
Returns the node's data for the specified model ``role``.
%End

virtual int childCount() const;
%Docstring
Returns the number of child nodes owned by this node.
%End


private:
QgsHistoryEntryNode( const QgsHistoryEntryNode &other );
};


class QgsHistoryEntryGroup : QgsHistoryEntryNode
{
%Docstring(signature="appended")
Base class for history entry "group" nodes, which contain children of their own.

.. versionadded:: 3.32
%End

%TypeHeaderCode
#include "qgshistoryentrynode.h"
%End
public:

QgsHistoryEntryGroup();
~QgsHistoryEntryGroup();

void addChild( QgsHistoryEntryNode *child /Transfer/ );
%Docstring
Adds a ``child`` node to this node.

Ownership is transferred to the group.
%End

int indexOf( QgsHistoryEntryNode *child ) const;
%Docstring
Returns the index of the specified ``child`` node.

.. warning::

``child`` must be a valid child of this node.
%End

QgsHistoryEntryNode *childAt( int index );
%Docstring
Returns the child at the specified ``index``.
%End

void removeChildAt( int index );
%Docstring
Removes the child at the specified ``index``.
%End

void clear();
%Docstring
Clears the group, removing all its children.
%End

virtual int childCount() const ${SIP_FINAL};


private:
QgsHistoryEntryGroup( const QgsHistoryEntryGroup &other );
};




/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/history/qgshistoryentrynode.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -342,6 +342,7 @@
%Include auto_generated/effects/qgspainteffectwidget.sip
%Include auto_generated/elevation/qgselevationprofilecanvas.sip
%Include auto_generated/history/qgshistoryentry.sip
%Include auto_generated/history/qgshistoryentrynode.sip
%Include auto_generated/history/qgshistoryprovider.sip
%Include auto_generated/history/qgshistoryproviderregistry.sip
%Include auto_generated/labeling/qgslabellineanchorwidget.sip
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -237,6 +237,7 @@ set(QGIS_GUI_SRCS
elevation/qgselevationprofilelayertreeview.cpp

history/qgshistoryentry.cpp
history/qgshistoryentrynode.cpp
history/qgshistoryprovider.cpp
history/qgshistoryproviderregistry.cpp

Expand Down Expand Up @@ -1144,6 +1145,7 @@ set(QGIS_GUI_HDRS
elevation/qgselevationprofilelayertreeview.h

history/qgshistoryentry.h
history/qgshistoryentrynode.h
history/qgshistoryprovider.h
history/qgshistoryproviderregistry.h

Expand Down
107 changes: 107 additions & 0 deletions src/gui/history/qgshistoryentrynode.cpp
@@ -0,0 +1,107 @@
/***************************************************************************
qgshistoryentrynode.cpp
--------------------------
begin : Aprial 2023
copyright : (C) 2023 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgshistoryentrynode.h"

//
// QgsHistoryEntryNode
//

QgsHistoryEntryNode::~QgsHistoryEntryNode() = default;

int QgsHistoryEntryNode::childCount() const
{
return 0;
}

#if 0
QString QgsHistoryEntryNode::html() const
{
return QString();
}

QWidget *QgsHistoryEntryNode::createWidget()
{
return nullptr;
}

QList<QAction *> QgsHistoryEntryNode::actions( QWidget * )
{
return {};
}

bool QgsHistoryEntryNode::matchesString( const QString & )
{
return false;
}
#endif

//
// QgsHistoryEntryGroup
//

QgsHistoryEntryGroup::~QgsHistoryEntryGroup() = default;

void QgsHistoryEntryGroup::addChild( QgsHistoryEntryNode *child )
{
if ( !child )
return;

Q_ASSERT( !child->mParent );
child->mParent = this;

mChildren.emplace_back( child );
}

int QgsHistoryEntryGroup::indexOf( QgsHistoryEntryNode *child ) const
{
if ( child->mParent != this )
return -1;

auto it = std::find_if( mChildren.begin(), mChildren.end(), [&]( const std::unique_ptr<QgsHistoryEntryNode> &p )
{
return p.get() == child;
} );
if ( it != mChildren.end() )
return std::distance( mChildren.begin(), it );
return -1;
}

QgsHistoryEntryNode *QgsHistoryEntryGroup::childAt( int index )
{
if ( static_cast< std::size_t >( index ) >= mChildren.size() )
return nullptr;

return mChildren[ index ].get();

}

void QgsHistoryEntryGroup::removeChildAt( int index )
{
if ( static_cast< std::size_t >( index ) >= mChildren.size() )
return;

mChildren.erase( mChildren.begin() + index );
}

void QgsHistoryEntryGroup::clear()
{
mChildren.clear();
}

int QgsHistoryEntryGroup::childCount() const
{
return mChildren.size();
}

0 comments on commit dd25f39

Please sign in to comment.