mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
Title block template editor: implemented paste operation
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1560 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -848,3 +848,78 @@ void ChangeTemplateInformationsCommand::undo() {
|
|||||||
void ChangeTemplateInformationsCommand::redo() {
|
void ChangeTemplateInformationsCommand::redo() {
|
||||||
tbtemplate_ -> setInformation(new_information_);
|
tbtemplate_ -> setInformation(new_information_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructor
|
||||||
|
@param tb_template Changed title block template
|
||||||
|
@param parent Parent command
|
||||||
|
*/
|
||||||
|
PasteTemplateCellsCommand::PasteTemplateCellsCommand(TitleBlockTemplate *tb_template, QUndoCommand *parent) :
|
||||||
|
TitleBlockTemplateCommand(tb_template, parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Destructor
|
||||||
|
*/
|
||||||
|
PasteTemplateCellsCommand::~PasteTemplateCellsCommand() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Update the label describing this command
|
||||||
|
*/
|
||||||
|
void PasteTemplateCellsCommand::updateText() {
|
||||||
|
setText(QObject::tr("Coller %n cellule(s)", "undo caption", erased_cells_.count()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Undo a paste action.
|
||||||
|
*/
|
||||||
|
void PasteTemplateCellsCommand::undo() {
|
||||||
|
foreach (TitleBlockCell *cell, erased_cells_.keys()) {
|
||||||
|
cell -> loadContentFromCell(erased_cells_.value(cell));
|
||||||
|
}
|
||||||
|
if (view_) {
|
||||||
|
view_ -> refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Redo a paste action.
|
||||||
|
*/
|
||||||
|
void PasteTemplateCellsCommand::redo() {
|
||||||
|
// paste the first cell ony
|
||||||
|
foreach (TitleBlockCell *cell, erased_cells_.keys()) {
|
||||||
|
cell -> loadContentFromCell(pasted_cells_.value(cell));
|
||||||
|
}
|
||||||
|
if (view_) {
|
||||||
|
view_ -> refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@param cell Pointer to the cell impacted by te paste operation
|
||||||
|
@param new_cell_content Content pasted to the cell
|
||||||
|
*/
|
||||||
|
void PasteTemplateCellsCommand::addPastedCell(TitleBlockCell *cell, const TitleBlockCell &new_cell_content) {
|
||||||
|
pasted_cells_.insert(cell, new_cell_content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@param cell Pointer to the cell impacted by te paste operation
|
||||||
|
@param former_cell_content Content of the cell before the paste operation
|
||||||
|
*/
|
||||||
|
void PasteTemplateCellsCommand::addErasedCell(TitleBlockCell *cell, const TitleBlockCell &former_cell_content) {
|
||||||
|
erased_cells_.insert(cell, former_cell_content);
|
||||||
|
updateText();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
This is a convenience function equivalent to:
|
||||||
|
addErasedCell(cell, before)
|
||||||
|
addPastedCell(cell, after)
|
||||||
|
*/
|
||||||
|
void PasteTemplateCellsCommand::addCell(TitleBlockCell *cell, const TitleBlockCell &before, const TitleBlockCell &after) {
|
||||||
|
addPastedCell(cell, after);
|
||||||
|
addErasedCell(cell, before);
|
||||||
|
}
|
||||||
|
|||||||
@@ -250,4 +250,34 @@ class ChangeTemplateInformationsCommand : public QUndoCommand {
|
|||||||
/// Informations after they were modified
|
/// Informations after they were modified
|
||||||
QString new_information_;
|
QString new_information_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
This class represents the action of pasting a cells set.
|
||||||
|
*/
|
||||||
|
class PasteTemplateCellsCommand : public TitleBlockTemplateCommand {
|
||||||
|
// constructors, destructor
|
||||||
|
public:
|
||||||
|
PasteTemplateCellsCommand(TitleBlockTemplate *, QUndoCommand * = 0);
|
||||||
|
virtual ~PasteTemplateCellsCommand();
|
||||||
|
private:
|
||||||
|
PasteTemplateCellsCommand(const PasteTemplateCellsCommand &);
|
||||||
|
|
||||||
|
// methods
|
||||||
|
public:
|
||||||
|
virtual void undo();
|
||||||
|
virtual void redo();
|
||||||
|
virtual void addPastedCell(TitleBlockCell *, const TitleBlockCell &);
|
||||||
|
virtual void addErasedCell(TitleBlockCell *, const TitleBlockCell &);
|
||||||
|
virtual void addCell(TitleBlockCell *, const TitleBlockCell &, const TitleBlockCell &);
|
||||||
|
protected:
|
||||||
|
virtual void updateText();
|
||||||
|
|
||||||
|
// attributes
|
||||||
|
public:
|
||||||
|
/// Pasted cells
|
||||||
|
QHash<TitleBlockCell *, TitleBlockCell> pasted_cells_;
|
||||||
|
/// Existing cells impacted by the paste operation
|
||||||
|
QHash<TitleBlockCell *, TitleBlockCell> erased_cells_;
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -159,7 +159,44 @@ void TitleBlockTemplateView::copy() {
|
|||||||
Import the cells described in the clipboard.
|
Import the cells described in the clipboard.
|
||||||
*/
|
*/
|
||||||
void TitleBlockTemplateView::paste() {
|
void TitleBlockTemplateView::paste() {
|
||||||
/// TODO
|
// retrieve the clipboard content and parse it as XML
|
||||||
|
QClipboard *clipboard = QApplication::clipboard();
|
||||||
|
QDomDocument xml_import;
|
||||||
|
|
||||||
|
if (!xml_import.setContent(clipboard -> text().trimmed())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure the XML document describes cells that can be pasted
|
||||||
|
if (xml_import.documentElement().tagName() != "titleblocktemplate-partial") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// load pasted cells
|
||||||
|
QList<TitleBlockCell> pasted_cells;
|
||||||
|
QDomElement paste_root = xml_import.documentElement();
|
||||||
|
for (QDomElement e = paste_root.firstChildElement() ; !e.isNull() ; e = e.nextSiblingElement()) {
|
||||||
|
if (e.tagName() == "empty" || e.tagName() == "field" || e.tagName() == "logo") {
|
||||||
|
TitleBlockCell cell;
|
||||||
|
cell.loadContentFromXml(e);
|
||||||
|
pasted_cells << cell;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// paste the first cell only
|
||||||
|
if (!pasted_cells.count()) return;
|
||||||
|
|
||||||
|
// onto the first selected one
|
||||||
|
TitleBlockTemplateVisualCell *selected_cell = selectedCellsSet().topLeftCell();
|
||||||
|
if (!selected_cell) return;
|
||||||
|
|
||||||
|
TitleBlockCell *erased_cell = selected_cell -> cell();
|
||||||
|
if (!erased_cell) return;
|
||||||
|
|
||||||
|
PasteTemplateCellsCommand *paste_command = new PasteTemplateCellsCommand(tbtemplate_);
|
||||||
|
paste_command -> addCell(erased_cell, *erased_cell, pasted_cells.first());
|
||||||
|
requestGridModification(paste_command);
|
||||||
|
/// TODO paste more cells, using some kind of heuristic to place them?
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user