Examples: move widgets specific "tools" examples to the correct place
examples/tools -> examples/widgets/tools Change-Id: I8b9e23c45e07ce5cd9da8f24a9a9f7ae10b2b107 Reviewed-by: hjk <qthjk@ovi.com>
@ -43,7 +43,8 @@
|
||||
#include <QContiguousCache>
|
||||
#include <QAbstractListModel>
|
||||
|
||||
class QTimer;
|
||||
QT_FORWARD_DECLARE_CLASS(QTimer)
|
||||
|
||||
class RandomListModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -44,7 +44,7 @@
|
||||
#include <QWidget>
|
||||
#include "message.h"
|
||||
|
||||
class QTextEdit;
|
||||
QT_FORWARD_DECLARE_CLASS(QTextEdit)
|
||||
|
||||
//! [Window class definition]
|
||||
class Window : public QWidget
|
||||
|
@ -1,21 +1,8 @@
|
||||
TEMPLATE = subdirs
|
||||
CONFIG += ordered
|
||||
SUBDIRS = codecs \
|
||||
completer \
|
||||
customcompleter \
|
||||
echoplugin \
|
||||
i18n \
|
||||
contiguouscache \
|
||||
plugandpaintplugins \
|
||||
plugandpaint \
|
||||
regexp \
|
||||
settingseditor \
|
||||
styleplugin \
|
||||
treemodelcompleter \
|
||||
undo \
|
||||
undoframework
|
||||
|
||||
plugandpaint.depends = plugandpaintplugins
|
||||
SUBDIRS = contiguouscache \
|
||||
customtype \
|
||||
customtypesending
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/tools
|
||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 7.4 KiB After Width: | Height: | Size: 7.4 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 83 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
@ -26,7 +26,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example completer
|
||||
\example tools/completer
|
||||
\title Completer Example
|
||||
|
||||
The Completer example shows how to provide string-completion facilities
|
||||
@ -45,14 +45,14 @@
|
||||
\e{countries.txt} and \e{words.txt}. The resource file contains the
|
||||
following code:
|
||||
|
||||
\quotefile completer/completer.qrc
|
||||
\quotefile tools/completer/completer.qrc
|
||||
|
||||
\section1 FileSystemModel Class Definition
|
||||
|
||||
The \c FileSystemModel class is a subclass of QFileSystemModel, which provides a data
|
||||
model for the local filesystem.
|
||||
|
||||
\snippet completer/fsmodel.h 0
|
||||
\snippet tools/completer/fsmodel.h 0
|
||||
|
||||
This class only has a constructor and a \c data() function as it is only
|
||||
created to enable \c data() to return the entire file path for the
|
||||
@ -65,14 +65,14 @@
|
||||
The constructor for the \c FileSystemModel class is used to pass \a parent to
|
||||
QFileSystemModel.
|
||||
|
||||
\snippet completer/fsmodel.cpp 0
|
||||
\snippet tools/completer/fsmodel.cpp 0
|
||||
|
||||
As mentioned earlier, the \c data() function is reimplemented in order to
|
||||
get it to return the entire file parth for the display role. For example,
|
||||
with a QFileSystemModel, you will see "Program Files" in the view. However, with
|
||||
\c FileSystemModel, you will see "C:\\Program Files".
|
||||
|
||||
\snippet completer/fsmodel.cpp 1
|
||||
\snippet tools/completer/fsmodel.cpp 1
|
||||
|
||||
The screenshots below illustrate this difference:
|
||||
|
||||
@ -90,14 +90,14 @@
|
||||
private slots - \c about(), \c changeCase(), \c changeMode(), \c changeModel(),
|
||||
and \c changeMaxVisible().
|
||||
|
||||
\snippet completer/mainwindow.h 0
|
||||
\snippet tools/completer/mainwindow.h 0
|
||||
|
||||
Within the \c MainWindow class, we have two private functions:
|
||||
\c createMenu() and \c modelFromFile(). We also declare the private widgets
|
||||
needed - three QComboBox objects, a QCheckBox, a QCompleter, a QLabel, and
|
||||
a QLineEdit.
|
||||
|
||||
\snippet completer/mainwindow.h 1
|
||||
\snippet tools/completer/mainwindow.h 1
|
||||
|
||||
\section1 MainWindow Class Implementation
|
||||
|
||||
@ -110,7 +110,7 @@
|
||||
the \c modeCombo is set to "Filtered Popup" and the \c caseCombo is set
|
||||
to "Case Insensitive".
|
||||
|
||||
\snippet completer/mainwindow.cpp 0
|
||||
\snippet tools/completer/mainwindow.cpp 0
|
||||
|
||||
The \c maxVisibleSpinBox is created and determines the number of visible
|
||||
item in the completer
|
||||
@ -119,26 +119,26 @@
|
||||
\c{completer}'s \l{QCompleter::setWrapAround()}{setWrapAround()} property
|
||||
is enabled or disabled.
|
||||
|
||||
\snippet completer/mainwindow.cpp 1
|
||||
\snippet tools/completer/mainwindow.cpp 1
|
||||
|
||||
We instantiate \c contentsLabel and set its size policy to
|
||||
\l{QSizePolicy::Fixed}{fixed}. The combo boxes' \l{QComboBox::activated()}
|
||||
{activated()} signals are then connected to their respective slots.
|
||||
|
||||
\snippet completer/mainwindow.cpp 2
|
||||
\snippet tools/completer/mainwindow.cpp 2
|
||||
|
||||
The \c lineEdit is set up and then we arrange all the widgets using a
|
||||
QGridLayout. The \c changeModel() function is called, to initialize the
|
||||
\c completer.
|
||||
|
||||
\snippet completer/mainwindow.cpp 3
|
||||
\snippet tools/completer/mainwindow.cpp 3
|
||||
|
||||
The \c createMenu() function is used to instantiate the QAction objects
|
||||
needed to fill the \c fileMenu and \c helpMenu. The actions'
|
||||
\l{QAction::triggered()}{triggered()} signals are connected to their
|
||||
respective slots.
|
||||
|
||||
\snippet completer/mainwindow.cpp 4
|
||||
\snippet tools/completer/mainwindow.cpp 4
|
||||
|
||||
The \c modelFromFile() function accepts the \a fileName of a file and
|
||||
processes it depending on its contents.
|
||||
@ -147,26 +147,26 @@
|
||||
QFile::ReadOnly mode. If this is unsuccessful, the function returns an
|
||||
empty QStringListModel.
|
||||
|
||||
\snippet completer/mainwindow.cpp 5
|
||||
\snippet tools/completer/mainwindow.cpp 5
|
||||
|
||||
The mouse cursor is then overridden with Qt::WaitCursor before we fill
|
||||
a QStringList object, \c words, with the contents of \c file. Once this
|
||||
is done, we restore the mouse cursor.
|
||||
|
||||
\snippet completer/mainwindow.cpp 6
|
||||
\snippet tools/completer/mainwindow.cpp 6
|
||||
|
||||
As mentioned earlier, the resources file contains two files -
|
||||
\e{countries.txt} and \e{words.txt}. If the \c file read is \e{words.txt},
|
||||
we return a QStringListModel with \c words as its QStringList and
|
||||
\c completer as its parent.
|
||||
|
||||
\snippet completer/mainwindow.cpp 7
|
||||
\snippet tools/completer/mainwindow.cpp 7
|
||||
|
||||
If the \c file read is \e{countries.txt}, then we require a
|
||||
QStandardItemModel with \c words.count() rows, 2 columns, and \c completer
|
||||
as its parent.
|
||||
|
||||
\snippet completer/mainwindow.cpp 8
|
||||
\snippet tools/completer/mainwindow.cpp 8
|
||||
|
||||
A standard line in \e{countries.txt} is:
|
||||
\quotation
|
||||
@ -177,12 +177,12 @@
|
||||
split the country name and its symbol. Once this is done, we return
|
||||
\c m.
|
||||
|
||||
\snippet completer/mainwindow.cpp 9
|
||||
\snippet tools/completer/mainwindow.cpp 9
|
||||
|
||||
The \c changeMode() function sets the \c{completer}'s mode, depending on
|
||||
the value of \c index.
|
||||
|
||||
\snippet completer/mainwindow.cpp 10
|
||||
\snippet tools/completer/mainwindow.cpp 10
|
||||
|
||||
The \c changeModel() function changes the item model used based on the
|
||||
model selected by the user.
|
||||
@ -191,7 +191,7 @@
|
||||
of \c modelCombo. If \c case is 0, we use an unsorted QFileSystemModel, providing
|
||||
us with a file path excluding the drive label.
|
||||
|
||||
\snippet completer/mainwindow.cpp 11
|
||||
\snippet tools/completer/mainwindow.cpp 11
|
||||
|
||||
Note that we create the model with \c completer as the parent as this
|
||||
allows us to replace the model with a new model. The \c completer will
|
||||
@ -201,14 +201,14 @@
|
||||
If \c case is 1, we use the \c DirModel we defined earlier, resulting in
|
||||
full paths for the files.
|
||||
|
||||
\snippet completer/mainwindow.cpp 12
|
||||
\snippet tools/completer/mainwindow.cpp 12
|
||||
|
||||
When \c case is 2, we attempt to complete names of countries. This requires
|
||||
a QTreeView object, \c treeView. The country names are extracted from
|
||||
\e{countries.txt} and set the popup used to display completions to
|
||||
\c treeView.
|
||||
|
||||
\snippet completer/mainwindow.cpp 13
|
||||
\snippet tools/completer/mainwindow.cpp 13
|
||||
|
||||
The screenshot below shows the Completer with the country list model.
|
||||
|
||||
@ -229,21 +229,21 @@
|
||||
to the \c{completer}'s \l{QCompleter::setWrapAround()}{setWrapAround()}
|
||||
slot.
|
||||
|
||||
\snippet completer/mainwindow.cpp 14
|
||||
\snippet tools/completer/mainwindow.cpp 14
|
||||
|
||||
The \c changeMaxVisible() update the maximum number of visible items in
|
||||
the completer.
|
||||
|
||||
\snippet completer/mainwindow.cpp 15
|
||||
\snippet tools/completer/mainwindow.cpp 15
|
||||
|
||||
The \c about() function provides a brief description about the example.
|
||||
|
||||
\snippet completer/mainwindow.cpp 16
|
||||
\snippet tools/completer/mainwindow.cpp 16
|
||||
|
||||
\section1 \c main() Function
|
||||
|
||||
The \c main() function instantiates QApplication and \c MainWindow and
|
||||
invokes the \l{QWidget::show()}{show()} function.
|
||||
|
||||
\snippet completer/main.cpp 0
|
||||
\snippet tools/completer/main.cpp 0
|
||||
*/
|
@ -26,7 +26,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example echoplugin
|
||||
\example tools/echoplugin
|
||||
\title Echo Plugin Example
|
||||
|
||||
This example shows how to create a Qt plugin.
|
||||
@ -64,7 +64,7 @@
|
||||
The \c EchoWindow class lets us test the \c EchoPlugin through a
|
||||
GUI.
|
||||
|
||||
\snippet echoplugin/echowindow/echowindow.h 0
|
||||
\snippet tools/echoplugin/echowindow/echowindow.h 0
|
||||
|
||||
We load the plugin in \c loadPlugin() and cast it to \c
|
||||
EchoInterface. When the user clicks the \c button we take the
|
||||
@ -75,7 +75,7 @@
|
||||
|
||||
We start with a look at the constructor:
|
||||
|
||||
\snippet echoplugin/echowindow/echowindow.cpp 0
|
||||
\snippet tools/echoplugin/echowindow/echowindow.cpp 0
|
||||
|
||||
We create the widgets and set a title for the window. We then load
|
||||
the plugin. \c loadPlugin() returns false if the plugin could not
|
||||
@ -86,7 +86,7 @@
|
||||
|
||||
Here is the implementation of \c sendEcho():
|
||||
|
||||
\snippet echoplugin/echowindow/echowindow.cpp 1
|
||||
\snippet tools/echoplugin/echowindow/echowindow.cpp 1
|
||||
|
||||
This slot is called when the user pushes \c button or presses
|
||||
enter in \c lineEdit. We call \c echo() of the echo interface. In
|
||||
@ -96,14 +96,14 @@
|
||||
|
||||
Here is the implementation of \c createGUI():
|
||||
|
||||
\snippet echoplugin/echowindow/echowindow.cpp 2
|
||||
\snippet tools/echoplugin/echowindow/echowindow.cpp 2
|
||||
|
||||
We create the widgets and lay them out in a grid layout. We
|
||||
connect the label and line edit to our \c sendEcho() slot.
|
||||
|
||||
Here is the \c loadPlugin() function:
|
||||
|
||||
\snippet echoplugin/echowindow/echowindow.cpp 3
|
||||
\snippet tools/echoplugin/echowindow/echowindow.cpp 3
|
||||
|
||||
Access to plugins at run-time is provided by QPluginLoader. You
|
||||
supply it with the filename of the shared library the plugin is
|
||||
@ -126,7 +126,7 @@
|
||||
virtual functions. If non virtual functions were present in the
|
||||
class you would get misleading compile errors in the moc files.
|
||||
|
||||
\snippet echoplugin/echowindow/echointerface.h 0
|
||||
\snippet tools/echoplugin/echowindow/echointerface.h 0
|
||||
|
||||
We declare \c echo(). In our \c EchoPlugin we use this method to
|
||||
return, or echo, \a message.
|
||||
@ -146,18 +146,18 @@
|
||||
If a class implements more than one interface, they are given as
|
||||
a comma separated list.
|
||||
|
||||
\snippet echoplugin/plugin/echoplugin.h 0
|
||||
\snippet tools/echoplugin/plugin/echoplugin.h 0
|
||||
|
||||
|
||||
\section1 EchoPlugin Class Implementation
|
||||
|
||||
Here is the implementation of \c echo():
|
||||
|
||||
\snippet echoplugin/plugin/echoplugin.cpp 0
|
||||
\snippet tools/echoplugin/plugin/echoplugin.cpp 0
|
||||
|
||||
We simply return the functions parameter.
|
||||
|
||||
\snippet echoplugin/plugin/echoplugin.cpp 1
|
||||
\snippet tools/echoplugin/plugin/echoplugin.cpp 1
|
||||
|
||||
We use the Q_EXPORT_PLUGIN2 macro to let Qt know that the \c
|
||||
EchoPlugin class is a plugin. The first parameter is the name of
|
||||
@ -166,7 +166,7 @@
|
||||
|
||||
\section1 The \c main() function
|
||||
|
||||
\snippet echoplugin/echowindow/main.cpp 0
|
||||
\snippet tools/echoplugin/echowindow/main.cpp 0
|
||||
|
||||
We create an \c EchoWindow and display it as a top-level window.
|
||||
|
||||
@ -179,12 +179,12 @@
|
||||
template and simply includes includes to directories in which
|
||||
the echo window and echo plugin lives:
|
||||
|
||||
\snippet echoplugin/echoplugin.pro 0
|
||||
\snippet tools/echoplugin/echoplugin.pro 0
|
||||
|
||||
The profile for the echo window does not need any plugin specific
|
||||
settings. We move on to the plugin profile:
|
||||
|
||||
\snippet echoplugin/plugin/plugin.pro 0
|
||||
\snippet tools/echoplugin/plugin/plugin.pro 0
|
||||
|
||||
We need to set the TEMPLATE as we now want to make a library
|
||||
instead of an executable. We also need to tell qmake that we are
|
@ -26,7 +26,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example i18n
|
||||
\example tools/i18n
|
||||
\title I18N Example
|
||||
|
||||
The Internationalization (I18N) example demonstrates Qt's support for translated
|
@ -26,7 +26,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example plugandpaint
|
||||
\example tools/plugandpaint
|
||||
\title Plug & Paint Example
|
||||
|
||||
The Plug & Paint example demonstrates how to write Qt
|
||||
@ -74,7 +74,7 @@
|
||||
in the plugins.
|
||||
|
||||
|
||||
\snippet plugandpaint/interfaces.h 0
|
||||
\snippet tools/plugandpaint/interfaces.h 0
|
||||
|
||||
The \c BrushInterface class declares four pure virtual functions.
|
||||
The first pure virtual function, \c brushes(), returns a list of
|
||||
@ -96,7 +96,7 @@
|
||||
virtual destructor. We provide the destructor to keep these
|
||||
compilers happy.
|
||||
|
||||
\snippet plugandpaint/interfaces.h 1
|
||||
\snippet tools/plugandpaint/interfaces.h 1
|
||||
|
||||
The \c ShapeInterface class declares a \c shapes() function that
|
||||
works the same as \c{BrushInterface}'s \c brushes() function, and
|
||||
@ -106,13 +106,13 @@
|
||||
parent parameter can be used by the plugin to pop up a dialog
|
||||
asking the user to specify more information.
|
||||
|
||||
\snippet plugandpaint/interfaces.h 2
|
||||
\snippet tools/plugandpaint/interfaces.h 2
|
||||
|
||||
The \c FilterInterface class declares a \c filters() function
|
||||
that returns a list of filter names, and a \c filterImage()
|
||||
function that applies a filter to an image.
|
||||
|
||||
\snippet plugandpaint/interfaces.h 4
|
||||
\snippet tools/plugandpaint/interfaces.h 4
|
||||
|
||||
To make it possible to query at run-time whether a plugin
|
||||
implements a given interface, we must use the \c
|
||||
@ -144,7 +144,7 @@
|
||||
\l{mainwindows/application}{Application}). Here, we'll
|
||||
concentrate on the parts of the code that are related to plugins.
|
||||
|
||||
\snippet plugandpaint/mainwindow.cpp 4
|
||||
\snippet tools/plugandpaint/mainwindow.cpp 4
|
||||
|
||||
The \c loadPlugins() function is called from the \c MainWindow
|
||||
constructor to detect plugins and update the \uicontrol{Brush},
|
||||
@ -155,7 +155,7 @@
|
||||
QObject. That QObject implements plugin interfaces using multiple
|
||||
inheritance.
|
||||
|
||||
\snippet plugandpaint/mainwindow.cpp 5
|
||||
\snippet tools/plugandpaint/mainwindow.cpp 5
|
||||
|
||||
The next step is to load dynamic plugins. We initialize the \c
|
||||
pluginsDir member variable to refer to the \c plugins
|
||||
@ -166,9 +166,9 @@
|
||||
this file is usually located in a subdirectory, so we need to
|
||||
take this into account.
|
||||
|
||||
\snippet plugandpaint/mainwindow.cpp 6
|
||||
\snippet plugandpaint/mainwindow.cpp 7
|
||||
\snippet plugandpaint/mainwindow.cpp 8
|
||||
\snippet tools/plugandpaint/mainwindow.cpp 6
|
||||
\snippet tools/plugandpaint/mainwindow.cpp 7
|
||||
\snippet tools/plugandpaint/mainwindow.cpp 8
|
||||
|
||||
We use QDir::entryList() to get a list of all files in that
|
||||
directory. Then we iterate over the result using \l foreach and
|
||||
@ -181,12 +181,12 @@
|
||||
|
||||
If QPluginLoader::instance() is non-null, we add it to the menus.
|
||||
|
||||
\snippet plugandpaint/mainwindow.cpp 9
|
||||
\snippet tools/plugandpaint/mainwindow.cpp 9
|
||||
|
||||
At the end, we enable or disable the \uicontrol{Brush}, \uicontrol{Shapes},
|
||||
and \uicontrol{Filters} menus based on whether they contain any items.
|
||||
|
||||
\snippet plugandpaint/mainwindow.cpp 10
|
||||
\snippet tools/plugandpaint/mainwindow.cpp 10
|
||||
|
||||
For each plugin (static or dynamic), we check which interfaces it
|
||||
implements using \l qobject_cast(). First, we try to cast the
|
||||
@ -195,7 +195,7 @@
|
||||
by \c brushes(). Then we do the same with the \c ShapeInterface
|
||||
and the \c FilterInterface.
|
||||
|
||||
\snippet plugandpaint/mainwindow.cpp 3
|
||||
\snippet tools/plugandpaint/mainwindow.cpp 3
|
||||
|
||||
The \c aboutPlugins() slot is called on startup and can be
|
||||
invoked at any time through the \uicontrol{About Plugins} action. It
|
||||
@ -211,7 +211,7 @@
|
||||
plugin from which it comes from as the parent; this makes it
|
||||
convenient to get access to the plugin later.
|
||||
|
||||
\snippet plugandpaint/mainwindow.cpp 0
|
||||
\snippet tools/plugandpaint/mainwindow.cpp 0
|
||||
|
||||
The \c changeBrush() slot is invoked when the user chooses one of
|
||||
the brushes from the \uicontrol{Brush} menu. We start by finding out
|
||||
@ -222,7 +222,7 @@
|
||||
identifying the brush. Next time the user draws on the paint
|
||||
area, \c PaintArea will use this brush.
|
||||
|
||||
\snippet plugandpaint/mainwindow.cpp 1
|
||||
\snippet tools/plugandpaint/mainwindow.cpp 1
|
||||
|
||||
The \c insertShape() is invoked when the use chooses one of the
|
||||
shapes from the \uicontrol{Shapes} menu. We retrieve the QAction that
|
||||
@ -230,7 +230,7 @@
|
||||
QAction, and finally we call \c ShapeInterface::generateShape()
|
||||
to obtain a QPainterPath.
|
||||
|
||||
\snippet plugandpaint/mainwindow.cpp 2
|
||||
\snippet tools/plugandpaint/mainwindow.cpp 2
|
||||
|
||||
The \c applyFilter() slot is similar: We retrieve the QAction
|
||||
that invoked the slot, then the \c FilterInterface associated to
|
||||
@ -243,12 +243,12 @@
|
||||
The \c PaintArea class contains some code that deals with \c
|
||||
BrushInterface, so we'll review it briefly.
|
||||
|
||||
\snippet plugandpaint/paintarea.cpp 0
|
||||
\snippet tools/plugandpaint/paintarea.cpp 0
|
||||
|
||||
In \c setBrush(), we simply store the \c BrushInterface and the
|
||||
brush that are given to us by \c MainWindow.
|
||||
|
||||
\snippet plugandpaint/paintarea.cpp 1
|
||||
\snippet tools/plugandpaint/paintarea.cpp 1
|
||||
|
||||
In the \l{QWidget::mouseMoveEvent()}{mouse move event handler},
|
||||
we call the \c BrushInterface::mouseMove() function on the
|
||||
@ -262,7 +262,7 @@
|
||||
and a list of plugin file names. It calls \c findPlugins()
|
||||
to fill the QTreeWdiget with information about the plugins:
|
||||
|
||||
\snippet plugandpaint/plugindialog.cpp 0
|
||||
\snippet tools/plugandpaint/plugindialog.cpp 0
|
||||
|
||||
The \c findPlugins() is very similar to \c
|
||||
MainWindow::loadPlugins(). It uses QPluginLoader to access the
|
||||
@ -270,7 +270,7 @@
|
||||
populateTreeWidget() uses \l qobject_cast() to find out which
|
||||
interfaces are implemented by the plugins:
|
||||
|
||||
\snippet plugandpaint/plugindialog.cpp 1
|
||||
\snippet tools/plugandpaint/plugindialog.cpp 1
|
||||
|
||||
\section1 Importing Static Plugins
|
||||
|
||||
@ -283,7 +283,7 @@
|
||||
For Plug & Paint, we have chosen to put Q_IMPORT_PLUGIN() in \c
|
||||
main.cpp:
|
||||
|
||||
\snippet plugandpaint/main.cpp 0
|
||||
\snippet tools/plugandpaint/main.cpp 0
|
||||
|
||||
The argument to Q_IMPORT_PLUGIN() is the plugin's name, as
|
||||
specified with Q_EXPORT_PLUGIN2() in the \l{Exporting the
|
||||
@ -292,7 +292,7 @@
|
||||
In the \c .pro file, we need to specify the static library.
|
||||
Here's the project file for building Plug & Paint:
|
||||
|
||||
\snippet plugandpaint/plugandpaint.pro 0
|
||||
\snippet tools/plugandpaint/plugandpaint.pro 0
|
||||
|
||||
The \c LIBS line variable specifies the library \c pnp_basictools
|
||||
located in the \c ../plugandpaintplugins/basictools directory.
|
||||
@ -311,7 +311,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\example plugandpaintplugins/basictools
|
||||
\example tools/plugandpaintplugins/basictools
|
||||
\title Plug & Paint Basic Tools Example
|
||||
|
||||
The Basic Tools example is a static plugin for the
|
||||
@ -329,7 +329,7 @@
|
||||
|
||||
\section1 Declaration of the Plugin Class
|
||||
|
||||
\snippet plugandpaintplugins/basicbasictoolsplugin.h 0
|
||||
\snippet tools/plugandpaintplugins/basictools/basictoolsplugin.h 0
|
||||
|
||||
We start by including \c interfaces.h, which defines the plugin
|
||||
interfaces for the \l{plugandpaint}{Plug & Paint}
|
||||
@ -346,7 +346,7 @@
|
||||
\l qobject_cast() in the \l{plugandpaint}{Plug & Paint}
|
||||
application to detect interfaces.
|
||||
|
||||
\snippet plugandpaintplugins/basicbasictoolsplugin.h 2
|
||||
\snippet tools/plugandpaintplugins/basictools/basictoolsplugin.h 2
|
||||
|
||||
In the \c public section of the class, we declare all the
|
||||
functions from the three interfaces.
|
||||
@ -356,23 +356,23 @@
|
||||
Let's now review the implementation of the \c BasicToolsPlugin
|
||||
member functions inherited from \c BrushInterface.
|
||||
|
||||
\snippet plugandpaintplugins/basicbasictoolsplugin.cpp 0
|
||||
\snippet tools/plugandpaintplugins/basictools/basictoolsplugin.cpp 0
|
||||
|
||||
The \c brushes() function returns a list of brushes provided by
|
||||
this plugin. We provide three brushes: \uicontrol{Pencil}, \uicontrol{Air
|
||||
Brush}, and \uicontrol{Random Letters}.
|
||||
|
||||
\snippet plugandpaintplugins/basicbasictoolsplugin.cpp 1
|
||||
\snippet tools/plugandpaintplugins/basictools/basictoolsplugin.cpp 1
|
||||
|
||||
On a mouse press event, we just call \c mouseMove() to draw the
|
||||
spot where the event occurred.
|
||||
|
||||
\snippet plugandpaintplugins/basicbasictoolsplugin.cpp 2
|
||||
\snippet tools/plugandpaintplugins/basictools/basictoolsplugin.cpp 2
|
||||
|
||||
In \c mouseMove(), we start by saving the state of the QPainter
|
||||
and we compute a few variables that we'll need later.
|
||||
|
||||
\snippet plugandpaintplugins/basicbasictoolsplugin.cpp 3
|
||||
\snippet tools/plugandpaintplugins/basictools/basictoolsplugin.cpp 3
|
||||
|
||||
Then comes the brush-dependent part of the code:
|
||||
|
||||
@ -394,14 +394,14 @@
|
||||
At the end, we restore the painter state to what it was upon
|
||||
entering the function and we return the bounding rectangle.
|
||||
|
||||
\snippet plugandpaintplugins/basicbasictoolsplugin.cpp 4
|
||||
\snippet tools/plugandpaintplugins/basictools/basictoolsplugin.cpp 4
|
||||
|
||||
When the user releases the mouse, we do nothing and return an
|
||||
empty QRect.
|
||||
|
||||
\section1 Implementation of the Shape Interface
|
||||
|
||||
\snippet plugandpaintplugins/basicbasictoolsplugin.cpp 5
|
||||
\snippet tools/plugandpaintplugins/basictools/basictoolsplugin.cpp 5
|
||||
|
||||
The plugin provides three shapes: \uicontrol{Circle}, \uicontrol{Star}, and
|
||||
\uicontrol{Text...}. The three dots after \uicontrol{Text} are there because
|
||||
@ -413,7 +413,7 @@
|
||||
distinguish between the internal shape name and the name used in
|
||||
the user interface.
|
||||
|
||||
\snippet plugandpaintplugins/basicbasictoolsplugin.cpp 6
|
||||
\snippet tools/plugandpaintplugins/basictools/basictoolsplugin.cpp 6
|
||||
|
||||
The \c generateShape() creates a QPainterPath for the specified
|
||||
shape. If the shape is \uicontrol{Text}, we pop up a QInputDialog to
|
||||
@ -421,12 +421,12 @@
|
||||
|
||||
\section1 Implementation of the Filter Interface
|
||||
|
||||
\snippet plugandpaintplugins/basicbasictoolsplugin.cpp 7
|
||||
\snippet tools/plugandpaintplugins/basictools/basictoolsplugin.cpp 7
|
||||
|
||||
The plugin provides three filters: \uicontrol{Invert Pixels}, \uicontrol{Swap
|
||||
RGB}, and \uicontrol{Grayscale}.
|
||||
|
||||
\snippet plugandpaintplugins/basicbasictoolsplugin.cpp 8
|
||||
\snippet tools/plugandpaintplugins/basictools/basictoolsplugin.cpp 8
|
||||
|
||||
The \c filterImage() function takes a filter name and a QImage as
|
||||
parameters and returns an altered QImage. The first thing we do
|
||||
@ -444,7 +444,7 @@
|
||||
Q_EXPORT_PLUGIN2() macro to specify which class provides the
|
||||
plugin:
|
||||
|
||||
\snippet plugandpaintplugins/basicbasictoolsplugin.cpp 9
|
||||
\snippet tools/plugandpaintplugins/basictools/basictoolsplugin.cpp 9
|
||||
|
||||
This line may appear in any \c .cpp file that is part of the
|
||||
plugin's source code.
|
||||
@ -453,7 +453,7 @@
|
||||
|
||||
Here's the project file for building the Basic Tools plugin:
|
||||
|
||||
\snippet plugandpaintplugins/basicbasictools.pro 0
|
||||
\snippet tools/plugandpaintplugins/basictools/basictools.pro 0
|
||||
|
||||
The \c .pro file differs from typical \c .pro files in many
|
||||
respects. First, it starts with a \c TEMPLATE entry specifying \c
|
||||
@ -489,7 +489,7 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\example plugandpaintplugins/extrafilters
|
||||
\example tools/plugandpaintplugins/extrafilters
|
||||
\title Plug & Paint Extra Filters Example
|
||||
|
||||
The Extra Filters example is a plugin for the
|
||||
@ -506,7 +506,7 @@
|
||||
|
||||
Here's the project file for building the Extra Filters plugin:
|
||||
|
||||
\snippet plugandpaintplugins/extrafilters/extrafilters.pro 0
|
||||
\snippet tools/plugandpaintplugins/extrafilters/extrafilters.pro 0
|
||||
|
||||
The \c .pro file differs from typical \c .pro files in many
|
||||
respects. First, it starts with a \c TEMPLATE entry specifying \c
|
@ -26,7 +26,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example regexp
|
||||
\example tools/regexp
|
||||
\title Regular Expressions Example
|
||||
|
||||
The Regular Expressions (RegExp) example shows how regular expressions in Qt are
|
@ -26,7 +26,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example settingseditor
|
||||
\example tools/settingseditor
|
||||
\title Settings Editor Example
|
||||
|
||||
The Settings Editor example shows how Qt's standard settings support is used in an
|
@ -26,7 +26,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example styleplugin
|
||||
\example tools/styleplugin
|
||||
\title Style Plugin Example
|
||||
|
||||
This example shows how to create a plugin that extends Qt with a new
|
||||
@ -73,7 +73,7 @@
|
||||
\c SimpleStylePlugin inherits QStylePlugin and is the plugin
|
||||
class.
|
||||
|
||||
\snippet styleplugin/plugin/simplestyleplugin.h 0
|
||||
\snippet tools/styleplugin/plugin/simplestyleplugin.h 0
|
||||
|
||||
\c keys() returns a list of style names that this plugin can
|
||||
create, while \c create() takes such a string and returns the
|
||||
@ -87,14 +87,14 @@
|
||||
|
||||
Here is the implementation of \c keys():
|
||||
|
||||
\snippet styleplugin/plugin/simplestyleplugin.cpp 0
|
||||
\snippet tools/styleplugin/plugin/simplestyleplugin.cpp 0
|
||||
|
||||
Since this plugin only supports one style, we return a QStringList
|
||||
with the class name of that style.
|
||||
|
||||
Here is the \c create() function:
|
||||
|
||||
\snippet styleplugin/plugin/simplestyleplugin.cpp 1
|
||||
\snippet tools/styleplugin/plugin/simplestyleplugin.cpp 1
|
||||
|
||||
Note that the key for style plugins are case insensitive.
|
||||
The case sensitivity varies from plugin to plugin, so you need to
|
||||
@ -102,7 +102,7 @@
|
||||
|
||||
\section1 The \c main() function
|
||||
|
||||
\snippet styleplugin/stylewindow/main.cpp 0
|
||||
\snippet tools/styleplugin/stylewindow/main.cpp 0
|
||||
|
||||
Qt loads the available style plugins when the QApplication object
|
||||
is initialized. The QStyleFactory class knows about all styles and
|
||||
@ -114,7 +114,7 @@
|
||||
The \c SimpleStylePlugin lives in its own directory and have
|
||||
its own profile:
|
||||
|
||||
\snippet styleplugin/plugin/plugin.pro 0
|
||||
\snippet tools/styleplugin/plugin/plugin.pro 0
|
||||
|
||||
In the plugin profile we need to set the lib template as we are
|
||||
building a shared library instead of an executable. We must also
|
@ -26,7 +26,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example treemodelcompleter
|
||||
\example tools/treemodelcompleter
|
||||
\title Tree Model Completer Example
|
||||
|
||||
The Tree Model Completer example shows how to provide completion
|
||||
@ -45,7 +45,7 @@
|
||||
This file is embedded within the \e treemodelcompleter.qrc resource file,
|
||||
which contains the following:
|
||||
|
||||
\quotefile treemodelcompleter/treemodelcompleter.qrc
|
||||
\quotefile tools/treemodelcompleter/treemodelcompleter.qrc
|
||||
|
||||
\section1 TreeModelCompleter Class Definition
|
||||
|
||||
@ -53,7 +53,7 @@
|
||||
constructors - one with \a parent as an argument and another with
|
||||
\a parent and \a model as arguments.
|
||||
|
||||
\snippet treemodelcompleter/treemodelcompleter.h 0
|
||||
\snippet tools/treemodelcompleter/treemodelcompleter.h 0
|
||||
|
||||
The class reimplements the protected functions
|
||||
\l{QCompleter::splitPath()}{splitPath()} and
|
||||
@ -72,14 +72,14 @@
|
||||
parent while the second constructor constructs an object with a parent
|
||||
and a QAbstractItemModel, \a model.
|
||||
|
||||
\snippet treemodelcompleter/treemodelcompleter.cpp 0
|
||||
\snippet tools/treemodelcompleter/treemodelcompleter.cpp 0
|
||||
\codeline
|
||||
\snippet treemodelcompleter/treemodelcompleter.cpp 1
|
||||
\snippet tools/treemodelcompleter/treemodelcompleter.cpp 1
|
||||
|
||||
The \c separator() function is a getter function that returns the
|
||||
separator string.
|
||||
|
||||
\snippet treemodelcompleter/treemodelcompleter.cpp 2
|
||||
\snippet tools/treemodelcompleter/treemodelcompleter.cpp 2
|
||||
|
||||
As mentioned earlier, the \c splitPath() function is reimplemented because
|
||||
the default implementation is more suited to QDirModel or list models. In
|
||||
@ -87,7 +87,7 @@
|
||||
matched at each level, we split it using QString::split() with \c sep as its
|
||||
separator.
|
||||
|
||||
\snippet treemodelcompleter/treemodelcompleter.cpp 3
|
||||
\snippet tools/treemodelcompleter/treemodelcompleter.cpp 3
|
||||
|
||||
The \c pathFromIndex() function returns data for the completionRole() for a
|
||||
tree model. This function is reimplemented as its default implementation is
|
||||
@ -97,7 +97,7 @@
|
||||
accumulate the data. The function then returns a QStringList, \c dataList,
|
||||
using a separator to join objects of different levels.
|
||||
|
||||
\snippet treemodelcompleter/treemodelcompleter.cpp 4
|
||||
\snippet tools/treemodelcompleter/treemodelcompleter.cpp 4
|
||||
|
||||
\section1 MainWindow Class Definition
|
||||
|
||||
@ -105,13 +105,13 @@
|
||||
custom slots: \c about(), \c changeCase(), \c changeMode(),
|
||||
\c highlight(), and \c updateContentsLabel().
|
||||
|
||||
\snippet treemodelcompleter/mainwindow.h 0
|
||||
\snippet tools/treemodelcompleter/mainwindow.h 0
|
||||
|
||||
In addition, the class has two private functions, \c createMenu() and
|
||||
\c modelFromFile(), as well as private instances of QTreeView, QComboBox,
|
||||
QLabel, \c TreeModelCompleter and QLineEdit.
|
||||
|
||||
\snippet treemodelcompleter/mainwindow.h 1
|
||||
\snippet tools/treemodelcompleter/mainwindow.h 1
|
||||
|
||||
\section1 MainWindow Class Implementation
|
||||
|
||||
@ -123,49 +123,49 @@
|
||||
{highlighted()} signal is connected to \c{MainWindow}'s \c highlight()
|
||||
slot.
|
||||
|
||||
\snippet treemodelcompleter/mainwindow.cpp 0
|
||||
\snippet tools/treemodelcompleter/mainwindow.cpp 0
|
||||
|
||||
The QLabel objects \c modelLabel, \c modeLabel and \c caseLabel are
|
||||
instantiated. Also, the QComboBox objects, \c modeCombo and \c caseCombo,
|
||||
are instantiated and populated. By default, the \c{completer}'s mode is
|
||||
"Filtered Popup" and the case is insensitive.
|
||||
|
||||
\snippet treemodelcompleter/mainwindow.cpp 1
|
||||
\snippet tools/treemodelcompleter/mainwindow.cpp 1
|
||||
\codeline
|
||||
\snippet treemodelcompleter/mainwindow.cpp 2
|
||||
\snippet tools/treemodelcompleter/mainwindow.cpp 2
|
||||
|
||||
We use a QGridLayout to place all the objects in the \c MainWindow.
|
||||
|
||||
\snippet treemodelcompleter/mainwindow.cpp 3
|
||||
\snippet tools/treemodelcompleter/mainwindow.cpp 3
|
||||
|
||||
The \c createMenu() function sets up the QAction objects required and
|
||||
adds them to the "File" menu and "Help" menu. The
|
||||
\l{QAction::triggered()}{triggered()} signals from these actions are
|
||||
connected to their respective slots.
|
||||
|
||||
\snippet treemodelcompleter/mainwindow.cpp 4
|
||||
\snippet tools/treemodelcompleter/mainwindow.cpp 4
|
||||
|
||||
The \c changeMode() function accepts an \a index corresponding to the
|
||||
user's choice of completion mode and changes the \c{completer}'s mode
|
||||
accordingly.
|
||||
|
||||
\snippet treemodelcompleter/mainwindow.cpp 5
|
||||
\snippet tools/treemodelcompleter/mainwindow.cpp 5
|
||||
|
||||
The \c about() function provides a brief description on the Tree Model
|
||||
Completer example.
|
||||
|
||||
\snippet treemodelcompleter/mainwindow.cpp 6
|
||||
\snippet tools/treemodelcompleter/mainwindow.cpp 6
|
||||
|
||||
The \c changeCase() function alternates between \l{Qt::CaseSensitive}
|
||||
{Case Sensitive} and \l{Qt::CaseInsensitive}{Case Insensitive} modes,
|
||||
depending on the value of \a cs.
|
||||
|
||||
\snippet treemodelcompleter/mainwindow.cpp 7
|
||||
\snippet tools/treemodelcompleter/mainwindow.cpp 7
|
||||
|
||||
\section1 \c main() Function
|
||||
|
||||
The \c main() function instantiates \c MainWindow and invokes the
|
||||
\l{QWidget::show()}{show()} function to display it.
|
||||
|
||||
\snippet treemodelcompleter/main.cpp 0
|
||||
\snippet tools/treemodelcompleter/main.cpp 0
|
||||
*/
|
@ -26,7 +26,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example undo
|
||||
\example tools/undo
|
||||
\title Undo Framework
|
||||
|
||||
This example shows Qt's undo framework in action.
|
@ -26,7 +26,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example undoframework
|
||||
\example tools/undoframework
|
||||
\title Undo Framework Example
|
||||
|
||||
This example shows how to implement undo/redo functionality
|
||||
@ -78,7 +78,7 @@
|
||||
|
||||
\section1 MainWindow Class Definition
|
||||
|
||||
\snippet undoframework/mainwindow.h 0
|
||||
\snippet tools/undoframework/mainwindow.h 0
|
||||
|
||||
The \c MainWindow class maintains the undo stack, i.e., it creates
|
||||
\l{QUndoCommand}s and pushes and pops them from the stack when it
|
||||
@ -89,13 +89,13 @@
|
||||
|
||||
We will start with a look at the constructor:
|
||||
|
||||
\snippet undoframework/mainwindow.cpp 0
|
||||
\snippet tools/undoframework/mainwindow.cpp 0
|
||||
|
||||
In the constructor, we set up the DiagramScene and QGraphicsView.
|
||||
|
||||
Here is the \c createUndoView() function:
|
||||
|
||||
\snippet undoframework/mainwindow.cpp 1
|
||||
\snippet tools/undoframework/mainwindow.cpp 1
|
||||
|
||||
The QUndoView is a widget that display the text, which is set with
|
||||
the \l{QUndoCommand::}{setText()} function, for each QUndoCommand
|
||||
@ -103,11 +103,11 @@
|
||||
|
||||
Here is the \c createActions() function:
|
||||
|
||||
\snippet undoframework/mainwindow.cpp 2
|
||||
\snippet tools/undoframework/mainwindow.cpp 2
|
||||
\codeline
|
||||
\snippet undoframework/mainwindow.cpp 3
|
||||
\snippet tools/undoframework/mainwindow.cpp 3
|
||||
\dots
|
||||
\snippet undoframework/mainwindow.cpp 5
|
||||
\snippet tools/undoframework/mainwindow.cpp 5
|
||||
|
||||
The \c createActions() function sets up all the examples actions
|
||||
in the manner shown above. The
|
||||
@ -120,12 +120,12 @@
|
||||
|
||||
Here is the \c createMenus() function:
|
||||
|
||||
\snippet undoframework/mainwindow.cpp 6
|
||||
\snippet tools/undoframework/mainwindow.cpp 6
|
||||
|
||||
\dots
|
||||
\snippet undoframework/mainwindow.cpp 7
|
||||
\snippet tools/undoframework/mainwindow.cpp 7
|
||||
\dots
|
||||
\snippet undoframework/mainwindow.cpp 8
|
||||
\snippet tools/undoframework/mainwindow.cpp 8
|
||||
|
||||
We have to use the QMenu \c aboutToShow() and \c aboutToHide()
|
||||
signals since we only want \c deleteAction to be enabled when we
|
||||
@ -133,14 +133,14 @@
|
||||
|
||||
Here is the \c itemMoved() slot:
|
||||
|
||||
\snippet undoframework/mainwindow.cpp 9
|
||||
\snippet tools/undoframework/mainwindow.cpp 9
|
||||
|
||||
We simply push a MoveCommand on the stack, which calls \c redo()
|
||||
on it.
|
||||
|
||||
Here is the \c deleteItem() slot:
|
||||
|
||||
\snippet undoframework/mainwindow.cpp 10
|
||||
\snippet tools/undoframework/mainwindow.cpp 10
|
||||
|
||||
An item must be selected to be deleted. We need to check if it is
|
||||
selected as the \c deleteAction may be enabled even if an item is
|
||||
@ -149,9 +149,9 @@
|
||||
|
||||
Here is the \c itemMenuAboutToShow() and itemMenuAboutToHide() slots:
|
||||
|
||||
\snippet undoframework/mainwindow.cpp 11
|
||||
\snippet tools/undoframework/mainwindow.cpp 11
|
||||
\codeline
|
||||
\snippet undoframework/mainwindow.cpp 12
|
||||
\snippet tools/undoframework/mainwindow.cpp 12
|
||||
|
||||
We implement \c itemMenuAboutToShow() and \c itemMenuAboutToHide()
|
||||
to get a dynamic item menu. These slots are connected to the
|
||||
@ -160,28 +160,28 @@
|
||||
|
||||
Here is the \c addBox() slot:
|
||||
|
||||
\snippet undoframework/mainwindow.cpp 13
|
||||
\snippet tools/undoframework/mainwindow.cpp 13
|
||||
|
||||
The \c addBox() function creates an AddCommand and pushes it on
|
||||
the undo stack.
|
||||
|
||||
Here is the \c addTriangle() sot:
|
||||
|
||||
\snippet undoframework/mainwindow.cpp 14
|
||||
\snippet tools/undoframework/mainwindow.cpp 14
|
||||
|
||||
The \c addTriangle() function creates an AddCommand and pushes it
|
||||
on the undo stack.
|
||||
|
||||
Here is the implementation of \c about():
|
||||
|
||||
\snippet undoframework/mainwindow.cpp 15
|
||||
\snippet tools/undoframework/mainwindow.cpp 15
|
||||
|
||||
The about slot is triggered by the \c aboutAction and displays an
|
||||
about box for the example.
|
||||
|
||||
\section1 AddCommand Class Definition
|
||||
|
||||
\snippet undoframework/commands.h 2
|
||||
\snippet tools/undoframework/commands.h 2
|
||||
|
||||
The \c AddCommand class adds DiagramItem graphics items to the
|
||||
DiagramScene.
|
||||
@ -190,32 +190,32 @@
|
||||
|
||||
We start with the constructor:
|
||||
|
||||
\snippet undoframework/commands.cpp 7
|
||||
\snippet tools/undoframework/commands.cpp 7
|
||||
|
||||
We first create the DiagramItem to add to the DiagramScene. The
|
||||
\l{QUndoCommand::}{setText()} function let us set a QString that
|
||||
describes the command. We use this to get custom messages in the
|
||||
QUndoView and in the menu of the main window.
|
||||
|
||||
\snippet undoframework/commands.cpp 8
|
||||
\snippet tools/undoframework/commands.cpp 8
|
||||
|
||||
\c undo() removes the item from the scene.
|
||||
|
||||
\snippet undoframework/commands.cpp 9
|
||||
\snippet tools/undoframework/commands.cpp 9
|
||||
|
||||
We set the position of the item as we do not do this in the
|
||||
constructor.
|
||||
|
||||
\section1 DeleteCommand Class Definition
|
||||
|
||||
\snippet undoframework/commands.h 1
|
||||
\snippet tools/undoframework/commands.h 1
|
||||
|
||||
The DeleteCommand class implements the functionality to remove an
|
||||
item from the scene.
|
||||
|
||||
\section1 DeleteCommand Class Implementation
|
||||
|
||||
\snippet undoframework/commands.cpp 4
|
||||
\snippet tools/undoframework/commands.cpp 4
|
||||
|
||||
We know that there must be one selected item as it is not possible
|
||||
to create a DeleteCommand unless the item to be deleted is
|
||||
@ -223,17 +223,17 @@
|
||||
The item must be unselected if it is inserted back into the
|
||||
scene.
|
||||
|
||||
\snippet undoframework/commands.cpp 5
|
||||
\snippet tools/undoframework/commands.cpp 5
|
||||
|
||||
The item is simply reinserted into the scene.
|
||||
|
||||
\snippet undoframework/commands.cpp 6
|
||||
\snippet tools/undoframework/commands.cpp 6
|
||||
|
||||
The item is removed from the scene.
|
||||
|
||||
\section1 MoveCommand Class Definition
|
||||
|
||||
\snippet undoframework/commands.h 0
|
||||
\snippet tools/undoframework/commands.h 0
|
||||
|
||||
The \l{QUndoCommand::}{mergeWith()} is reimplemented to make
|
||||
consecutive moves of an item one MoveCommand, i.e, the item will
|
||||
@ -244,20 +244,20 @@
|
||||
|
||||
The constructor of MoveCommand looks like this:
|
||||
|
||||
\snippet undoframework/commands.cpp 0
|
||||
\snippet tools/undoframework/commands.cpp 0
|
||||
|
||||
We save both the old and new positions for undo and redo
|
||||
respectively.
|
||||
|
||||
\snippet undoframework/commands.cpp 2
|
||||
\snippet tools/undoframework/commands.cpp 2
|
||||
|
||||
We simply set the items old position and update the scene.
|
||||
|
||||
\snippet undoframework/commands.cpp 3
|
||||
\snippet tools/undoframework/commands.cpp 3
|
||||
|
||||
We set the item to its new position.
|
||||
|
||||
\snippet undoframework/commands.cpp 1
|
||||
\snippet tools/undoframework/commands.cpp 1
|
||||
|
||||
Whenever a MoveCommand is created, this function is called to
|
||||
check if it should be merged with the previous command. It is the
|
||||
@ -271,7 +271,7 @@
|
||||
|
||||
\section1 DiagramScene Class Definition
|
||||
|
||||
\snippet undoframework/diagramscene.h 0
|
||||
\snippet tools/undoframework/diagramscene.h 0
|
||||
|
||||
The DiagramScene implements the functionality to move a
|
||||
DiagramItem with the mouse. It emits a signal when a move is
|
||||
@ -283,7 +283,7 @@
|
||||
|
||||
The \c main() function of the program looks like this:
|
||||
|
||||
\snippet undoframework/main.cpp 0
|
||||
\snippet tools/undoframework/main.cpp 0
|
||||
|
||||
We draw a grid in the background of the DiagramScene, so we use a
|
||||
resource file. The rest of the function creates the \c MainWindow and
|