[qet] [2432] adding diagram image have now an undo/redo comand |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2432
Author: blacksun
Date: 2013-08-16 17:21:23 +0200 (Fri, 16 Aug 2013)
Log Message:
-----------
adding diagram image have now an undo/redo comand
Modified Paths:
--------------
branches/0.4/sources/diagram.cpp
branches/0.4/sources/diagram.h
branches/0.4/sources/diagramcommands.cpp
branches/0.4/sources/diagramcommands.h
branches/0.4/sources/diagramview.cpp
Modified: branches/0.4/sources/diagram.cpp
===================================================================
--- branches/0.4/sources/diagram.cpp 2013-08-16 14:26:56 UTC (rev 2431)
+++ branches/0.4/sources/diagram.cpp 2013-08-16 15:21:23 UTC (rev 2432)
@@ -30,6 +30,7 @@
#include "ghostelement.h"
#include "independenttextitem.h"
#include "qetapp.h"
+#include "diagramimageitem.h"
const int Diagram::xGrid = 10;
const int Diagram::yGrid = 10;
@@ -707,6 +708,15 @@
);
}
+void Diagram::addDiagramImageItem(DiagramImageItem *dii) {
+ if (!dii || isReadOnly()) return;
+
+ //add image at diagram
+ if (dii -> scene() != this) {
+ addItem(dii);
+ }
+}
+
/**
Enleve un element du schema
@param element Element a enlever
Modified: branches/0.4/sources/diagram.h
===================================================================
--- branches/0.4/sources/diagram.h 2013-08-16 14:26:56 UTC (rev 2431)
+++ branches/0.4/sources/diagram.h 2013-08-16 15:21:23 UTC (rev 2432)
@@ -40,6 +40,7 @@
class QETProject;
class Terminal;
class ConductorTextItem;
+class DiagramImageItem;
/**
This class represents an electric diagram. It manages its various child
elements, conductors and texts and handles their graphic rendering.
@@ -134,6 +135,7 @@
void addElement(Element *);
void addConductor(Conductor *);
void addIndependentTextItem(IndependentTextItem *);
+ void addDiagramImageItem(DiagramImageItem *);
void removeElement(Element *);
void removeConductor(Conductor *);
Modified: branches/0.4/sources/diagramcommands.cpp
===================================================================
--- branches/0.4/sources/diagramcommands.cpp 2013-08-16 14:26:56 UTC (rev 2431)
+++ branches/0.4/sources/diagramcommands.cpp 2013-08-16 15:21:23 UTC (rev 2432)
@@ -25,6 +25,7 @@
#include "qgimanager.h"
#include "diagram.h"
#include "diagramtextitem.h"
+#include "diagramimageitem.h"
/**
Constructeur
@@ -98,6 +99,38 @@
/**
Constructeur
+ @param dia Schema auquel on ajoute une image
+ @param image Image ajoute
+ @param pos Position a laquelle l'image est ajoute
+ @param parent QUndoCommand parent
+ */
+AddImageCommand::AddImageCommand(Diagram *dia, DiagramImageItem *image, const QPointF &pos, QUndoCommand *parent):
+ QUndoCommand(QObject::tr("Ajouter une image", "undo caption"), parent),
+ imageitem(image),
+ diagram(dia),
+ position(pos)
+{
+ diagram -> qgiManager().manage(imageitem);
+}
+
+///Destructor
+AddImageCommand::~AddImageCommand() {
+ diagram -> qgiManager().release(imageitem);
+}
+
+///Annule l'ajout
+void AddImageCommand::undo() {
+ diagram -> removeItem(imageitem);
+}
+
+///Refait l'ajout
+void AddImageCommand::redo() {
+ diagram -> addDiagramImageItem(imageitem);
+ imageitem -> setPos(position);
+}
+
+/**
+ Constructeur
@param d Schema auquel on ajoute un conducteur
@param c Conducteur ajoute
@param parent QUndoCommand parent
Modified: branches/0.4/sources/diagramcommands.h
===================================================================
--- branches/0.4/sources/diagramcommands.h 2013-08-16 14:26:56 UTC (rev 2431)
+++ branches/0.4/sources/diagramcommands.h 2013-08-16 15:21:23 UTC (rev 2432)
@@ -29,6 +29,7 @@
class Element;
class ElementTextItem;
class IndependentTextItem;
+class DiagramImageItem;
/**
This command adds an element to a particular diagram.
@@ -84,6 +85,33 @@
};
/**
+ This command adds an image item to a particular diagram
+*/
+class AddImageCommand : public QUndoCommand {
+ //constructors, destructor
+ public:
+ AddImageCommand (Diagram *, DiagramImageItem *, const QPointF &, QUndoCommand * = 0);
+ virtual ~AddImageCommand();
+ private:
+ AddImageCommand(const AddImageCommand &);
+
+ //methods
+ public:
+ virtual void undo();
+ virtual void redo();
+
+ // attributes
+ private:
+ /// added image item
+ DiagramImageItem *imageitem;
+ /// diagram the image item is added to
+ Diagram *diagram;
+ /// position of the image item on the diagram
+ QPointF position;
+
+};
+
+/**
This command adds a conductor to a particular diagram.
*/
class AddConductorCommand : public QUndoCommand {
Modified: branches/0.4/sources/diagramview.cpp
===================================================================
--- branches/0.4/sources/diagramview.cpp 2013-08-16 14:26:56 UTC (rev 2431)
+++ branches/0.4/sources/diagramview.cpp 2013-08-16 15:21:23 UTC (rev 2432)
@@ -428,8 +428,8 @@
is_adding_text = false;
}
if (is_adding_image && e -> buttons() == Qt::LeftButton) {
- addDiagramImageAtPos(mapToScene(e -> pos()));
- is_adding_image = false;
+ addDiagramImageAtPos(mapToScene(e -> pos()));
+ is_adding_image = false;
}
}
// workaround for drag view with hold wheel click and drag mouse
@@ -1241,7 +1241,6 @@
*/
void DiagramView::addImage() {
if (scene -> isReadOnly()) return;
- is_adding_image = true;
QString pathPictures = QDesktopServices::storageLocation ( QDesktopServices::PicturesLocation );
QString fileName = QFileDialog::getOpenFileName(this, tr("Selectionner une image..."), pathPictures.toStdString().c_str(), tr("Image Files (*.png *.jpg *.bmp *.svg)"));
@@ -1252,29 +1251,22 @@
QMessageBox::critical(this, tr("Erreur"), tr("Impossible de charger l'image...D\351soler :("));
return;
}
+ is_adding_image = true;
}
/**
* @brief DiagramView::addDiagramImageAtPos
* @param pos
* @return
*/
-DiagramImageItem *DiagramView::addDiagramImageAtPos(const QPointF &) {
+DiagramImageItem *DiagramView::addDiagramImageAtPos(const QPointF &pos) {
if (!isInteractive() || scene -> isReadOnly()) return(0);
- QGraphicsPixmapItem *pixItem = new QGraphicsPixmapItem( QPixmap::fromImage(image_to_add_) );
- pixItem->setFlag(QGraphicsItem::ItemIsMovable,true);
- pixItem->setFlag(QGraphicsItem::ItemIsSelectable,true);
- pixItem->setCursor(Qt::PointingHandCursor);
-
- scene ->addItem(pixItem);
-
-
-// cree un nouveau champ image
+ // cree un nouveau champ image
DiagramImageItem *Imageitem = new DiagramImageItem( QPixmap::fromImage(image_to_add_) );
// le place a la position pos en gerant l'annulation
- //scene -> undoStack().push(new AddImageCommand(scene, Imageitem, pos));
+ scene -> undoStack().push(new AddImageCommand(scene, Imageitem, pos));
adjustSceneRect();
// emet le signal ImageAdded