mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Basic Shapes: XML export/import added.
Many files were changed, so debugging required. Minor Bug exists: If we export to xml first time, it is OK. But if we then add another shape and then export, then the new shape is not added in XML. Reason: UndoAction not implemented at present for basi shape addition. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2888 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
#include "qetgraphicsitem/independenttextitem.h"
|
#include "qetgraphicsitem/independenttextitem.h"
|
||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
#include "qetgraphicsitem/diagramimageitem.h"
|
#include "qetgraphicsitem/diagramimageitem.h"
|
||||||
|
#include "qetgraphicsitem/qetshapeitem.h"
|
||||||
|
|
||||||
const int Diagram::xGrid = 10;
|
const int Diagram::xGrid = 10;
|
||||||
const int Diagram::yGrid = 10;
|
const int Diagram::yGrid = 10;
|
||||||
@@ -345,9 +346,12 @@ QDomDocument Diagram::toXml(bool whole_content) {
|
|||||||
QList<Conductor *> list_conductors;
|
QList<Conductor *> list_conductors;
|
||||||
QList<DiagramTextItem *> list_texts;
|
QList<DiagramTextItem *> list_texts;
|
||||||
QList<DiagramImageItem *> list_images;
|
QList<DiagramImageItem *> list_images;
|
||||||
|
QList<QetShapeItem *> list_shapes;
|
||||||
|
|
||||||
|
QList<QGraphicsItem *> list_items = items();
|
||||||
|
;
|
||||||
// Determine les elements a "XMLiser"
|
// Determine les elements a "XMLiser"
|
||||||
foreach(QGraphicsItem *qgi, items()) {
|
foreach(QGraphicsItem *qgi, list_items) {
|
||||||
if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
|
if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
|
||||||
if (whole_content) list_elements << elmt;
|
if (whole_content) list_elements << elmt;
|
||||||
else if (elmt -> isSelected()) list_elements << elmt;
|
else if (elmt -> isSelected()) list_elements << elmt;
|
||||||
@@ -364,6 +368,9 @@ QDomDocument Diagram::toXml(bool whole_content) {
|
|||||||
} else if (DiagramImageItem *dii = qgraphicsitem_cast<DiagramImageItem *>(qgi)) {
|
} else if (DiagramImageItem *dii = qgraphicsitem_cast<DiagramImageItem *>(qgi)) {
|
||||||
if (whole_content) list_images << dii;
|
if (whole_content) list_images << dii;
|
||||||
else if (dii -> isSelected()) list_images << dii;
|
else if (dii -> isSelected()) list_images << dii;
|
||||||
|
} else if (QetShapeItem *dsi = dynamic_cast<QetShapeItem *>(qgi)) {
|
||||||
|
if (whole_content) list_shapes << dsi;
|
||||||
|
else if (dsi -> isSelected()) list_shapes << dsi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,7 +412,17 @@ QDomDocument Diagram::toXml(bool whole_content) {
|
|||||||
}
|
}
|
||||||
racine.appendChild(images);
|
racine.appendChild(images);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save of basic shapes
|
||||||
|
if (!list_shapes.isEmpty()) {
|
||||||
|
QDomElement shapes = document.createElement("shapes");
|
||||||
|
foreach (QetShapeItem *dii, list_shapes) {
|
||||||
|
dii ->setWritingXml(true);
|
||||||
|
shapes.appendChild(dii -> toXml(document));
|
||||||
|
dii ->setWritingXml(false);
|
||||||
|
}
|
||||||
|
racine.appendChild(shapes);
|
||||||
|
}
|
||||||
// on retourne le document XML ainsi genere
|
// on retourne le document XML ainsi genere
|
||||||
return(document);
|
return(document);
|
||||||
}
|
}
|
||||||
@@ -568,6 +585,14 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
addItem(dii);
|
addItem(dii);
|
||||||
added_images << dii;
|
added_images << dii;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QetShapeItem *> added_shapes;
|
||||||
|
foreach (QDomElement shape_xml, QET::findInDomElement(root, "shapes", "shape")) {
|
||||||
|
QetShapeItem *dii = new QetShapeItem (QPointF(0,0));
|
||||||
|
dii -> fromXml(shape_xml);
|
||||||
|
addItem(dii);
|
||||||
|
added_shapes << dii;
|
||||||
|
}
|
||||||
|
|
||||||
// gere la translation des nouveaux elements et texte si celle-ci est demandee
|
// gere la translation des nouveaux elements et texte si celle-ci est demandee
|
||||||
if (position != QPointF()) {
|
if (position != QPointF()) {
|
||||||
@@ -578,6 +603,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
foreach (Element *added_element, added_elements) added_items << added_element;
|
foreach (Element *added_element, added_elements) added_items << added_element;
|
||||||
foreach (DiagramTextItem *added_text, added_texts) added_items << added_text;
|
foreach (DiagramTextItem *added_text, added_texts) added_items << added_text;
|
||||||
foreach (DiagramImageItem *added_image, added_images) added_items << added_image;
|
foreach (DiagramImageItem *added_image, added_images) added_items << added_image;
|
||||||
|
foreach (QetShapeItem *added_shape, added_shapes) added_items << added_shape;
|
||||||
foreach (QGraphicsItem *item, added_items) {
|
foreach (QGraphicsItem *item, added_items) {
|
||||||
QPointF csg = item -> mapToScene(item -> boundingRect()).boundingRect().topLeft();
|
QPointF csg = item -> mapToScene(item -> boundingRect()).boundingRect().topLeft();
|
||||||
qreal px = csg.x();
|
qreal px = csg.x();
|
||||||
@@ -602,6 +628,9 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
foreach (DiagramImageItem *added_image, added_images) {
|
foreach (DiagramImageItem *added_image, added_images) {
|
||||||
added_image -> setPos(added_image -> pos().x() + diff_x, added_image -> pos().y() + diff_y);
|
added_image -> setPos(added_image -> pos().x() + diff_x, added_image -> pos().y() + diff_y);
|
||||||
}
|
}
|
||||||
|
foreach (QetShapeItem *added_shape, added_shapes) {
|
||||||
|
added_shape -> setPos(added_shape -> pos().x() + diff_x, added_shape -> pos().y() + diff_y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// chargement de tous les Conducteurs du fichier XML
|
// chargement de tous les Conducteurs du fichier XML
|
||||||
@@ -638,6 +667,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
content_ptr -> conductorsToMove = added_conductors.toSet();
|
content_ptr -> conductorsToMove = added_conductors.toSet();
|
||||||
content_ptr -> textFields = added_texts.toSet();
|
content_ptr -> textFields = added_texts.toSet();
|
||||||
content_ptr -> images = added_images.toSet();
|
content_ptr -> images = added_images.toSet();
|
||||||
|
content_ptr -> shapes = added_shapes.toSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
|
|||||||
@@ -136,6 +136,43 @@ void AddImageCommand::redo() {
|
|||||||
imageitem -> setPos(position - imageitem -> boundingRect().center());
|
imageitem -> setPos(position - imageitem -> boundingRect().center());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param dia Schema auquel on ajoute une shape
|
||||||
|
@param shape Shape ajoute
|
||||||
|
@param pos Position a laquelle l'shape est ajoute
|
||||||
|
@param parent QUndoCommand parent
|
||||||
|
*/
|
||||||
|
AddShapeCommand::AddShapeCommand(Diagram *dia, QetShapeItem *shape, const QPointF &pos, QUndoCommand *parent):
|
||||||
|
QUndoCommand(QObject::tr("Ajouter une Shape", "undo caption"), parent),
|
||||||
|
shapeitem(shape),
|
||||||
|
diagram(dia),
|
||||||
|
position(pos)
|
||||||
|
{
|
||||||
|
diagram -> qgiManager().manage(shapeitem);
|
||||||
|
}
|
||||||
|
|
||||||
|
///Destructor
|
||||||
|
AddShapeCommand::~AddShapeCommand() {
|
||||||
|
diagram -> qgiManager().release(shapeitem);
|
||||||
|
}
|
||||||
|
|
||||||
|
///Annule l'ajout
|
||||||
|
void AddShapeCommand::undo() {
|
||||||
|
diagram -> showMe();
|
||||||
|
diagram -> removeItem(shapeitem);
|
||||||
|
}
|
||||||
|
|
||||||
|
///Refait l'ajout
|
||||||
|
void AddShapeCommand::redo() {
|
||||||
|
diagram -> showMe();
|
||||||
|
if (shapeitem ->diagram() != diagram)
|
||||||
|
diagram -> addItem(shapeitem);
|
||||||
|
//diagram -> addDiagramImageItem(imageitem);
|
||||||
|
//imageitem -> setPos(position - imageitem -> boundingRect().center());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@param d Schema auquel on ajoute un conducteur
|
@param d Schema auquel on ajoute un conducteur
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "diagramcontent.h"
|
#include "diagramcontent.h"
|
||||||
#include "titleblockproperties.h"
|
#include "titleblockproperties.h"
|
||||||
#include "qet.h"
|
#include "qet.h"
|
||||||
|
#include "qetgraphicsitem/qetshapeitem.h"
|
||||||
class Diagram;
|
class Diagram;
|
||||||
class DiagramTextItem;
|
class DiagramTextItem;
|
||||||
class Element;
|
class Element;
|
||||||
@@ -111,6 +112,34 @@ class AddImageCommand : public QUndoCommand {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
This command adds an image item to a particular diagram
|
||||||
|
*/
|
||||||
|
class AddShapeCommand : public QUndoCommand {
|
||||||
|
//constructors, destructor
|
||||||
|
public:
|
||||||
|
AddShapeCommand (Diagram *, QetShapeItem *, const QPointF &, QUndoCommand * = 0);
|
||||||
|
virtual ~AddShapeCommand();
|
||||||
|
private:
|
||||||
|
AddShapeCommand(const AddShapeCommand &);
|
||||||
|
|
||||||
|
//methods
|
||||||
|
public:
|
||||||
|
virtual void undo();
|
||||||
|
virtual void redo();
|
||||||
|
|
||||||
|
// attributes
|
||||||
|
private:
|
||||||
|
/// added shape item
|
||||||
|
QetShapeItem *shapeitem;
|
||||||
|
/// 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.
|
This command adds a conductor to a particular diagram.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ DiagramContent::DiagramContent(const DiagramContent &other) :
|
|||||||
elements(other.elements),
|
elements(other.elements),
|
||||||
textFields(other.textFields),
|
textFields(other.textFields),
|
||||||
images(other.images),
|
images(other.images),
|
||||||
|
shapes(other.shapes),
|
||||||
conductorsToUpdate(other.conductorsToUpdate),
|
conductorsToUpdate(other.conductorsToUpdate),
|
||||||
conductorsToMove(other.conductorsToMove),
|
conductorsToMove(other.conductorsToMove),
|
||||||
otherConductors(other.otherConductors)
|
otherConductors(other.otherConductors)
|
||||||
@@ -71,6 +72,7 @@ void DiagramContent::clear() {
|
|||||||
elements.clear();
|
elements.clear();
|
||||||
textFields.clear();
|
textFields.clear();
|
||||||
images.clear();
|
images.clear();
|
||||||
|
shapes.clear();
|
||||||
conductorsToUpdate.clear();
|
conductorsToUpdate.clear();
|
||||||
conductorsToMove.clear();
|
conductorsToMove.clear();
|
||||||
otherConductors.clear();
|
otherConductors.clear();
|
||||||
@@ -86,6 +88,7 @@ QList<QGraphicsItem *> DiagramContent::items(int filter) const {
|
|||||||
if (filter & Elements) foreach(QGraphicsItem *qgi, elements) items_list << qgi;
|
if (filter & Elements) foreach(QGraphicsItem *qgi, elements) items_list << qgi;
|
||||||
if (filter & TextFields) foreach(QGraphicsItem *qgi, textFields) items_list << qgi;
|
if (filter & TextFields) foreach(QGraphicsItem *qgi, textFields) items_list << qgi;
|
||||||
if (filter & Images) foreach(QGraphicsItem *qgi, images) items_list << qgi;
|
if (filter & Images) foreach(QGraphicsItem *qgi, images) items_list << qgi;
|
||||||
|
if (filter & Shapes) foreach(QGraphicsItem *qgi, shapes) items_list << qgi;
|
||||||
if (filter & SelectedOnly) {
|
if (filter & SelectedOnly) {
|
||||||
foreach(QGraphicsItem *qgi, items_list) {
|
foreach(QGraphicsItem *qgi, items_list) {
|
||||||
if (!qgi -> isSelected()) items_list.removeOne(qgi);
|
if (!qgi -> isSelected()) items_list.removeOne(qgi);
|
||||||
@@ -104,6 +107,7 @@ int DiagramContent::count(int filter) const {
|
|||||||
if (filter & Elements) foreach(Element *element, elements) { if (element -> isSelected()) ++ count; }
|
if (filter & Elements) foreach(Element *element, elements) { if (element -> isSelected()) ++ count; }
|
||||||
if (filter & TextFields) foreach(DiagramTextItem *dti, textFields) { if (dti -> isSelected()) ++ count; }
|
if (filter & TextFields) foreach(DiagramTextItem *dti, textFields) { if (dti -> isSelected()) ++ count; }
|
||||||
if (filter & Images) foreach(DiagramImageItem *dii, images) { if (dii -> isSelected()) ++ count; }
|
if (filter & Images) foreach(DiagramImageItem *dii, images) { if (dii -> isSelected()) ++ count; }
|
||||||
|
if (filter & Shapes) foreach(QetShapeItem *dsi, shapes) { if (dsi -> isSelected()) ++ count; }
|
||||||
if (filter & ConductorsToMove) foreach(Conductor *conductor, conductorsToMove) { if (conductor -> isSelected()) ++ count; }
|
if (filter & ConductorsToMove) foreach(Conductor *conductor, conductorsToMove) { if (conductor -> isSelected()) ++ count; }
|
||||||
if (filter & ConductorsToUpdate) foreach(Conductor *conductor, conductorsToUpdate) { if (conductor -> isSelected()) ++ count; }
|
if (filter & ConductorsToUpdate) foreach(Conductor *conductor, conductorsToUpdate) { if (conductor -> isSelected()) ++ count; }
|
||||||
if (filter & OtherConductors) foreach(Conductor *conductor, otherConductors) { if (conductor -> isSelected()) ++ count; }
|
if (filter & OtherConductors) foreach(Conductor *conductor, otherConductors) { if (conductor -> isSelected()) ++ count; }
|
||||||
@@ -112,6 +116,7 @@ int DiagramContent::count(int filter) const {
|
|||||||
if (filter & Elements) count += elements.count();
|
if (filter & Elements) count += elements.count();
|
||||||
if (filter & TextFields) count += textFields.count();
|
if (filter & TextFields) count += textFields.count();
|
||||||
if (filter & Images) count += images.count();
|
if (filter & Images) count += images.count();
|
||||||
|
if (filter & Shapes) count += shapes.count();
|
||||||
if (filter & ConductorsToMove) count += conductorsToMove.count();
|
if (filter & ConductorsToMove) count += conductorsToMove.count();
|
||||||
if (filter & ConductorsToUpdate) count += conductorsToUpdate.count();
|
if (filter & ConductorsToUpdate) count += conductorsToUpdate.count();
|
||||||
if (filter & OtherConductors) count += otherConductors.count();
|
if (filter & OtherConductors) count += otherConductors.count();
|
||||||
@@ -130,13 +135,15 @@ QString DiagramContent::sentence(int filter) const {
|
|||||||
int conductors_count = conductors(filter).count();
|
int conductors_count = conductors(filter).count();
|
||||||
int textfields_count = (filter & TextFields) ? textFields.count() : 0;
|
int textfields_count = (filter & TextFields) ? textFields.count() : 0;
|
||||||
int images_count = (filter & Images) ? images.count() : 0;
|
int images_count = (filter & Images) ? images.count() : 0;
|
||||||
|
int shapes_count = (filter & Shapes) ? shapes.count() : 0;
|
||||||
|
|
||||||
return(
|
return(
|
||||||
QET::ElementsAndConductorsSentence(
|
QET::ElementsAndConductorsSentence(
|
||||||
elements_count,
|
elements_count,
|
||||||
conductors_count,
|
conductors_count,
|
||||||
textfields_count,
|
textfields_count,
|
||||||
images_count
|
images_count,
|
||||||
|
shapes_count
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,12 @@
|
|||||||
#ifndef DIAGRAM_CONTENT_H
|
#ifndef DIAGRAM_CONTENT_H
|
||||||
#define DIAGRAM_CONTENT_H
|
#define DIAGRAM_CONTENT_H
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
#include "qetgraphicsitem/qetshapeitem.h"
|
||||||
class Conductor;
|
class Conductor;
|
||||||
class Element;
|
class Element;
|
||||||
class IndependentTextItem;
|
class IndependentTextItem;
|
||||||
class DiagramImageItem;
|
class DiagramImageItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This class provides a container that makes the transmission of diagram content
|
This class provides a container that makes the transmission of diagram content
|
||||||
to other functions/methods easier. The different kind of items are made
|
to other functions/methods easier. The different kind of items are made
|
||||||
@@ -47,7 +49,8 @@ class DiagramContent {
|
|||||||
OtherConductors = 32,
|
OtherConductors = 32,
|
||||||
AnyConductor = 56,
|
AnyConductor = 56,
|
||||||
All = 63,
|
All = 63,
|
||||||
SelectedOnly = 64
|
SelectedOnly = 64,
|
||||||
|
Shapes = 128
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Hold electrical elements
|
/// Hold electrical elements
|
||||||
@@ -56,6 +59,8 @@ class DiagramContent {
|
|||||||
QSet<IndependentTextItem *> textFields;
|
QSet<IndependentTextItem *> textFields;
|
||||||
/// Hold image
|
/// Hold image
|
||||||
QSet<DiagramImageItem *> images;
|
QSet<DiagramImageItem *> images;
|
||||||
|
/// Hold shape
|
||||||
|
QSet<QetShapeItem *> shapes;
|
||||||
/// Hold conductors that would get updated considering electrical elements are moved
|
/// Hold conductors that would get updated considering electrical elements are moved
|
||||||
QSet<Conductor *> conductorsToUpdate;
|
QSet<Conductor *> conductorsToUpdate;
|
||||||
/// Hold conductors that would be moved as is considering electrical elements are moved
|
/// Hold conductors that would be moved as is considering electrical elements are moved
|
||||||
|
|||||||
@@ -461,6 +461,9 @@ void DiagramView::mousePressEvent(QMouseEvent *e) {
|
|||||||
rubber_band_origin = mapToScene(e -> pos());
|
rubber_band_origin = mapToScene(e -> pos());
|
||||||
newItem = new QetShapeItem(rubber_band_origin, rubber_band_origin, QetShapeItem::Line, false);
|
newItem = new QetShapeItem(rubber_band_origin, rubber_band_origin, QetShapeItem::Line, false);
|
||||||
scene -> addItem(newItem);
|
scene -> addItem(newItem);
|
||||||
|
// le place a la position pos en gerant l'annulation
|
||||||
|
//scene -> undoStack().push(new AddShapeCommand(scene, newItem, e->pos));
|
||||||
|
//adjustSceneRect();
|
||||||
break;
|
break;
|
||||||
case addingRectangle:
|
case addingRectangle:
|
||||||
rubber_band_origin = mapToScene(e -> pos());
|
rubber_band_origin = mapToScene(e -> pos());
|
||||||
@@ -714,7 +717,7 @@ bool DiagramView::hasCopiableItems() {
|
|||||||
if (
|
if (
|
||||||
qgraphicsitem_cast<Element *>(qgi) ||
|
qgraphicsitem_cast<Element *>(qgi) ||
|
||||||
qgraphicsitem_cast<IndependentTextItem *>(qgi) ||
|
qgraphicsitem_cast<IndependentTextItem *>(qgi) ||
|
||||||
qgraphicsitem_cast<QetShapeItem *>(qgi) ||
|
dynamic_cast<QetShapeItem *>(qgi) ||
|
||||||
qgraphicsitem_cast<DiagramImageItem *>(qgi)
|
qgraphicsitem_cast<DiagramImageItem *>(qgi)
|
||||||
) {
|
) {
|
||||||
return(true);
|
return(true);
|
||||||
@@ -733,7 +736,7 @@ bool DiagramView::hasDeletableItems() {
|
|||||||
qgraphicsitem_cast<Element *>(qgi) ||
|
qgraphicsitem_cast<Element *>(qgi) ||
|
||||||
qgraphicsitem_cast<Conductor *>(qgi) ||
|
qgraphicsitem_cast<Conductor *>(qgi) ||
|
||||||
qgraphicsitem_cast<IndependentTextItem *>(qgi) ||
|
qgraphicsitem_cast<IndependentTextItem *>(qgi) ||
|
||||||
qgraphicsitem_cast<QetShapeItem *>(qgi) ||
|
dynamic_cast<QetShapeItem *>(qgi) ||
|
||||||
qgraphicsitem_cast<DiagramImageItem *>(qgi)
|
qgraphicsitem_cast<DiagramImageItem *>(qgi)
|
||||||
) {
|
) {
|
||||||
return(true);
|
return(true);
|
||||||
|
|||||||
@@ -481,7 +481,7 @@ void ExportDialog::generateDxf(Diagram *diagram, int width, int height, bool kee
|
|||||||
list_texts << iti;
|
list_texts << iti;
|
||||||
} else if (DiagramImageItem *dii = qgraphicsitem_cast<DiagramImageItem *>(qgi)) {
|
} else if (DiagramImageItem *dii = qgraphicsitem_cast<DiagramImageItem *>(qgi)) {
|
||||||
list_images << dii;
|
list_images << dii;
|
||||||
} else if (QetShapeItem *dii = qgraphicsitem_cast<QetShapeItem *>(qgi)) {
|
} else if (QetShapeItem *dii = dynamic_cast<QetShapeItem *>(qgi)) {
|
||||||
if (dii -> getType() == QetShapeItem::Line && dii -> getLine()) {
|
if (dii -> getType() == QetShapeItem::Line && dii -> getLine()) {
|
||||||
list_lines << dii -> getLine();
|
list_lines << dii -> getLine();
|
||||||
} else if (dii -> getType() == QetShapeItem::Rectangle && dii -> getRectangle()) {
|
} else if (dii -> getType() == QetShapeItem::Rectangle && dii -> getRectangle()) {
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ bool QET::attributeIsAReal(const QDomElement &e, QString nom_attribut, qreal *re
|
|||||||
@return la proposition decrivant le nombre d'elements, de conducteurs et de
|
@return la proposition decrivant le nombre d'elements, de conducteurs et de
|
||||||
textes
|
textes
|
||||||
*/
|
*/
|
||||||
QString QET::ElementsAndConductorsSentence(int elements_count, int conductors_count, int texts_count, int images_count) {
|
QString QET::ElementsAndConductorsSentence(int elements_count, int conductors_count, int texts_count, int images_count, int shapes_count) {
|
||||||
QString text;
|
QString text;
|
||||||
if (elements_count) {
|
if (elements_count) {
|
||||||
text += QObject::tr(
|
text += QObject::tr(
|
||||||
@@ -270,6 +270,14 @@ QString QET::ElementsAndConductorsSentence(int elements_count, int conductors_co
|
|||||||
images_count
|
images_count
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shapes_count) {
|
||||||
|
text += QObject::tr(
|
||||||
|
"%n image(s)",
|
||||||
|
"part of a sentence listing the content of a diagram",
|
||||||
|
shapes_count
|
||||||
|
);
|
||||||
|
}
|
||||||
return(text);
|
return(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ namespace QET {
|
|||||||
bool orthogonalProjection(const QPointF &, const QLineF &, QPointF * = 0);
|
bool orthogonalProjection(const QPointF &, const QLineF &, QPointF * = 0);
|
||||||
bool attributeIsAnInteger(const QDomElement &, QString , int * = NULL);
|
bool attributeIsAnInteger(const QDomElement &, QString , int * = NULL);
|
||||||
bool attributeIsAReal(const QDomElement &, QString , qreal * = NULL);
|
bool attributeIsAReal(const QDomElement &, QString , qreal * = NULL);
|
||||||
QString ElementsAndConductorsSentence(int, int, int = 0, int = 0);
|
QString ElementsAndConductorsSentence(int, int, int = 0, int = 0, int = 0);
|
||||||
QList<QDomElement> findInDomElement(const QDomElement &, const QString &);
|
QList<QDomElement> findInDomElement(const QDomElement &, const QString &);
|
||||||
QList<QDomElement> findInDomElement(const QDomElement &, const QString &, const QString &);
|
QList<QDomElement> findInDomElement(const QDomElement &, const QString &, const QString &);
|
||||||
QList<QChar> forbiddenCharacters();
|
QList<QChar> forbiddenCharacters();
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
#include "qetshapeitem.h"
|
#include "qetshapeitem.h"
|
||||||
|
|
||||||
|
|
||||||
QetShapeItem::QetShapeItem(QPointF p1, QPointF p2, ShapeType type, bool lineAngle,QGraphicsItem *parent) :
|
QetShapeItem::QetShapeItem(QPointF p1, QPointF p2, ShapeType type, bool lineAngle,QGraphicsItem *parent) :
|
||||||
QetGraphicsItem(parent),
|
QetGraphicsItem(parent),
|
||||||
_shapeStyle(Qt::DashLine),
|
_shapeStyle(Qt::DashLine),
|
||||||
_lineAngle(lineAngle),
|
_lineAngle(lineAngle),
|
||||||
_isFullyBuilt(false)
|
_isFullyBuilt(false),
|
||||||
|
_writingXml(false)
|
||||||
{
|
{
|
||||||
_shapeType = type;
|
_shapeType = type;
|
||||||
_boundingRect = QRectF(p1, p2);
|
_boundingRect = QRectF(p1, p2);
|
||||||
@@ -96,24 +98,63 @@ QPainterPath QetShapeItem::shape() const
|
|||||||
|
|
||||||
void QetShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
void QetShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
painter -> setRenderHint(QPainter::Antialiasing, false);
|
if (!_writingXml) {
|
||||||
QRectF rec = boundingRect();
|
painter -> setRenderHint(QPainter::Antialiasing, false);
|
||||||
QPen pen(Qt::black);
|
QRectF rec = boundingRect();
|
||||||
if (isSelected())
|
QPen pen(Qt::black);
|
||||||
pen.setColor(Qt::red);
|
if (isSelected())
|
||||||
pen.setStyle(_shapeStyle);
|
pen.setColor(Qt::red);
|
||||||
painter->setPen(pen);
|
pen.setStyle(_shapeStyle);
|
||||||
switch(_shapeType) {
|
painter->setPen(pen);
|
||||||
case Line:
|
switch(_shapeType) {
|
||||||
if (_lineAngle)
|
case Line:
|
||||||
painter -> drawLine(rec.topRight(), rec.bottomLeft());
|
if (_lineAngle)
|
||||||
else
|
painter -> drawLine(rec.topRight(), rec.bottomLeft());
|
||||||
painter -> drawLine(rec.topLeft(), rec.bottomRight());
|
else
|
||||||
break;
|
painter -> drawLine(rec.topLeft(), rec.bottomRight());
|
||||||
case Rectangle:
|
break;
|
||||||
painter -> drawRect(rec);
|
case Rectangle:
|
||||||
break;
|
painter -> drawRect(rec);
|
||||||
default: //(case Ellipse:)
|
break;
|
||||||
painter ->drawEllipse(rec);
|
default: //(case Ellipse:)
|
||||||
|
painter ->drawEllipse(rec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool QetShapeItem::fromXml(const QDomElement &e)
|
||||||
|
{
|
||||||
|
if (!_writingXml) {
|
||||||
|
if (e.tagName() != "shape") return (false);
|
||||||
|
|
||||||
|
_shapeType = QetShapeItem::ShapeType(e.attribute("type","0").toInt());
|
||||||
|
_shapeStyle = Qt::PenStyle(e.attribute("style","0").toInt());
|
||||||
|
_lineAngle = e.attribute("lineAngle","0").toInt();
|
||||||
|
qreal x = e.attribute("x","0").toDouble();
|
||||||
|
qreal y = e.attribute("y","0").toDouble();
|
||||||
|
qreal w = e.attribute("w","0").toDouble();
|
||||||
|
qreal h = e.attribute("h","0").toDouble();
|
||||||
|
setBoundingRect(QRectF(x, y, w, h));
|
||||||
|
setFullyBuilt(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QDomElement QetShapeItem::toXml(QDomDocument &document) const {
|
||||||
|
QDomElement result = document.createElement("shape");
|
||||||
|
QRectF rec = boundingRect();
|
||||||
|
|
||||||
|
//write some attribute
|
||||||
|
result.setAttribute("type", QString::number(_shapeType));
|
||||||
|
result.setAttribute("x", QString::number(rec.topLeft().x()));
|
||||||
|
result.setAttribute("y", QString::number(rec.topLeft().y()));
|
||||||
|
result.setAttribute("w", QString::number(rec.width()));
|
||||||
|
result.setAttribute("h", QString::number(rec.height()));
|
||||||
|
result.setAttribute("lineAngle", QString::number(_lineAngle));
|
||||||
|
result.setAttribute("style", QString::number(_shapeStyle));
|
||||||
|
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ class QetShapeItem : public QetGraphicsItem
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
enum ShapeType {
|
enum ShapeType {
|
||||||
Line,
|
Line = 0,
|
||||||
Rectangle,
|
Rectangle,
|
||||||
Ellipse
|
Ellipse
|
||||||
};
|
};
|
||||||
|
|
||||||
QetShapeItem(QPointF, QPointF, ShapeType, bool lineAngle = false, QGraphicsItem *parent = 0);
|
QetShapeItem(QPointF, QPointF = QPointF(0,0), ShapeType = Line, bool lineAngle = false, QGraphicsItem *parent = 0);
|
||||||
virtual ~QetShapeItem();
|
virtual ~QetShapeItem();
|
||||||
|
|
||||||
void setStyle(Qt::PenStyle);
|
void setStyle(Qt::PenStyle);
|
||||||
@@ -25,6 +25,9 @@ class QetShapeItem : public QetGraphicsItem
|
|||||||
QLineF *getLine();
|
QLineF *getLine();
|
||||||
QRectF *getRectangle();
|
QRectF *getRectangle();
|
||||||
QRectF *getEllipse();
|
QRectF *getEllipse();
|
||||||
|
virtual bool fromXml(const QDomElement &);
|
||||||
|
virtual QDomElement toXml(QDomDocument &document) const;
|
||||||
|
void setWritingXml(bool writing) { _writingXml = writing; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ShapeType _shapeType;
|
ShapeType _shapeType;
|
||||||
@@ -35,6 +38,7 @@ class QetShapeItem : public QetGraphicsItem
|
|||||||
bool _isFullyBuilt;
|
bool _isFullyBuilt;
|
||||||
QPointF _lineP1;
|
QPointF _lineP1;
|
||||||
QPointF _lineP2;
|
QPointF _lineP2;
|
||||||
|
bool _writingXml;
|
||||||
|
|
||||||
virtual void editProperty() {}
|
virtual void editProperty() {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user