labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

SignallingUndoCommand Class Reference

An undo command calling a method/signal/slot on a QObject on redo/undo. More...

#include <SignallingUndoCommand.h>

Inheritance diagram for SignallingUndoCommand:
[legend]
Collaboration diagram for SignallingUndoCommand:
[legend]

Public Member Functions

 SignallingUndoCommand (const QString &text, QObject *receiver, const char *redoMethod, const char *undoMethod, QGenericArgument val0=QGenericArgument(), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument())
 Constructor. More...
 
 ~SignallingUndoCommand () override
 
void redo () override
 
void undo () override
 

Private Member Functions

QGenericArgument arg (int index)
 

Private Attributes

QByteArray m_redo
 
QByteArray m_undo
 
QObject * m_receiver
 
int m_argument_count
 
int * m_argument_types
 
void ** m_argument_data
 

Detailed Description

An undo command calling a method/signal/slot on a QObject on redo/undo.

File : SignallingUndoCommand.h

Project : SciDAVis / LabPlot

Copyright : (C) 2010 Knut Franke Email (use @ for *) : Knut.Franke*gmx.net Description : An undo command calling a method/signal/slot on a QObject on redo/undo.

  • 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. *
  • This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. *
  • You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA *
  • File : SignallingUndoCommand.cpp

Project : SciDAVis / LabPlot

Copyright : (C) 2010 Knut Franke Email (use @ for *) : Knut.Franke*gmx.net Description : An undo command calling a method/signal/slot on a QObject on redo/undo.

  • 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. *
  • This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. *
  • You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA *

SignallingUndoCommand is a generic undo command which can be used in cases where undo/redo events need to be forwarded to given methods, signals or slots of a QObject. That is, it behaves like a cross between an undo command and a Qt signal-slot (or signal-signal) connection. Different methods can be selected for undo and redo, but they are supposed to have the same signature.

The intended use case is to have SignallingUndoCommand trigger notification signals before and after one or more undo commands change some internal state; compare AbstractAspect::exec(QUndoCommand*,const char*,const char*,QGenericArgument,QGenericArgument,QGenericArgument,QGenericArgument). The advantage of separating out the signalling into this class is that the names and arguments of the signals appear in the source code of the Aspect instead of its private class or commands; this is desirable because signals are conceptually part of the public API rather than the internal implementation (compare The Aspect Framework).

SignallingUndoCommand uses Qt's meta object system to dynamically invoke the target method, so the class declaring the method needs to inherit from QObject and contain the Q_OBJECT macro; just as if you wanted it to participate in signal-slot connections (though the methods to be invoked need to be neither signals nor slots). Method arguments are given using the macro Q_ARG(typename, const value&). Since the variable given as "value" will likely be out of scope when undo() is called, a copy needs to be created. This uses QMetaType, which means that (non-trivial) argument types need to be registered using qRegisterMetaType() before giving them to a SignallingUndoCommand (in particular, this also goes for pointers to custom data types). The situation here is analogous to an asynchronous method invocation using QMetaMethod::invoke() with Qt::QueuedConnection.

Definition at line 37 of file SignallingUndoCommand.h.

Constructor & Destructor Documentation

◆ SignallingUndoCommand()

SignallingUndoCommand::SignallingUndoCommand ( const QString &  text,
QObject *  receiver,
const char *  redoMethod,
const char *  undoMethod,
QGenericArgument  val0 = QGenericArgument(),
QGenericArgument  val1 = QGenericArgument(),
QGenericArgument  val2 = QGenericArgument(),
QGenericArgument  val3 = QGenericArgument() 
)

Constructor.

  • text A description of the undo command (compare QUndoCommand::setText()).
  • receiver The object whose methods/signals/slots should be invoked.
  • redo The name of the method to be called when the command is (re-)executed; excluding the signature.
  • undo Analogously to redo, the method to be called when the command is undone.
  • val0,val1,val2,val3 Arguments to the undo and redo methods; to be given using Q_ARG().

Simple example:

QUndoStack stack;
QAction action;
stack.push(new SignallingUndoCommand(i18n("enable action"), &action, "setEnabled", "setDisabled", Q_ARG(bool, true)));
SignallingUndoCommand(const QString &text, QObject *receiver, const char *redoMethod, const char *undoMethod, QGenericArgument val0=QGenericArgument(), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument())
Constructor.
#define i18n(m)
Definition: nsl_common.h:38

Definition at line 80 of file SignallingUndoCommand.cpp.

References m_argument_count, m_argument_data, m_argument_types, and asan_symbolize::type.

◆ ~SignallingUndoCommand()

SignallingUndoCommand::~SignallingUndoCommand ( )
override

Definition at line 108 of file SignallingUndoCommand.cpp.

References m_argument_count, m_argument_data, and m_argument_types.

Member Function Documentation

◆ arg()

QGenericArgument SignallingUndoCommand::arg ( int  index)
private

Definition at line 116 of file SignallingUndoCommand.cpp.

References m_argument_count, m_argument_data, and m_argument_types.

Referenced by redo(), and undo().

◆ redo()

void SignallingUndoCommand::redo ( )
override

Definition at line 123 of file SignallingUndoCommand.cpp.

References arg(), m_receiver, and m_redo.

◆ undo()

void SignallingUndoCommand::undo ( )
override

Definition at line 129 of file SignallingUndoCommand.cpp.

References arg(), m_receiver, and m_undo.

Member Data Documentation

◆ m_argument_count

int SignallingUndoCommand::m_argument_count
private

Definition at line 51 of file SignallingUndoCommand.h.

Referenced by arg(), SignallingUndoCommand(), and ~SignallingUndoCommand().

◆ m_argument_data

void** SignallingUndoCommand::m_argument_data
private

Definition at line 53 of file SignallingUndoCommand.h.

Referenced by arg(), SignallingUndoCommand(), and ~SignallingUndoCommand().

◆ m_argument_types

int* SignallingUndoCommand::m_argument_types
private

Definition at line 52 of file SignallingUndoCommand.h.

Referenced by arg(), SignallingUndoCommand(), and ~SignallingUndoCommand().

◆ m_receiver

QObject* SignallingUndoCommand::m_receiver
private

Definition at line 50 of file SignallingUndoCommand.h.

Referenced by redo(), and undo().

◆ m_redo

QByteArray SignallingUndoCommand::m_redo
private

Definition at line 49 of file SignallingUndoCommand.h.

Referenced by redo().

◆ m_undo

QByteArray SignallingUndoCommand::m_undo
private

Definition at line 49 of file SignallingUndoCommand.h.

Referenced by undo().


The documentation for this class was generated from the following files: