~ubuntu-branches/debian/sid/kexi/sid

« back to all changes in this revision

Viewing changes to src/formeditor/commands.h

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2017-06-24 20:10:10 UTC
  • Revision ID: package-import@ubuntu.com-20170624201010-5lrzd5r2vwthwifp
Tags: upstream-3.0.1.1
ImportĀ upstreamĀ versionĀ 3.0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
 
3
   Copyright (C) 2005-2010 Jarosław Staniek <staniek@kde.org>
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library General Public
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2 of the License, or (at your option) any later version.
 
9
 
 
10
   This library is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public License
 
16
   along with this library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#ifndef KFORMEDITOR_COMMANDS_H
 
22
#define KFORMEDITOR_COMMANDS_H
 
23
 
 
24
#include "kformdesigner_export.h"
 
25
#include "utils.h"
 
26
#include "objecttree.h"
 
27
#include "form.h"
 
28
 
 
29
#include <QHash>
 
30
#include <QVariant>
 
31
 
 
32
#include <kundo2command.h>
 
33
 
 
34
#include <QDebug>
 
35
 
 
36
class QPoint;
 
37
class QStringList;
 
38
class QDomElement;
 
39
 
 
40
namespace KFormDesigner
 
41
{
 
42
 
 
43
class ObjectTreeItem;
 
44
class Container;
 
45
class Form;
 
46
 
 
47
//! Base class for KFormDesigner's commands
 
48
class KFORMDESIGNER_EXPORT Command : public KUndo2Command
 
49
{
 
50
public:
 
51
    explicit Command(Command *parent = 0);
 
52
 
 
53
    explicit Command(const QString &text, Command *parent = 0);
 
54
 
 
55
    virtual ~Command();
 
56
 
 
57
    //! Reimplemented to support effect of blockRedoOnce().
 
58
    virtual void redo();
 
59
 
 
60
    //! Implement instead of redo().
 
61
    virtual void execute() = 0;
 
62
 
 
63
    virtual void debug() const;
 
64
 
 
65
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const Command &c);
 
66
protected:
 
67
    //! Used to block execution of redo() once, on adding the command to the stack.
 
68
    void blockRedoOnce();
 
69
 
 
70
    friend class Form;
 
71
    bool m_blockRedoOnce; //!< Used to block redo() once
 
72
};
 
73
 
 
74
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
75
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const Command &c);
 
76
 
 
77
//! Command is used when changing a property for one or more widgets.
 
78
class KFORMDESIGNER_EXPORT PropertyCommand : public Command
 
79
{
 
80
public:
 
81
   /*! @a oldValue is the old property value for selected widget.
 
82
     This enables reverting the change. @a value is the new property value. */
 
83
    PropertyCommand(Form& form, const QByteArray &wname, const QVariant &oldValue,
 
84
                    const QVariant &value, const QByteArray &propertyName, Command *parent = 0);
 
85
 
 
86
   /*! @a oldValues is a QHash of the old property values for every widget,
 
87
     to allow reverting the change. @a value is the new property value.
 
88
     You can use the simpler constructor for a single widget. */
 
89
    PropertyCommand(Form& form, const QHash<QByteArray, QVariant> &oldValues,
 
90
                    const QVariant &value, const QByteArray &propertyName, Command *parent = 0);
 
91
 
 
92
    virtual ~PropertyCommand();
 
93
 
 
94
    Form* form() const;
 
95
 
 
96
    virtual int id() const;
 
97
 
 
98
    void setUniqueId(int id);
 
99
 
 
100
    virtual void execute();
 
101
 
 
102
    virtual void undo();
 
103
 
 
104
    bool mergeWith(const KUndo2Command * command);
 
105
 
 
106
    QByteArray propertyName() const;
 
107
 
 
108
    QVariant value() const;
 
109
 
 
110
    void setValue(const QVariant &value);
 
111
 
 
112
    const QHash<QByteArray, QVariant>& oldValues() const;
 
113
 
 
114
    //! @return old value if there is single value, otherwise null value.
 
115
    QVariant oldValue() const;
 
116
 
 
117
    //! @return widget name in case when there is only one widget
 
118
    //! with changed property in this command
 
119
    /*! Otherwise empty value is returned. */
 
120
    QByteArray widgetName() const;
 
121
 
 
122
    virtual void debug() const;
 
123
 
 
124
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const PropertyCommand &c);
 
125
protected:
 
126
    void init();
 
127
    class Private;
 
128
    Private * const d;
 
129
};
 
130
 
 
131
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
132
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const PropertyCommand &c);
 
133
 
 
134
//! Command used when moving multiples widgets at the same time, while holding Ctrl or Shift.
 
135
/*! You need to supply a list of widget names, and the position of the cursor before moving. Use setPos()
 
136
  to tell the new cursor pos every time it changes.*/
 
137
class KFORMDESIGNER_EXPORT GeometryPropertyCommand : public Command
 
138
{
 
139
public:
 
140
    GeometryPropertyCommand(Form& form, const QStringList &names,
 
141
                            const QPoint& oldPos, Command *parent = 0);
 
142
 
 
143
    virtual ~GeometryPropertyCommand();
 
144
 
 
145
    virtual int id() const;
 
146
 
 
147
    virtual void execute();
 
148
 
 
149
    virtual void undo();
 
150
 
 
151
    void setPos(const QPoint& pos);
 
152
 
 
153
    QPoint pos() const;
 
154
 
 
155
    QPoint oldPos() const;
 
156
 
 
157
    virtual void debug() const;
 
158
 
 
159
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const GeometryPropertyCommand &c);
 
160
protected:
 
161
    class Private;
 
162
    Private * const d;
 
163
};
 
164
 
 
165
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
166
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const GeometryPropertyCommand &c);
 
167
 
 
168
//! Command used when an "Align Widgets position" action is activated.
 
169
/* You just need to give the list of widget names (the selected ones), and the
 
170
  type of alignment (see the enum for possible values). */
 
171
class KFORMDESIGNER_EXPORT AlignWidgetsCommand : public Command
 
172
{
 
173
public:
 
174
    AlignWidgetsCommand(Form &form, Form::WidgetAlignment alignment, const QWidgetList &list,
 
175
                        Command *parent = 0);
 
176
 
 
177
    virtual ~AlignWidgetsCommand();
 
178
 
 
179
    virtual int id() const;
 
180
 
 
181
    virtual void execute();
 
182
 
 
183
    virtual void undo();
 
184
 
 
185
    virtual void debug() const;
 
186
 
 
187
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const AlignWidgetsCommand &c);
 
188
protected:
 
189
    class Private;
 
190
    Private * const d;
 
191
};
 
192
 
 
193
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
194
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const AlignWidgetsCommand &c);
 
195
 
 
196
//! Command used when an "Adjust Widgets Size" action is activated.
 
197
/*! You just need to give the list of widget names (the selected ones),
 
198
    and the type of size modification (see the enum for possible values). */
 
199
class KFORMDESIGNER_EXPORT AdjustSizeCommand : public Command
 
200
{
 
201
public:
 
202
    enum Adjustment {
 
203
        SizeToGrid,
 
204
        SizeToFit,
 
205
        SizeToSmallWidth,
 
206
        SizeToBigWidth,
 
207
        SizeToSmallHeight,
 
208
        SizeToBigHeight
 
209
    };
 
210
 
 
211
    AdjustSizeCommand(Form& form, Adjustment type, const QWidgetList &list, Command *parent = 0);
 
212
 
 
213
    virtual ~AdjustSizeCommand();
 
214
 
 
215
    virtual int id() const;
 
216
 
 
217
    virtual void execute();
 
218
 
 
219
    virtual void undo();
 
220
 
 
221
    virtual void debug() const;
 
222
 
 
223
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const AdjustSizeCommand &c);
 
224
protected:
 
225
    QSize getSizeFromChildren(ObjectTreeItem *item);
 
226
 
 
227
protected:
 
228
    class Private;
 
229
    Private * const d;
 
230
};
 
231
 
 
232
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
233
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const AdjustSizeCommand &c);
 
234
 
 
235
//! Command used when switching the layout of a container.
 
236
/*! It remembers the old pos of every widget inside the container. */
 
237
class KFORMDESIGNER_EXPORT LayoutPropertyCommand : public PropertyCommand
 
238
{
 
239
public:
 
240
    LayoutPropertyCommand(Form& form, const QByteArray &wname,
 
241
                          const QVariant &oldValue, const QVariant &value,
 
242
                          Command *parent = 0);
 
243
 
 
244
    virtual ~LayoutPropertyCommand();
 
245
 
 
246
    virtual int id() const;
 
247
 
 
248
    virtual void execute();
 
249
 
 
250
    virtual void undo();
 
251
 
 
252
    virtual void debug() const;
 
253
 
 
254
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const LayoutPropertyCommand &c);
 
255
protected:
 
256
    class Private;
 
257
    Private * const d;
 
258
};
 
259
 
 
260
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
261
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const LayoutPropertyCommand &c);
 
262
 
 
263
//! Command used when inserting a widget using toolbar or menu.
 
264
/*! You only have to give the parent Container and the widget pos.
 
265
 The other information is taken from the form. */
 
266
class KFORMDESIGNER_EXPORT InsertWidgetCommand : public Command
 
267
{
 
268
public:
 
269
    explicit InsertWidgetCommand(const Container& container, Command *parent = 0);
 
270
 
 
271
    /*! This ctor allows to set explicit class name and position.
 
272
     Used for dropping widgets on the form surface.
 
273
     If \a namePrefix is empty, widget's unique name is constructed using
 
274
     hint for \a className (WidgetLibrary::namePrefix()),
 
275
     otherwise, \a namePrefix is used to generate widget's name.
 
276
     This allows e.g. inserting a widgets having name constructed using
 
277
     */
 
278
    InsertWidgetCommand(const Container& container, const QByteArray& className,
 
279
                        const QPoint& pos, const QByteArray& namePrefix = QByteArray(),
 
280
                        Command *parent = 0);
 
281
 
 
282
    virtual ~InsertWidgetCommand();
 
283
 
 
284
    virtual int id() const;
 
285
 
 
286
    virtual void execute();
 
287
 
 
288
    virtual void undo();
 
289
 
 
290
    //! @return inserted widget's name
 
291
    QByteArray widgetName() const;
 
292
 
 
293
    virtual void debug() const;
 
294
 
 
295
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const InsertWidgetCommand &c);
 
296
protected:
 
297
    void init();
 
298
 
 
299
    class Private;
 
300
    Private * const d;
 
301
};
 
302
 
 
303
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
304
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const InsertWidgetCommand &c);
 
305
 
 
306
//! @todo add CopyWidgetCommand
 
307
 
 
308
//! Command used when pasting widgets.
 
309
/*! You need to give the QDomDocument containing
 
310
    the widget(s) to paste, and optionally the point where to paste widgets. */
 
311
class KFORMDESIGNER_EXPORT PasteWidgetCommand : public Command
 
312
{
 
313
public:
 
314
    PasteWidgetCommand(const QDomDocument &domDoc, const Container& container,
 
315
                       const QPoint& p = QPoint(), Command *parent = 0);
 
316
 
 
317
    virtual ~PasteWidgetCommand();
 
318
 
 
319
    virtual int id() const;
 
320
 
 
321
    virtual void execute();
 
322
 
 
323
    virtual void undo();
 
324
 
 
325
    virtual void debug() const;
 
326
 
 
327
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const PasteWidgetCommand &c);
 
328
 
 
329
protected:
 
330
    /*! Internal function used to change the coordinates of a widget to \a newPos
 
331
     before pasting it (to paste it at the position of the contextual menu). It modifies
 
332
       the "geometry" property of the QDomElement representing the widget. */
 
333
    void changePos(QDomElement &el, const QPoint &newPos);
 
334
 
 
335
    /*! Internal function used to fix the coordinates of a widget before pasting it
 
336
       (to avoid having two widgets at the same position). It moves the widget by
 
337
       (10, 10) increment (several times if there are already pasted widgets at this position). */
 
338
    void fixPos(QDomElement &el, Container *container);
 
339
 
 
340
    void moveWidgetBy(QDomElement &el, Container *container, const QPoint &p);
 
341
 
 
342
    /*! Internal function used to fix the names of the widgets before pasting them.
 
343
      It prevents from pasting a widget with
 
344
      the same name as an actual widget. The child widgets are also fixed recursively.\n
 
345
      If the name of the widget ends with a number (eg "QLineEdit1"), the new name is
 
346
      just incremented by one (eg becomes "QLineEdit2"). Otherwise, a "2" is just
 
347
      appended at the end of the name (eg "myWidget" becomes "myWidget2"). */
 
348
    void fixNames(QDomElement &el);
 
349
 
 
350
protected:
 
351
    class Private;
 
352
    Private * const d;
 
353
};
 
354
 
 
355
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
356
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const PasteWidgetCommand &c);
 
357
 
 
358
//! Command used when deleting widgets using the "Delete" menu item.
 
359
/*! You need to give a QWidgetList of the selected widgets. */
 
360
class KFORMDESIGNER_EXPORT DeleteWidgetCommand : public Command
 
361
{
 
362
public:
 
363
    DeleteWidgetCommand(Form& form, const QWidgetList &list, Command *parent = 0);
 
364
 
 
365
    virtual ~DeleteWidgetCommand();
 
366
 
 
367
    virtual int id() const;
 
368
 
 
369
    virtual void execute();
 
370
 
 
371
    virtual void undo();
 
372
 
 
373
    virtual void debug() const;
 
374
 
 
375
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const DeleteWidgetCommand &c);
 
376
protected:
 
377
    class Private;
 
378
    Private * const d;
 
379
};
 
380
 
 
381
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
382
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const DeleteWidgetCommand &c);
 
383
 
 
384
//! Command used when duplicating widgets.
 
385
/*! You need to give a QWidgetList of the selected widgets. */
 
386
class KFORMDESIGNER_EXPORT DuplicateWidgetCommand : public Command
 
387
{
 
388
public:
 
389
    DuplicateWidgetCommand(const Container& container, const QWidgetList &list,
 
390
                           const QPoint& copyToPoint, Command *parent = 0);
 
391
 
 
392
    virtual ~DuplicateWidgetCommand();
 
393
 
 
394
    virtual int id() const;
 
395
 
 
396
    virtual void execute();
 
397
 
 
398
    virtual void undo();
 
399
 
 
400
    virtual void debug() const;
 
401
 
 
402
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const DuplicateWidgetCommand &c);
 
403
protected:
 
404
    class Private;
 
405
    Private * const d;
 
406
};
 
407
 
 
408
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
409
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const DuplicateWidgetCommand &c);
 
410
 
 
411
//! Command used when cutting widgets.
 
412
/*! It is basically a DeleteWidgetCommand which also updates the clipboard contents. */
 
413
class KFORMDESIGNER_EXPORT CutWidgetCommand : public DeleteWidgetCommand
 
414
{
 
415
public:
 
416
    CutWidgetCommand(Form &form, const QWidgetList &list, Command *parent = 0);
 
417
 
 
418
    virtual ~CutWidgetCommand();
 
419
 
 
420
    virtual int id() const;
 
421
 
 
422
    virtual void execute();
 
423
 
 
424
    virtual void undo();
 
425
 
 
426
    virtual void debug() const;
 
427
 
 
428
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const CutWidgetCommand &c);
 
429
protected:
 
430
    class Private;
 
431
    Private * const d2;
 
432
};
 
433
 
 
434
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
435
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const CutWidgetCommand &c);
 
436
 
 
437
//! Command that holds several PropertyCommand subcommands.
 
438
/*! It appears as one to the user and in the command history. */
 
439
class KFORMDESIGNER_EXPORT PropertyCommandGroup : public Command
 
440
{
 
441
public:
 
442
    explicit PropertyCommandGroup(const QString &text, Command *parent = 0);
 
443
 
 
444
    virtual ~PropertyCommandGroup();
 
445
 
 
446
    virtual int id() const;
 
447
 
 
448
    virtual void execute();
 
449
 
 
450
    virtual void debug() const;
 
451
 
 
452
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const PropertyCommandGroup &c);
 
453
protected:
 
454
    class Private;
 
455
    Private * const d;
 
456
};
 
457
 
 
458
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
459
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const PropertyCommandGroup &c);
 
460
 
 
461
//! Command is used when inline text is edited for a single widget.
 
462
class KFORMDESIGNER_EXPORT InlineTextEditingCommand : public Command
 
463
{
 
464
public:
 
465
   /*! @a oldValue is the old property value for selected widget.
 
466
     This enables reverting the change. @a value is the new property value. */
 
467
    InlineTextEditingCommand(
 
468
        Form& form, QWidget *widget, const QByteArray &editedWidgetClass,
 
469
        const QString &text, Command *parent = 0);
 
470
 
 
471
    virtual ~InlineTextEditingCommand();
 
472
 
 
473
    virtual int id() const;
 
474
 
 
475
    virtual bool mergeWith(const KUndo2Command * command);
 
476
 
 
477
    virtual void execute();
 
478
 
 
479
    virtual void debug() const;
 
480
 
 
481
    virtual void undo();
 
482
 
 
483
    Form* form() const;
 
484
 
 
485
    QString text() const;
 
486
 
 
487
    QString oldText() const;
 
488
 
 
489
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const InlineTextEditingCommand &c);
 
490
 
 
491
protected:
 
492
    class Private;
 
493
    Private * const d;
 
494
};
 
495
 
 
496
//! qDebug() stream operator. Writes command group @a c to the debug output in a nicely formatted way.
 
497
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const InlineTextEditingCommand &c);
 
498
 
 
499
class KFORMDESIGNER_EXPORT InsertPageCommand : public Command
 
500
{
 
501
public:
 
502
    InsertPageCommand(Container *container, QWidget *widget);
 
503
 
 
504
    virtual ~InsertPageCommand();
 
505
 
 
506
    virtual int id() const;
 
507
 
 
508
    virtual void execute();
 
509
 
 
510
    void execute(const QString& pageWidgetName, const QString& pageName, int pageIndex);
 
511
 
 
512
    virtual void debug() const;
 
513
 
 
514
    virtual void undo();
 
515
 
 
516
    void undo(const QString& name);
 
517
 
 
518
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const InsertPageCommand &c);
 
519
 
 
520
protected:
 
521
    class Private;
 
522
    Private * const d;
 
523
};
 
524
 
 
525
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
526
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const InsertPageCommand &c);
 
527
 
 
528
class KFORMDESIGNER_EXPORT RemovePageCommand : public Command
 
529
{
 
530
public:
 
531
    RemovePageCommand(Container *container, QWidget *widget);
 
532
 
 
533
    virtual ~RemovePageCommand();
 
534
 
 
535
    virtual int id() const;
 
536
 
 
537
    virtual void execute();
 
538
 
 
539
    virtual void debug() const;
 
540
 
 
541
    virtual void undo();
 
542
 
 
543
    int pageIndex() const;
 
544
 
 
545
    QString pageName() const;
 
546
 
 
547
    friend KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const RemovePageCommand &c);
 
548
 
 
549
protected:
 
550
    class Private;
 
551
    Private * const d;
 
552
};
 
553
 
 
554
//! qDebug() stream operator. Writes command @a c to the debug output in a nicely formatted way.
 
555
KFORMDESIGNER_EXPORT QDebug operator<<(QDebug dbg, const RemovePageCommand &c);
 
556
 
 
557
}
 
558
 
 
559
#endif