Change the way to add new element in a diagram.

Drag & drop an element in a diagram and click left to add it, click right to finish


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3803 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun 2015-03-04 21:13:13 +00:00
parent 317626446a
commit bb54483e23
12 changed files with 669 additions and 33 deletions

View File

@ -73,7 +73,8 @@ INCLUDEPATH += sources \
sources/editor \
sources/editor/esevent \
sources/editor/graphicspart \
sources/undocommand
sources/undocommand \
sources/diagramevent
# Fichiers sources
@ -83,7 +84,8 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) $$files(sources/editor/*
$$files(sources/editor/esevent/*.h) \
$$files(sources/editor/graphicspart/*.h) \
$$files(sources/dvevent/*.h) \
$$files(sources/undocommand/*.h)
$$files(sources/undocommand/*.h) \
$$files(sources/diagramevent/*.h)
SOURCES += $$files(sources/*.cpp) $$files(sources/editor/*.cpp) $$files(sources/titleblock/*.cpp) $$files(sources/richtext/*.cpp) $$files(sources/ui/*.cpp) $$files(sources/qetgraphicsitem/*.cpp) $$files(sources/factory/*.cpp) \
$$files(sources/properties/*.cpp) \
@ -91,7 +93,8 @@ SOURCES += $$files(sources/*.cpp) $$files(sources/editor/*.cpp) $$files(sources/
$$files(sources/editor/esevent/*.cpp) \
$$files(sources/editor/graphicspart/*.cpp) \
$$files(sources/dvevent/*.cpp) \
$$files(sources/undocommand/*.cpp)
$$files(sources/undocommand/*.cpp) \
$$files(sources/diagramevent/*.cpp)
# Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt
RESOURCES += qelectrotech.qrc

View File

@ -34,6 +34,7 @@
#include "qetgraphicsitem/qetshapeitem.h"
#include "terminal.h"
#include "elementtextsmover.h"
#include "diagrameventinterface.h"
const int Diagram::xGrid = 10;
const int Diagram::yGrid = 10;
@ -54,17 +55,15 @@ Diagram::Diagram(QETProject *project) :
draw_grid_ (true),
use_border_ (true),
draw_terminals_ (true),
draw_colored_conductors_ (true)
draw_colored_conductors_ (true),
m_event_interface (nullptr)
{
setProject(project);
qgi_manager_ = new QGIManager(this);
setBackgroundBrush(Qt::white);
conductor_setter_ = new QGraphicsLineItem(0);
conductor_setter_ -> setZValue(1000000);
// QPen t;
// t.setColor(Qt::black);
// t.setWidthF(1.5);
// t.setStyle(Qt::DashLine);
QPen pen(Qt::NoBrush, 1.5, Qt::DashLine);
pen.setColor(Qt::black);
conductor_setter_ -> setPen(pen);
@ -93,6 +92,8 @@ Diagram::~Diagram() {
// delete of object for manage movement
delete elements_mover_;
delete element_texts_mover_;
if (m_event_interface) delete m_event_interface;
// list removable items
QList<QGraphicsItem *> deletable_items;
@ -155,10 +156,115 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
}
/**
Gere les enfoncements de touches du clavier
@param e QKeyEvent decrivant l'evenement clavier
*/
void Diagram::keyPressEvent(QKeyEvent *e) {
* @brief Diagram::mouseDoubleClickEvent
* This event is managed by diagram event interface if any.
* @param event :
*/
void Diagram::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
if (m_event_interface) {
if (m_event_interface -> mouseDoubleClickEvent(event)) {
if (m_event_interface->isFinish()) {
delete m_event_interface; m_event_interface = nullptr;
}
return;
}
}
QGraphicsScene::mouseDoubleClickEvent(event);
}
/**
* @brief Diagram::mousePressEvent
* This event is managed by diagram event interface if any.
* @param event
*/
void Diagram::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (m_event_interface) {
if (m_event_interface -> mousePressEvent(event)) {
if (m_event_interface->isFinish()) {
delete m_event_interface; m_event_interface = nullptr;
}
return;
}
}
QGraphicsScene::mousePressEvent(event);
}
/**
* @brief Diagram::mouseMoveEvent
* This event is managed by diagram event interface if any.
* @param event
*/
void Diagram::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (m_event_interface) {
if (m_event_interface -> mouseMoveEvent(event)) {
if (m_event_interface->isFinish()) {
delete m_event_interface; m_event_interface = nullptr;
}
return;
}
}
QGraphicsScene::mouseMoveEvent(event);
}
/**
* @brief Diagram::mouseReleaseEvent
* This event is managed by diagram event interface if any.
* @param event
*/
void Diagram::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (m_event_interface) {
if (m_event_interface -> mouseReleaseEvent(event)) {
if (m_event_interface->isFinish()) {
delete m_event_interface; m_event_interface = nullptr;
}
return;
}
}
QGraphicsScene::mouseReleaseEvent(event);
}
/**
* @brief Diagram::wheelEvent
* This event is managed by diagram event interface if any.
* @param event
*/
void Diagram::wheelEvent(QGraphicsSceneWheelEvent *event)
{
if (m_event_interface) {
if (m_event_interface -> wheelEvent(event)) {
if (m_event_interface->isFinish()) {
delete m_event_interface; m_event_interface = nullptr;
}
return;
}
}
}
/**
* @brief Diagram::keyPressEvent
* This event is managed by diagram event interface if any.
* Else move selected elements
* @param e
*/
void Diagram::keyPressEvent(QKeyEvent *e)
{
if (m_event_interface) {
if (m_event_interface -> keyPressEvent(e)) {
if (m_event_interface->isFinish()) {
delete m_event_interface; m_event_interface = nullptr;
}
return;
}
}
bool transmit_event = true;
if (!isReadOnly()) {
QPointF movement;
@ -181,10 +287,22 @@ void Diagram::keyPressEvent(QKeyEvent *e) {
}
/**
Gere les relachements de touches du clavier
@param e QKeyEvent decrivant l'evenement clavier
*/
void Diagram::keyReleaseEvent(QKeyEvent *e) {
* @brief Diagram::keyReleaseEvent
* This event is managed by diagram event interface if any.
* Else move selected element
* @param e
*/
void Diagram::keyReleaseEvent(QKeyEvent *e)
{
if (m_event_interface) {
if (m_event_interface -> KeyReleaseEvent(e)) {
if (m_event_interface->isFinish()) {
delete m_event_interface; m_event_interface = nullptr;
}
return;
}
}
bool transmit_event = true;
if (!isReadOnly()) {
// detecte le relachement d'une touche de direction ( = deplacement d'elements)
@ -203,6 +321,24 @@ void Diagram::keyReleaseEvent(QKeyEvent *e) {
}
}
/**
* @brief Diagram::setEventInterface
* Set event_interface has current interface.
* Diagram become the ownership of event_interface
* If there is a previous interface, they will be delete before
* and call init() to the new interface.
* @param event_interface
*/
void Diagram::setEventInterface(DiagramEventInterface *event_interface)
{
if (m_event_interface)
{
delete m_event_interface;
event_interface -> init();
}
m_event_interface = event_interface;
}
/**
* @brief Diagram::conductorsAutonumName
* @return the name of autonum to use.

View File

@ -43,6 +43,8 @@ class Terminal;
class ConductorTextItem;
class DiagramImageItem;
class ElementTextsMover;
class DiagramEventInterface;
/**
This class represents an electric diagram. It manages its various child
elements, conductors and texts and handles their graphic rendering.
@ -99,14 +101,23 @@ class Diagram : public QGraphicsScene
bool draw_colored_conductors_;
QString m_conductors_autonum_name;
DiagramEventInterface *m_event_interface;
// METHODS
protected:
virtual void drawBackground(QPainter *, const QRectF &);
virtual void keyPressEvent(QKeyEvent *);
virtual void keyReleaseEvent(QKeyEvent *);
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event);
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
virtual void wheelEvent (QGraphicsSceneWheelEvent *event);
virtual void keyPressEvent (QKeyEvent *);
virtual void keyReleaseEvent (QKeyEvent *);
public:
void setEventInterface (DiagramEventInterface *event_interface);
//methods related to xref properties
QString defaultReportProperties () const {return project_ -> defaultReportProperties();}
XRefProperties defaultXRefProperties (const QString &str) const {return project_ -> defaultXRefProperties(str);}

View File

@ -0,0 +1,237 @@
/*
Copyright 2006-2015 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "diagrameventaddelement.h"
#include "elementscollectionitem.h"
#include "qetapp.h"
#include "integrationmoveelementshandler.h"
#include "elementfactory.h"
#include "diagram.h"
#include "element.h"
#include "diagramcommands.h"
#include "conductorautonumerotation.h"
/**
* @brief DiagramEventAddElement::DiagramEventAddElement
* Defaut constructor
* @param location :location of diagram
* @param diagram : diagram owner of this event
* @param pos : first pos of item ( optional, by defaut QPointF(0,0) )
*/
DiagramEventAddElement::DiagramEventAddElement(ElementsLocation &location, Diagram *diagram, QPointF pos) :
DiagramEventInterface(diagram),
m_location(location),
m_element(nullptr)
{
//Check if there is an element at this location
ElementsCollectionItem *item = QETApp::collectionItem(location);
if (item)
{
//location is an element, we build it, if build fail,
//m_running stay to false (by default), so this interface will be deleted at next event
if (buildElement())
{
init();
m_element -> setPos(pos);
m_element -> displayHelpLine(true);
m_diagram -> addItem(m_element);
m_running = true;
}
}
}
/**
* @brief DiagramEventAddElement::~DiagramEventAddElement
* Destructor
* Enable context menu for each view of diagram
*/
DiagramEventAddElement::~DiagramEventAddElement()
{
if (m_element) delete m_element;
foreach(QGraphicsView *view, m_diagram->views())
view -> setContextMenuPolicy(Qt::DefaultContextMenu);
}
/**
* @brief DiagramEventAddElement::mouseMoveEvent
* Move the element to new pos of mouse
* @param event
* @return always true
*/
bool DiagramEventAddElement::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (m_element)
m_element -> setPos(Diagram::snapToGrid(event->scenePos()));
return true;
}
/**
* @brief DiagramEventAddElement::mousePressEvent
* Do nothing, but return true for not transit the event to other thing in diagram.
* @param event
* @return always true
*/
bool DiagramEventAddElement::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event);
return true;
}
/**
* @brief DiagramEventAddElement::mouseReleaseEvent
* Right button finish this event (isRunning = false)
* Left button add an element to diagram
* @param event
* @return always true
*/
bool DiagramEventAddElement::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (m_element)
{
if (event->button() == Qt::RightButton)
{
delete m_element;
m_element = nullptr;
m_running = false;
}
else if (event->button() == Qt::LeftButton)
{
addElement();
}
}
return true;
}
/**
* @brief DiagramEventAddElement::mouseDoubleClickEvent
* If mouse left double clic, finish this event (isRunning = false)
* @param event
* @return always true
*/
bool DiagramEventAddElement::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
if (m_element && (event -> button() == Qt::LeftButton))
{
delete m_element;
m_element = nullptr;
m_running = false;
}
return true;
}
/**
* @brief DiagramEventAddElement::keyPressEvent
* Press space key rotate the element to 90° (return true)
* else call DiagramEventInterface::keyPressEvent(event), and return the value.
* @param event
* @return
*/
bool DiagramEventAddElement::keyPressEvent(QKeyEvent *event)
{
if (m_element && event->key() == Qt::Key_Space)
{
m_element->rotateBy(90);
return true;
}
return DiagramEventInterface::keyPressEvent(event);
}
/**
* @brief DiagramEventAddElement::init
* Init this event.
*/
void DiagramEventAddElement::init()
{
foreach(QGraphicsView *view, m_diagram->views())
view->setContextMenuPolicy(Qt::NoContextMenu);
}
/**
* @brief DiagramEventAddElement::buildElement
* Build the element, if the element is build successfully, we return true, otherwise false
*/
bool DiagramEventAddElement::buildElement()
{
if (QETProject::integrateElementToProject(m_location, m_diagram -> project()))
{
QString error_msg;
IntegrationMoveElementsHandler *integ_handler = new IntegrationMoveElementsHandler();
QString integ_path = m_diagram -> project() -> integrateElement(m_location.toString(), integ_handler, error_msg);
delete integ_handler;
if (integ_path.isEmpty())
{
qDebug() << "DiagramView::addDroppedElement : Impossible d'ajouter l'element. Motif : " << qPrintable(error_msg);
return false;
}
}
int state;
m_element = ElementFactory::Instance() -> createElement(m_location, 0, &state);
//The creation of element failed, we delete it
if (state)
{
delete m_element;
return(false);
}
//Everything is good
return true;
}
/**
* @brief DiagramEventAddElement::addElement
* Add an element at the current pos en current rotation,
* if project autoconductor option is enable, and the element can be wired, we do it.
*/
void DiagramEventAddElement::addElement()
{
int state;
Element *element = ElementFactory::Instance() -> createElement(m_location, 0, &state);
//Build failed
if (state)
{
delete element;
return;
}
//We must add item to scene (even if addItemCommand do this)
//for create the autoconnection below
element -> setPos(m_element->pos());
element -> setRotation(m_element -> rotation());
m_diagram -> addItem(element);
QUndoCommand *undo_object = new AddItemCommand<Element *>(element, m_diagram, m_element -> pos());
while (!element -> AlignedFreeTerminals().isEmpty() && m_diagram -> project() -> autoConductor())
{
QPair <Terminal *, Terminal *> pair = element -> AlignedFreeTerminals().takeFirst();
Conductor *conductor = new Conductor(pair.first, pair.second);
conductor -> setProperties(m_diagram -> defaultConductorProperties);
new AddItemCommand<Conductor *>(conductor, m_diagram, QPointF(), undo_object);
//Autonum the new conductor, the undo command associated for this, have for parent undo_object
ConductorAutoNumerotation can (conductor, m_diagram, undo_object);
can.numerate();
};
m_diagram -> undoStack().push(undo_object);
}

View File

@ -0,0 +1,53 @@
/*
Copyright 2006-2015 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DIAGRAMEVENTADDELEMENT_H
#define DIAGRAMEVENTADDELEMENT_H
#include "diagrameventinterface.h"
#include "elementslocation.h"
class Element;
/**
* @brief The DiagramEventAddElement class
* This diagram event add a new element, for each left click button at the position of click.
* Space key rotate current element by 90°, right click button finish this event.
*/
class DiagramEventAddElement : public DiagramEventInterface
{
public:
DiagramEventAddElement(ElementsLocation &location, Diagram *diagram, QPointF pos = QPointF(0,0));
virtual ~DiagramEventAddElement();
virtual bool mouseMoveEvent (QGraphicsSceneMouseEvent *event);
virtual bool mousePressEvent (QGraphicsSceneMouseEvent *event);
virtual bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
virtual bool mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event);
virtual bool keyPressEvent (QKeyEvent *event);
virtual void init();
private:
bool buildElement();
void addElement();
private:
ElementsLocation m_location;
Element *m_element;
};
#endif // DIAGRAMEVENTADDELEMENT_H

View File

@ -0,0 +1,86 @@
/*
Copyright 2006-2015 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "diagrameventinterface.h"
#include <QGraphicsSceneMouseEvent>
#include <QKeyEvent>
DiagramEventInterface::DiagramEventInterface(Diagram *diagram) :
m_diagram(diagram),
m_running(false),
m_abort(false)
{
}
DiagramEventInterface::~DiagramEventInterface() {};
bool DiagramEventInterface::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event);
return false;
}
bool DiagramEventInterface::mousePressEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event);
return false;
}
bool DiagramEventInterface::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event);
return false;
}
bool DiagramEventInterface::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event);
return false;
}
bool DiagramEventInterface::wheelEvent(QGraphicsSceneWheelEvent *event) {
Q_UNUSED (event);
return false;
}
/**
* @brief DiagramEventInterface::keyPressEvent
* By default, press escape key abort the curent action
* @param event
* @return
*/
bool DiagramEventInterface::keyPressEvent(QKeyEvent *event) {
if (event->key() == Qt::Key_Escape) {
m_running = false;
m_abort = true;
return true;
}
return false;
}
bool DiagramEventInterface::KeyReleaseEvent(QKeyEvent *event) {
Q_UNUSED (event);
return false;
}
bool DiagramEventInterface::isRunning() const {
return m_running;
}
bool DiagramEventInterface::isFinish() const {
return !m_running;
}
void DiagramEventInterface::init()
{}

View File

@ -0,0 +1,70 @@
/*
Copyright 2006-2015 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DIAGRAMEVENTINTERFACE_H
#define DIAGRAMEVENTINTERFACE_H
class QGraphicsSceneMouseEvent;
class QGraphicsSceneWheelEvent;
class QKeyEvent;
class Diagram;
/**
* @brief The DiagramEventInterface class
* Each method return a bool: True if the methode do something else return false.
* Each method of DVEventInterface return false;
* isRunning() return true if action is started but not finish. By default return false.
* isFinish() return true when the action is finish, or not started. By default return true.
*
* ##USE DiagramEventInterface##
* This class is the basic interface for manage event on a diagram.
* To create a behavior for event diagram, we need to herite this class.
* This interface work like this :
* You need to create an interface and call diagram::setEventInterface(*your_interface).
* When a diagram get an event (mouse or key) if they have an event interface,
* they send the event to the interface (for exemple mousePressEvent).
* If the interface do something with this event, you need to return true to signal the diagram you work with this event.
* (if you do nothing by defaut the interface return false, so diagram do nothing)
* after that, the diagram call interface::isRunning(), if true diagram do nothing, else if false,
* that mean interface has finish is action (interface::isFinish return true) so the diagram will delete this interface.
* Be carreful with the destructor, diagram can at any time (even if interface is still running) delete the interface,
* the bool m_abort is here for that at destruction time.
*
*/
class DiagramEventInterface
{
public:
DiagramEventInterface(Diagram *diagram);
virtual ~DiagramEventInterface() = 0;
virtual bool mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event);
virtual bool mousePressEvent (QGraphicsSceneMouseEvent *event);
virtual bool mouseMoveEvent (QGraphicsSceneMouseEvent *event);
virtual bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
virtual bool wheelEvent (QGraphicsSceneWheelEvent *event);
virtual bool keyPressEvent (QKeyEvent *event);
virtual bool KeyReleaseEvent (QKeyEvent *event);
virtual bool isRunning () const;
virtual bool isFinish () const;
virtual void init();
protected:
Diagram *m_diagram;
bool m_running;
bool m_abort;
};
#endif // DIAGRAMEVENTINTERFACE_H

View File

@ -42,6 +42,7 @@
#include "factory/elementfactory.h"
#include "diagrampropertiesdialog.h"
#include "dveventinterface.h"
#include "diagrameventaddelement.h"
/**
Constructeur
@ -287,11 +288,15 @@ void DiagramView::handleElementDrop(QDropEvent *e) {
// verifie qu'il existe un element correspondant a cet emplacement
ElementsCollectionItem *dropped_item = QETApp::collectionItem(location);
if (!dropped_item) return;
diagram()->setEventInterface(new DiagramEventAddElement(location, diagram(), mapToScene(e->pos())));
//Set focus to the view to get event
this->setFocus();
next_location_ = location;
next_position_ = e-> pos();
// next_location_ = location;
// next_position_ = e-> pos();
emit(aboutToAddElement());
// emit(aboutToAddElement());
}
/**

View File

@ -75,6 +75,17 @@ void Element::setHighlighted(bool hl) {
update();
}
/**
* @brief Element::displayHelpLine
* Display the help line of each terminal if b is true
* @param b
*/
void Element::displayHelpLine(bool b)
{
foreach (Terminal *t, terminals())
t->drawHelpLine(b);
}
/**
Methode principale de dessin de l'element
@param painter Le QPainter utilise pour dessiner l'elment

View File

@ -139,19 +139,20 @@ class Element : public QetGraphicsItem {
Draw this element
*/
public:
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0;
/// @return This element type ID
virtual QString typeId() const = 0;
/// @return the human name for this element
virtual QString name() const = 0;
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0;
/// @return This element type ID
virtual QString typeId() const = 0;
/// @return the human name for this element
virtual QString name() const = 0;
virtual bool isHighlighted() const;
virtual void setHighlighted(bool);
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
QRectF boundingRect() const;
QSize setSize(int, int);
QSize size() const;
QPixmap pixmap();
virtual bool isHighlighted() const;
virtual void setHighlighted(bool);
void displayHelpLine(bool b = true);
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
QRectF boundingRect() const;
QSize setSize(int, int);
QSize size() const;
QPixmap pixmap();
// methods related to the hotspot
QPoint setHotspot(QPoint);

View File

@ -168,6 +168,27 @@ QETProject::~QETProject() {
delete undo_stack_;
}
/**
* @brief QETProject::integrateElementToProject
* Return true if we must to integarte the element to the project otherwise false
* @param location : element location
* @param project : project to test
* @return
*/
bool QETProject::integrateElementToProject(const ElementsLocation &location, const QETProject *project)
{
//Integration element must be enable
bool auto_integration_enabled = QETApp::settings().value("diagrameditor/integrate-elements", true).toBool();
//the element belongs there a project and if so, is this another project of the project given by parameter?
bool elmt_from_project = location.project();
bool elmt_from_another_project = elmt_from_project && location.project() != project;
bool must_integrate_element = (elmt_from_another_project || (auto_integration_enabled && !elmt_from_project));
return(must_integrate_element);
}
/**
Cette methode peut etre utilisee pour tester la bonne ouverture d'un projet
@return l'etat du projet

View File

@ -75,6 +75,8 @@ class QETProject : public QObject
ProjectParsingFailed = 4, /// the parsing of the XML content failed
FileOpenDiscard = 5 /// the user cancelled the file opening
};
static bool integrateElementToProject (const ElementsLocation &location, const QETProject *project);
// methods
public: