Skip to content

Commit

Permalink
Make API a little more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 22, 2023
1 parent 9ee0453 commit f3f0946
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
5 changes: 2 additions & 3 deletions python/gui/auto_generated/history/qgshistoryprovider.sip.in
Expand Up @@ -8,7 +8,6 @@




class QgsAbstractHistoryProvider
{
%Docstring(signature="appended")
Expand Down Expand Up @@ -38,14 +37,14 @@ Abstract base class for objects which track user history (i.e. operations perfor
Returns the provider's unique id, which is used to associate existing history entries with the provider.
%End

virtual QgsHistoryEntryNode *createNodeForEntry( const QVariantMap &entry ) /Factory/;
virtual QgsHistoryEntryNode *createNodeForEntry( const QgsHistoryEntry &entry ) /Factory/;
%Docstring
Creates a new history node for the given ``entry``.

.. versionadded:: 3.32
%End

virtual void updateNodeForEntry( QgsHistoryEntryNode *node, const QVariantMap &entry );
virtual void updateNodeForEntry( QgsHistoryEntryNode *node, const QgsHistoryEntry &entry );
%Docstring
Updates an existing history ``node`` for the given ``entry``.

Expand Down
6 changes: 4 additions & 2 deletions src/gui/history/qgshistoryentrymodel.cpp
Expand Up @@ -219,14 +219,16 @@ void QgsHistoryEntryModel::entryUpdated( long long id, const QVariantMap &entry,
if ( QgsHistoryEntryNode *node = mIdToNodeHash.value( id ) )
{
bool ok = false;
const QString providerId = mRegistry->entry( id, ok, backend ).providerId;
QgsHistoryEntry historyEntry = mRegistry->entry( id, ok, backend );
historyEntry.entry = entry;
const QString providerId = historyEntry.providerId;
QgsAbstractHistoryProvider *provider = mRegistry->providerById( providerId );
if ( !provider )
return;

const QModelIndex nodeIndex = node2index( node );
const int existingChildRows = node->childCount();
provider->updateNodeForEntry( node, entry );
provider->updateNodeForEntry( node, historyEntry );
const int newChildRows = node->childCount();

if ( newChildRows < existingChildRows )
Expand Down
4 changes: 2 additions & 2 deletions src/gui/history/qgshistoryprovider.cpp
Expand Up @@ -18,12 +18,12 @@

QgsAbstractHistoryProvider::~QgsAbstractHistoryProvider() = default;

QgsHistoryEntryNode *QgsAbstractHistoryProvider::createNodeForEntry( const QVariantMap & )
QgsHistoryEntryNode *QgsAbstractHistoryProvider::createNodeForEntry( const QgsHistoryEntry & )
{
return nullptr;
}

void QgsAbstractHistoryProvider::updateNodeForEntry( QgsHistoryEntryNode *, const QVariantMap & )
void QgsAbstractHistoryProvider::updateNodeForEntry( QgsHistoryEntryNode *, const QgsHistoryEntry & )
{

}
6 changes: 3 additions & 3 deletions src/gui/history/qgshistoryprovider.h
Expand Up @@ -22,7 +22,7 @@
#include <QVariantMap>

class QgsHistoryEntryNode;

class QgsHistoryEntry;

/**
* Abstract base class for objects which track user history (i.e. operations performed through the GUI).
Expand Down Expand Up @@ -57,14 +57,14 @@ class GUI_EXPORT QgsAbstractHistoryProvider
*
* \since QGIS 3.32
*/
virtual QgsHistoryEntryNode *createNodeForEntry( const QVariantMap &entry ) SIP_FACTORY;
virtual QgsHistoryEntryNode *createNodeForEntry( const QgsHistoryEntry &entry ) SIP_FACTORY;

/**
* Updates an existing history \a node for the given \a entry.
*
* \since QGIS 3.32
*/
virtual void updateNodeForEntry( QgsHistoryEntryNode *node, const QVariantMap &entry );
virtual void updateNodeForEntry( QgsHistoryEntryNode *node, const QgsHistoryEntry &entry );

};

Expand Down
10 changes: 5 additions & 5 deletions tests/src/python/test_qgshistoryproviderregistry.py
Expand Up @@ -36,12 +36,12 @@

class TestEntryNode(QgsHistoryEntryGroup):

def __init__(self, entry):
def __init__(self, val):
super().__init__()
self.entry = entry
self.val = val

def data(self, role):
return self.entry
return self.val


class TestHistoryProvider(QgsAbstractHistoryProvider):
Expand All @@ -50,10 +50,10 @@ def id(self) -> str:
return 'test_provider'

def createNodeForEntry(self, entry):
return TestEntryNode(entry)
return TestEntryNode(entry.entry)

def updateNodeForEntry(self, node, entry):
node.entry = entry
node.val = entry.entry

new_child_node = TestEntryNode('my child')
node.addChild(new_child_node)
Expand Down

0 comments on commit f3f0946

Please sign in to comment.