[qet] [1561] Title block template editor: implemented cut operation. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 1561
Author: xavier
Date: 2012-03-11 17:06:43 +0100 (Sun, 11 Mar 2012)
Log Message:
-----------
Title block template editor: implemented cut operation.
Modified Paths:
--------------
branches/0.3/sources/titleblock/templatecommands.cpp
branches/0.3/sources/titleblock/templatecommands.h
branches/0.3/sources/titleblock/templateview.cpp
branches/0.3/sources/titleblock/templateview.h
Modified: branches/0.3/sources/titleblock/templatecommands.cpp
===================================================================
--- branches/0.3/sources/titleblock/templatecommands.cpp 2012-03-11 16:06:40 UTC (rev 1560)
+++ branches/0.3/sources/titleblock/templatecommands.cpp 2012-03-11 16:06:43 UTC (rev 1561)
@@ -851,6 +851,59 @@
/**
Constructor
+*/
+CutTemplateCellsCommand::CutTemplateCellsCommand(TitleBlockTemplate *tb_template, QUndoCommand *parent) :
+ TitleBlockTemplateCommand(tb_template, parent)
+{
+}
+
+/**
+ Destructor
+*/
+CutTemplateCellsCommand::~CutTemplateCellsCommand() {
+}
+
+/**
+ Undo a cut operation
+*/
+void CutTemplateCellsCommand::undo() {
+ foreach (TitleBlockCell *cell, cut_cells_.keys()) {
+ cell -> cell_type = cut_cells_.value(cell);
+ }
+ if (view_) {
+ view_ -> refresh();
+ }
+}
+
+/**
+ Redo a cut operation
+*/
+void CutTemplateCellsCommand::redo() {
+ foreach (TitleBlockCell *cell, cut_cells_.keys()) {
+ cell -> cell_type = TitleBlockCell::EmptyCell;
+ }
+ if (view_) {
+ view_ -> refresh();
+ }
+}
+
+void CutTemplateCellsCommand::setCutCells(const QList<TitleBlockCell *> &cells) {
+ foreach (TitleBlockCell *cell, cells) {
+ cut_cells_.insert(cell, cell -> cell_type);
+ }
+ updateText();
+}
+
+/**
+ Update the label describing this command
+*/
+void CutTemplateCellsCommand::updateText() {
+ setText(QObject::tr("Couper %n cellule(s)", "undo caption", cut_cells_.count()));
+}
+
+
+/**
+ Constructor
@param tb_template Changed title block template
@param parent Parent command
*/
Modified: branches/0.3/sources/titleblock/templatecommands.h
===================================================================
--- branches/0.3/sources/titleblock/templatecommands.h 2012-03-11 16:06:40 UTC (rev 1560)
+++ branches/0.3/sources/titleblock/templatecommands.h 2012-03-11 16:06:43 UTC (rev 1561)
@@ -22,8 +22,8 @@
#include <QUndoCommand>
#include "dimension.h"
#include "templatecellsset.h"
+#include "titleblockcell.h"
class TitleBlockTemplateView;
-class TitleBlockCell;
class TitleBlockTemplate;
/**
@@ -251,6 +251,30 @@
QString new_information_;
};
+/**
+ This class represents the action of cutting a cells set.
+*/
+class CutTemplateCellsCommand : public TitleBlockTemplateCommand {
+ // constructors, destructor
+ public:
+ CutTemplateCellsCommand(TitleBlockTemplate *, QUndoCommand * = 0);
+ virtual ~CutTemplateCellsCommand();
+ private:
+ CutTemplateCellsCommand(const CutTemplateCellsCommand &);
+
+ // methods
+ public:
+ virtual void undo();
+ virtual void redo();
+ virtual void setCutCells(const QList<TitleBlockCell *> &);
+ protected:
+ virtual void updateText();
+
+ // attributes
+ public:
+ /// Cut cells
+ QHash<TitleBlockCell *, TitleBlockCell::TemplateCellType> cut_cells_;
+};
/**
This class represents the action of pasting a cells set.
Modified: branches/0.3/sources/titleblock/templateview.cpp
===================================================================
--- branches/0.3/sources/titleblock/templateview.cpp 2012-03-11 16:06:40 UTC (rev 1560)
+++ branches/0.3/sources/titleblock/templateview.cpp 2012-03-11 16:06:43 UTC (rev 1561)
@@ -133,26 +133,39 @@
/**
Export currently selected cells to the clipboard before setting them as
empty.
+ @return the list of cells copied to the clipboard
*/
-void TitleBlockTemplateView::cut() {
- /// TODO
+QList<TitleBlockCell *> TitleBlockTemplateView::cut() {
+ if (!tbtemplate_) return(QList<TitleBlockCell *>());
+ QList<TitleBlockCell *> copied_cells = copy();
+
+ if (!copied_cells.isEmpty()) {
+ CutTemplateCellsCommand *cut_command = new CutTemplateCellsCommand(tbtemplate_);
+ cut_command -> setCutCells(copied_cells);
+ requestGridModification(cut_command);
+ }
+ return(copied_cells);
}
/**
Export currently selected cells to the clipboard.
+ @return the list of cells copied to the clipboard
*/
-void TitleBlockTemplateView::copy() {
- if (!tbtemplate_) return;
+QList<TitleBlockCell *> TitleBlockTemplateView::copy() {
+ if (!tbtemplate_) return(QList<TitleBlockCell *>());
+ QList<TitleBlockCell *> copied_cells = selectedCells();
QDomDocument xml_export;
QDomElement tbtpartial = xml_export.createElement("titleblocktemplate-partial");
xml_export.appendChild(tbtpartial);
- foreach (TitleBlockCell *cell, selectedCells()) {
+ foreach (TitleBlockCell *cell, copied_cells) {
tbtemplate_ -> exportCellToXml(cell, tbtpartial);
}
QClipboard *clipboard = QApplication::clipboard();
clipboard -> setText(xml_export.toString());
+
+ return(copied_cells);
}
/**
Modified: branches/0.3/sources/titleblock/templateview.h
===================================================================
--- branches/0.3/sources/titleblock/templateview.h 2012-03-11 16:06:40 UTC (rev 1560)
+++ branches/0.3/sources/titleblock/templateview.h 2012-03-11 16:06:43 UTC (rev 1561)
@@ -58,8 +58,8 @@
void zoomOut();
void zoomFit();
void zoomReset();
- void cut();
- void copy();
+ QList<TitleBlockCell *> cut();
+ QList<TitleBlockCell *> copy();
void paste();
void addColumnBefore();
void addRowBefore();