QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
layout
qgslayoutserializableobject.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgslayoutserializableobject.cpp
3
-------------------------------
4
begin : July 2017
5
copyright : (C) 2017 by Nyall Dawson
6
email : nyall dot dawson at gmail dot com
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
15
* *
16
***************************************************************************/
17
18
#include "
qgslayoutserializableobject.h
"
19
20
#include "
qgslayout.h
"
21
#include "
qgsproject.h
"
22
#include "
qgsreadwritecontext.h
"
23
24
#include <QString>
25
26
using namespace
Qt::StringLiterals;
27
29
class
QgsLayoutSerializableObjectUndoCommand :
public
QgsAbstractLayoutUndoCommand
30
{
31
public
:
32
QgsLayoutSerializableObjectUndoCommand( QgsLayoutSerializableObject *
object
,
const
QString &text,
int
id
, QUndoCommand *parent
SIP_TRANSFERTHIS
=
nullptr
)
33
: QgsAbstractLayoutUndoCommand( text, id, parent )
34
, mObject( object )
35
{}
36
37
bool
mergeWith(
const
QUndoCommand *command )
override
38
{
39
if
( command->id() == 0 )
40
return
false
;
41
42
const
QgsLayoutSerializableObjectUndoCommand *
c
=
dynamic_cast<
const
QgsLayoutSerializableObjectUndoCommand *
>
( command );
43
if
( !
c
)
44
{
45
return
false
;
46
}
47
48
if
( mObject->stringType() !=
c
->mObject->stringType() )
49
return
false
;
50
51
setAfterState(
c
->afterState() );
52
return
true
;
53
}
54
55
protected
:
56
void
saveState( QDomDocument &stateDoc )
const override
57
{
58
stateDoc.clear();
59
QDomElement documentElement = stateDoc.createElement( u
"UndoState"
_s );
60
mObject->writeXml( documentElement, stateDoc, QgsReadWriteContext() );
61
stateDoc.appendChild( documentElement );
62
}
63
void
restoreState( QDomDocument &stateDoc )
override
64
{
65
if
( !mObject )
66
{
67
return
;
68
}
69
70
mObject->readXml( stateDoc.documentElement().firstChild().toElement(), stateDoc, QgsReadWriteContext() );
71
mObject->layout()->project()->setDirty(
true
);
72
}
73
74
private
:
75
QgsLayoutSerializableObject *mObject =
nullptr
;
76
};
78
79
80
QgsAbstractLayoutUndoCommand
*
QgsLayoutSerializableObject::createCommand
(
const
QString &text,
int
id
, QUndoCommand *parent )
81
{
82
return
new
QgsLayoutSerializableObjectUndoCommand
(
this
, text,
id
, parent );
83
}
QgsAbstractLayoutUndoCommand
Base class for commands to undo/redo layout and layout object changes.
Definition
qgslayoutundocommand.h:34
QgsLayoutSerializableObject::QgsLayoutSerializableObjectUndoCommand
friend class QgsLayoutSerializableObjectUndoCommand
Definition
qgslayoutserializableobject.h:64
QgsLayoutSerializableObject::createCommand
QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id, QUndoCommand *parent=nullptr) override
Creates a new layout undo command with the specified text and parent.
Definition
qgslayoutserializableobject.cpp:80
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition
porting_processing.dox:1
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition
qgis_sip.h:52
qgslayout.h
qgslayoutserializableobject.h
qgsproject.h
qgsreadwritecontext.h
Generated on
for QGIS API Documentation by
1.17.0