Revert Rev 2096.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2097 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
scorpio810 2013-04-10 11:10:02 +00:00
parent 26a0ead2b0
commit c639d69108
6 changed files with 113 additions and 205 deletions

View File

@ -1264,22 +1264,8 @@ void Conductor::displayedTextChanged() {
// verifie que le texte a reellement change // verifie que le texte a reellement change
if (text_item -> toPlainText() == properties_.text) return; if (text_item -> toPlainText() == properties_.text) return;
if (Diagram *my_diagram = diagram()) {
int qmbreturn=0;
//if conductor isn't alone at this potential
//ask user to apply text on every conductors of this potential
if (relatedPotentialConductors().size() >= 1){
qmbreturn = QMessageBox::question(diagramEditor(), tr("Textes de conducteurs"),
tr("Voulez-vous appliquer le nouveau texte \n"
"\340 l'ensemble des conducteurs de ce potentiel ?"),
QMessageBox::No| QMessageBox::Yes, QMessageBox::Yes);
if (qmbreturn == QMessageBox::Yes){
ConductorAutoNumerotation can(this);
can.setText(text_item -> toPlainText());
}
}
if (qmbreturn == 0 || qmbreturn == QMessageBox::No) {
// initialise l'objet UndoCommand correspondant // initialise l'objet UndoCommand correspondant
if (Diagram *my_diagram = diagram()) {
ConductorProperties new_properties(properties_); ConductorProperties new_properties(properties_);
new_properties.text = text_item -> toPlainText(); new_properties.text = text_item -> toPlainText();
@ -1288,7 +1274,6 @@ void Conductor::displayedTextChanged() {
ccpc -> setNewSettings(new_properties); ccpc -> setNewSettings(new_properties);
my_diagram -> undoStack().push(ccpc); my_diagram -> undoStack().push(ccpc);
} }
}
} }
/** /**

View File

@ -1,9 +1,9 @@
#include <QStringList> #include <QStringList>
#include "conductorautonumerotation.h" #include "conductorautonumerotation.h"
#include "conductorautonumerotationwidget.h" #include "conductorautonumerotationwidget.h"
#include "diagram.h"
#include "qetdiagrameditor.h" #include "qetdiagrameditor.h"
#include "QGraphicsView" #include "QGraphicsView"
#include "diagramcommands.h"
/** /**
* Constructor * Constructor
@ -11,23 +11,19 @@
ConductorAutoNumerotation::ConductorAutoNumerotation() : ConductorAutoNumerotation::ConductorAutoNumerotation() :
conductor_ (0), conductor_ (0),
diagram_ (0), diagram_ (0),
strategy_ (0), strategy_(0)
strategy_is_set (false)
{} {}
/** /**
*Constructor *Constructor
* @param c the conductor to apply automatic numerotation * @param c le conducteur a appliquer une numerotation
*/ */
ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *c) : ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *c) :
conductor_ (c), conductor_ (c),
diagram_ (c -> diagram()), diagram_ (c -> diagram()),
conductor_list(c -> relatedPotentialConductors()), conductor_list(c -> relatedPotentialConductors()),
strategy_ (0), strategy_(0)
strategy_is_set (false) {}
{
setNumStrategy();
}
/** /**
*destructor *destructor
@ -37,136 +33,69 @@ ConductorAutoNumerotation::~ConductorAutoNumerotation() {
} }
/** /**
* @param c the conductor to apply automatic numerotation * @param c le conducteur a appliquer une numerotation
*/ */
void ConductorAutoNumerotation::setConductor(Conductor *c) { void ConductorAutoNumerotation::setConductor(Conductor *c) {
conductor_ = c; conductor_ = c;
diagram_ = c -> diagram(); diagram_ = c -> diagram();
strategy_ = 0;
conductor_list = c -> relatedPotentialConductors(); conductor_list = c -> relatedPotentialConductors();
setNumStrategy();
} }
/** /**
* @brief ConductorAutoNumerotation::numerate * @brief ConductorAutoNumerotation::numerate
* execute the automatic numerotation *execute la numerotation automatique du conducteur
*/ */
void ConductorAutoNumerotation::numerate() { void ConductorAutoNumerotation::numerate() {
if (strategy_is_set) if (conductor_ == 0) return;
strategy_ -> createNumerotation(); //ce conducteur est sur un potentiel existant
} if (conductor_list.size() >= 1) {
setNumStrategy(new SamePotential);
/** strategy_ -> createNumerotation(conductor_, diagram_);
* @brief ConductorAutoNumerotation::setText }
* apply the text @t by the strategy //ce conducteur est le premier d'un nouveau potentiel
*/ else if (conductor_list.size() == 0) {
void ConductorAutoNumerotation::setText(QString t) { }
if (strategy_is_set)
strategy_ -> applyText(t);
} }
/** /**
* @brief ConductorAutoNumerotation::setNumStrategy * @brief ConductorAutoNumerotation::setNumStrategy
* apply the good strategy relative to the conductor *applique la strategy adéquate à la situation
* @param strategy la class de la strategy à appliquer
*/ */
void ConductorAutoNumerotation::setNumStrategy() { void ConductorAutoNumerotation::setNumStrategy(NumStrategy *strategy) {
if (strategy_ != 0) if (strategy_ != 0)
delete strategy_; delete strategy_;
strategy_ = strategy;
if (conductor_list.size() >= 1) {
strategy_ = new SamePotential (conductor_);
strategy_is_set = true;
}
else if (conductor_list.size() == 0) {
strategy_is_set = false;
}
} }
NumStrategy::NumStrategy () {}
/**
* Constructor
*/
NumStrategy::NumStrategy (Conductor *c):
conductor_ (c),
c_list (c -> relatedPotentialConductors()),
diagram_ (c -> diagram())
{}
NumStrategy::~NumStrategy() {} NumStrategy::~NumStrategy() {}
/**
* @brief ConductorAutoNumerotationWidget::applyText
*apply the text @t on every conductors of @c_list and @conductor_
*/
void NumStrategy::applyText(QString t) {
if (!c_list.empty()) {
QSet <Conductor *> conductorslist = c_list;
conductorslist << conductor_;
QList <ConductorProperties> old_properties, new_properties;
ConductorProperties cp;
foreach (Conductor *c, conductorslist) {
old_properties << c -> properties();
cp = c -> properties();
cp.text = t;
c -> setProperties(cp);
new_properties << c -> properties();
c -> setText(t);
}
//initialize the corresponding UndoCommand object
ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(conductorslist);
cscpc -> setOldSettings(old_properties);
cscpc -> setNewSettings(new_properties);
diagram_ -> undoStack().push(cscpc);
}
else {
//initialize the corresponding UndoCommand object
ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand (conductor_);
ConductorProperties cp;
cp = conductor_ ->properties();
ccpc -> setOldSettings(cp);
cp.text = t;
ccpc -> setNewSettings(cp);
diagram_ -> undoStack().push(ccpc);
conductor_ -> setProperties(cp);
conductor_ -> setText(t);
}
}
/**
* Constructor
*/
SamePotential::SamePotential(Conductor *c):
NumStrategy(c)
{}
/** /**
* @brief SamePotential::createNumerotation * @brief SamePotential::createNumerotation
*create the numerotation for the conductor @c connected on an existing potential *crée la numerotation pour le conducteur @c connecté sur un potentiel deja existant
*/ */
void SamePotential::createNumerotation() { void SamePotential::createNumerotation(Conductor *c, Diagram *d) {
QSet <Conductor *> cl;
QStringList strl; QStringList strl;
foreach (const Conductor *cc, c_list) strl<<(cc->text()); cl = c -> relatedPotentialConductors();
//the texts is identicals foreach (const Conductor *cc, cl) strl<<(cc->text());
//tout les textes sont identique
if (eachIsEqual(strl)) { if (eachIsEqual(strl)) {
ConductorProperties cp; ConductorProperties cp;
cp.text = strl.at(0); cp.text = strl.at(0);
conductor_ -> setProperties(cp); c -> setProperties(cp);
conductor_ -> setText(strl.at(0)); c -> setText(strl.at(0));
} }
//the texts isn't identicals //les textes ne sont pas identique
else { else {
ConductorAutoNumerotationWidget *canw = new ConductorAutoNumerotationWidget(conductor_, c_list, conductor_ -> diagramEditor()); ConductorAutoNumerotationWidget canw (c, cl, c -> diagramEditor());
connect(canw, SIGNAL(textIsSelected(QString)), canw.exec();
this, SLOT(applyText(QString)));
canw -> exec();
} }
} }
/**
* @return true if every text of qsl is identical, else false.
*/
bool eachIsEqual (const QStringList &qsl) { bool eachIsEqual (const QStringList &qsl) {
foreach (const QString t, qsl) { foreach (const QString t, qsl) {
if (qsl.at(0) != t) return false; if (qsl.at(0) != t) return false;

View File

@ -1,9 +1,7 @@
#ifndef CONDUCTORAUTONUMEROTATION_H #ifndef CONDUCTORAUTONUMEROTATION_H
#define CONDUCTORAUTONUMEROTATION_H #define CONDUCTORAUTONUMEROTATION_H
#include <QObject> #include <conductor.h>
#include "conductor.h"
#include "diagram.h"
class NumStrategy; class NumStrategy;
@ -18,48 +16,32 @@ class ConductorAutoNumerotation
//methods //methods
void setConductor(Conductor *); void setConductor(Conductor *);
void numerate(); void numerate();
void setText(QString);
protected: protected:
//methods //methods
void setNumStrategy (); void setNumStrategy (NumStrategy *);
//attributes //attributes
Conductor *conductor_; Conductor *conductor_;
Diagram *diagram_; Diagram *diagram_;
QSet <Conductor *> conductor_list; QSet <Conductor *> conductor_list;
NumStrategy *strategy_; NumStrategy *strategy_;
private:
bool strategy_is_set;
}; };
class NumStrategy: public QObject class NumStrategy
{ {
Q_OBJECT
public: public:
NumStrategy (Conductor *); NumStrategy ();
virtual ~NumStrategy (); virtual ~NumStrategy ();
virtual void createNumerotation() = 0; //cree la numerotation en fonction de la strategie utilisé virtual void createNumerotation(Conductor *, Diagram *) = 0; //cree la numerotation en fonction de la strategie utilisé
public slots:
void applyText(QString);
protected:
Conductor *conductor_;
QSet <Conductor *> c_list;
Diagram *diagram_;
}; };
class SamePotential: public NumStrategy class SamePotential: public NumStrategy
{ {
public: virtual void createNumerotation(Conductor *, Diagram *);
SamePotential (Conductor *);
virtual void createNumerotation();
}; };
bool eachIsEqual (const QStringList &); bool eachIsEqual (const QStringList &);

View File

@ -1,8 +1,8 @@
#include "conductorautonumerotationwidget.h" #include "conductorautonumerotationwidget.h"
#include "conductorproperties.h"
#include "diagramcommands.h"
#include "diagram.h"
/**
* constructor
*/
ConductorAutoNumerotationWidget::ConductorAutoNumerotationWidget(Conductor *c, QSet<Conductor *> cl, QWidget *parent) : ConductorAutoNumerotationWidget::ConductorAutoNumerotationWidget(Conductor *c, QSet<Conductor *> cl, QWidget *parent) :
QDialog (parent), QDialog (parent),
conductor_(c), conductor_(c),
@ -15,9 +15,6 @@ ConductorAutoNumerotationWidget::ConductorAutoNumerotationWidget(Conductor *c, Q
buildInterface(); buildInterface();
} }
/**
* @brief ConductorAutoNumerotationWidget::buildInterface
*/
void ConductorAutoNumerotationWidget::buildInterface() { void ConductorAutoNumerotationWidget::buildInterface() {
QVBoxLayout *mainlayout = new QVBoxLayout; QVBoxLayout *mainlayout = new QVBoxLayout;
QGroupBox *potential_groupbox = new QGroupBox(tr("Textes de potentiel"), this); QGroupBox *potential_groupbox = new QGroupBox(tr("Textes de potentiel"), this);
@ -98,6 +95,31 @@ QMultiMap <int, QString> ConductorAutoNumerotationWidget::conductorsTextToMap(QS
return conductorlist; return conductorlist;
} }
/**
* @brief ConductorAutoNumerotationWidget::applyText
*applique le texte selectionne @text_ a tout les conducteur de @c_list et a @conducteur_
*/
void ConductorAutoNumerotationWidget::applyText() {
QSet <Conductor *> conductorslist = c_list;
conductorslist << conductor_;
QList <ConductorProperties> old_properties, new_properties;
ConductorProperties cp;
foreach (Conductor *c, conductorslist) {
old_properties << c -> properties();
cp = c -> properties();
cp.text = text_;
c -> setProperties(cp);
new_properties << c -> properties();
c -> setText(text_);
}
// initialise l'objet UndoCommand correspondant
ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(conductorslist);
cscpc -> setOldSettings(old_properties);
cscpc -> setNewSettings(new_properties);
diagram_ -> undoStack().push(cscpc);
}
/** /**
* @brief ConductorAutoNumerotationWidget::setText * @brief ConductorAutoNumerotationWidget::setText
* enregistre le texte @t passé en parametre * enregistre le texte @t passé en parametre
@ -112,9 +134,10 @@ void ConductorAutoNumerotationWidget::setText(QString t) {
*/ */
void ConductorAutoNumerotationWidget::accept() { void ConductorAutoNumerotationWidget::accept() {
if (text_field -> isEnabled()) { if (text_field -> isEnabled()) {
emit textIsSelected(text_field -> text()); text_ = text_field -> text();
applyText();
} }
else else
emit textIsSelected(text_); applyText();
close(); close();
} }

View File

@ -20,13 +20,11 @@ class ConductorAutoNumerotationWidget : public QDialog
void setText (QString); void setText (QString);
void accept(); void accept();
signals:
void textIsSelected (QString);
private: private:
//methods //methods
void buildInterface(); void buildInterface();
QVBoxLayout* buildRadioList(); QVBoxLayout* buildRadioList();
void applyText();
//attributes //attributes
Conductor *conductor_; Conductor *conductor_;

View File

@ -37,8 +37,7 @@
#include "qeticons.h" #include "qeticons.h"
#include "qetmessagebox.h" #include "qetmessagebox.h"
#include "qtextorientationspinboxwidget.h" #include "qtextorientationspinboxwidget.h"
#include "htmleditor/htmleditor.h"
#include "conductorautonumerotation.h"
/** /**
Constructeur Constructeur
@ -410,9 +409,8 @@ void DiagramView::pasteHere() {
} }
/** /**
Gere les clics et plus particulierement : Manage the events click mouse :
* le clic du milieu (= coller pour X11) * click to add an independent text field
* le clic pour ajouter un champ de texte independant
*/ */
void DiagramView::mousePressEvent(QMouseEvent *e) { void DiagramView::mousePressEvent(QMouseEvent *e) {
if (fresh_focus_in_) { if (fresh_focus_in_) {
@ -420,33 +418,40 @@ void DiagramView::mousePressEvent(QMouseEvent *e) {
fresh_focus_in_ = false; fresh_focus_in_ = false;
} }
if (isInteractive() && !scene -> isReadOnly()) { if (isInteractive() && !scene -> isReadOnly()) {
if (e -> buttons() == Qt::MidButton) {
paste(mapToScene(e -> pos()), QClipboard::Selection);
} else {
if (is_adding_text && e -> buttons() == Qt::LeftButton) { if (is_adding_text && e -> buttons() == Qt::LeftButton) {
addDiagramTextAtPos(mapToScene(e -> pos())); addDiagramTextAtPos(mapToScene(e -> pos()));
is_adding_text = false; is_adding_text = false;
} }
} }
}
QGraphicsView::mousePressEvent(e); QGraphicsView::mousePressEvent(e);
} }
/** /**
Gere les actions liees a la rollette de la souris Manage wheel event of mouse
@param e QWheelEvent decrivant l'evenement rollette @param e QWheelEvent
*/ */
void DiagramView::wheelEvent(QWheelEvent *e) { void DiagramView::wheelEvent(QWheelEvent *e) {
// si la touche Ctrl est enfoncee, on zoome / dezoome //Zoom and scrolling
if (e -> modifiers() & Qt::ControlModifier) { if (e->buttons() != Qt::MidButton) {
if (e -> delta() > 0) { if (!(e -> modifiers() & Qt::ControlModifier)) {
zoomIn(); if (e -> delta() > 0) zoomIn();
} else { else zoomOut();
zoomOut();
} }
} else { else {
QAbstractScrollArea::wheelEvent(e); QAbstractScrollArea::wheelEvent(e);
} }
}
// Or select visualisation or selection mode
else{
if (!is_moving_view_) {
setVisualisationMode();
is_moving_view_ = true;
}
else{
setSelectionMode();
is_moving_view_ = false;
}
}
} }
/** /**
@ -711,7 +716,7 @@ void DiagramView::updateWindowTitle() {
} }
/** /**
Active ou desactive le dessin de grille selon la quantite de pixels affichee Enables or disables the drawing grid according to the amount of pixels display
*/ */
void DiagramView::adjustGridToZoom() { void DiagramView::adjustGridToZoom() {
QRectF viewed_scene = viewedSceneRect(); QRectF viewed_scene = viewedSceneRect();
@ -977,21 +982,8 @@ void DiagramView::editConductor(Conductor *edited_conductor) {
if (conductor_dialog.exec() == QDialog::Accepted) { if (conductor_dialog.exec() == QDialog::Accepted) {
// recupere les nouvelles proprietes // recupere les nouvelles proprietes
ConductorProperties new_properties = cpw -> conductorProperties(); ConductorProperties new_properties = cpw -> conductorProperties();
if (new_properties != old_properties) { if (new_properties != old_properties) {
int qmbreturn=0;
//if conductor isn't alone at this potential
//ask user to apply text on every conductors of this potential
if (edited_conductor -> relatedPotentialConductors().size() >= 1){
qmbreturn = QMessageBox::question(diagramEditor(), tr("Textes de conducteurs"),
tr("Voulez-vous appliquer le nouveau texte \n"
"\340 l'ensemble des conducteurs de ce potentiel ?"),
QMessageBox::No| QMessageBox::Yes, QMessageBox::Yes);
if (qmbreturn == QMessageBox::Yes){
ConductorAutoNumerotation can(edited_conductor);
can.setText(new_properties.text);
}
}
if (qmbreturn == 0 || qmbreturn == QMessageBox::No) {
// initialise l'objet UndoCommand correspondant // initialise l'objet UndoCommand correspondant
ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(edited_conductor); ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(edited_conductor);
ccpc -> setOldSettings(old_properties); ccpc -> setOldSettings(old_properties);
@ -999,7 +991,6 @@ void DiagramView::editConductor(Conductor *edited_conductor) {
diagram() -> undoStack().push(ccpc); diagram() -> undoStack().push(ccpc);
} }
} }
}
} }
/** /**