Implementation d'un menu reinitialiser les conducteurs modifies

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@161 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavierqet
2007-10-06 18:37:21 +00:00
parent d8f96e1ea9
commit 06d95fa90a
10 changed files with 111 additions and 6 deletions

View File

@@ -1001,6 +1001,11 @@ void Conductor::setProfile(const ConductorProfile &cp) {
calculateTextItemPosition(); calculateTextItemPosition();
} }
/// @return le profil de ce conducteur
ConductorProfile Conductor::profile() const {
return(conductor_profile);
}
bool Conductor::isSingleLine() const { bool Conductor::isSingleLine() const {
return(is_single_line); return(is_single_line);
} }

View File

@@ -70,6 +70,7 @@ class Conductor : public QGraphicsPathItem {
QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const; QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
const QList<ConductorSegment *> segmentsList() const; const QList<ConductorSegment *> segmentsList() const;
void setProfile(const ConductorProfile &); void setProfile(const ConductorProfile &);
ConductorProfile profile() const;
void setSingleLine(bool); void setSingleLine(bool);
bool isSingleLine() const; bool isSingleLine() const;

View File

@@ -388,6 +388,40 @@ void ChangeConductorCommand::redo() {
else conductor -> setProfile(new_profile); else conductor -> setProfile(new_profile);
} }
/**
Constructeur
@param c Conducteurs reinitialises
@param p Anciens profils des conducteurs
@param parent QUndoCommand parent
*/
ResetConductorCommand::ResetConductorCommand(
const QHash<Conductor *, ConductorProfile> &cp,
QUndoCommand *parent
) :
QUndoCommand(QObject::tr("R\351initialiser ") + QET::ElementsAndConductorsSentence(0, cp.count()), parent),
conductors_profiles(cp)
{
}
/// Destructeur
ResetConductorCommand::~ResetConductorCommand() {
}
/// Annule la reinitialisation des conducteurs
void ResetConductorCommand::undo() {
foreach(Conductor *c, conductors_profiles.keys()) {
c -> setProfile(conductors_profiles[c]);
}
}
/// Refait la reinitialisation des conducteurs
void ResetConductorCommand::redo() {
foreach(Conductor *c, conductors_profiles.keys()) {
ConductorProfile t(conductors_profiles[c]);
c -> setProfile(ConductorProfile());
}
}
/** /**
Constructeur Constructeur
@param d Schema dont on modifie le cartouche @param d Schema dont on modifie le cartouche

View File

@@ -225,16 +225,38 @@ class ChangeConductorCommand : public QUndoCommand {
// attributs // attributs
private: private:
/// DiagramTextItem modifie /// Conducteur modifie
Conductor *conductor; Conductor *conductor;
/// texte avant changement /// profil avant changement
ConductorProfile old_profile; ConductorProfile old_profile;
/// texte apres changement /// profil apres changement
ConductorProfile new_profile; ConductorProfile new_profile;
/// booleen pour ne pas executer le premier redo() /// booleen pour ne pas executer le premier redo()
bool first_redo; bool first_redo;
}; };
/**
Cette classe represente l'action de reinitialiser des conducteurs
*/
class ResetConductorCommand : public QUndoCommand {
// constructeurs, destructeur
public:
ResetConductorCommand(const QHash<Conductor *, ConductorProfile> &, QUndoCommand * = 0);
virtual ~ResetConductorCommand();
private:
ResetConductorCommand(const ResetConductorCommand &);
// methodes
public:
virtual void undo();
virtual void redo();
// attributs
private:
/// Conducteurs reinitialises et leurs anciens profils
QHash<Conductor *, ConductorProfile> conductors_profiles;
};
/** /**
Cette classe represente l'action de modifier les informations du cartouche d'un schema Cette classe represente l'action de modifier les informations du cartouche d'un schema
*/ */

View File

@@ -669,3 +669,21 @@ void DiagramView::editConductor() {
delete ccpc; delete ccpc;
} }
} }
/**
Reinitialise le profil des conducteurs selectionnes
*/
void DiagramView::resetConductors() {
// recupere les conducteurs selectionnes
QSet<Conductor *> selected_conductors = scene -> selectedConductors();
// repere les conducteurs modifies (= profil non nul)
QHash<Conductor *, ConductorProfile> conductors_and_profiles;
foreach(Conductor *conductor, selected_conductors) {
ConductorProfile profile = conductor -> profile();
if (!profile.isNull()) conductors_and_profiles.insert(conductor, profile);
}
if (conductors_and_profiles.isEmpty()) return;
scene -> undoStack().push(new ResetConductorCommand(conductors_and_profiles));
}

View File

@@ -74,6 +74,7 @@ class DiagramView : public QGraphicsView {
void adjustSceneRect(); void adjustSceneRect();
void updateWindowTitle(); void updateWindowTitle();
void editConductor(); void editConductor();
void resetConductors();
private slots: private slots:
void slot_selectionChanged(); void slot_selectionChanged();

BIN
ico/conductor2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

View File

@@ -13,6 +13,7 @@
<file>ico/category_new.png</file> <file>ico/category_new.png</file>
<file>ico/circle.png</file> <file>ico/circle.png</file>
<file>ico/conductor.png</file> <file>ico/conductor.png</file>
<file>ico/conductor2.png</file>
<file>ico/configure.png</file> <file>ico/configure.png</file>
<file>ico/copy.png</file> <file>ico/copy.png</file>
<file>ico/cut.png</file> <file>ico/cut.png</file>

View File

@@ -162,6 +162,7 @@ void QETDiagramEditor::actions() {
delete_selection = new QAction(QIcon(":/ico/delete.png"), tr("Supprimer"), this); delete_selection = new QAction(QIcon(":/ico/delete.png"), tr("Supprimer"), this);
rotate_selection = new QAction(QIcon(":/ico/pivoter.png"), tr("Pivoter"), this); rotate_selection = new QAction(QIcon(":/ico/pivoter.png"), tr("Pivoter"), this);
conductor_prop = new QAction(QIcon(":/ico/conductor.png"), tr("Propri\351t\351s du conducteur"), this); conductor_prop = new QAction(QIcon(":/ico/conductor.png"), tr("Propri\351t\351s du conducteur"), this);
conductor_reset = new QAction(QIcon(":/ico/conductor2.png"), tr("R\351initialiser les conducteurs"), this);
infos_diagram = new QAction(QIcon(":/ico/info.png"), tr("Informations sur le sch\351ma"), this); infos_diagram = new QAction(QIcon(":/ico/info.png"), tr("Informations sur le sch\351ma"), this);
add_column = new QAction(QIcon(":/ico/add_col.png"), tr("Ajouter une colonne"), this); add_column = new QAction(QIcon(":/ico/add_col.png"), tr("Ajouter une colonne"), this);
remove_column = new QAction(QIcon(":/ico/remove_col.png"), tr("Enlever une colonne"), this); remove_column = new QAction(QIcon(":/ico/remove_col.png"), tr("Enlever une colonne"), this);
@@ -210,6 +211,7 @@ void QETDiagramEditor::actions() {
delete_selection -> setShortcut(QKeySequence(tr("Suppr"))); delete_selection -> setShortcut(QKeySequence(tr("Suppr")));
rotate_selection -> setShortcut(QKeySequence(tr("Ctrl+R"))); rotate_selection -> setShortcut(QKeySequence(tr("Ctrl+R")));
conductor_prop -> setShortcut(QKeySequence(tr("Ctrl+J"))); conductor_prop -> setShortcut(QKeySequence(tr("Ctrl+J")));
conductor_reset -> setShortcut(QKeySequence(tr("Ctrl+K")));
zoom_in -> setShortcut(QKeySequence::ZoomIn); zoom_in -> setShortcut(QKeySequence::ZoomIn);
zoom_out -> setShortcut(QKeySequence::ZoomOut); zoom_out -> setShortcut(QKeySequence::ZoomOut);
@@ -314,6 +316,7 @@ void QETDiagramEditor::actions() {
connect(next_window, SIGNAL(triggered()), &workspace, SLOT(activateNextWindow()) ); connect(next_window, SIGNAL(triggered()), &workspace, SLOT(activateNextWindow()) );
connect(prev_window, SIGNAL(triggered()), &workspace, SLOT(activatePreviousWindow()) ); connect(prev_window, SIGNAL(triggered()), &workspace, SLOT(activatePreviousWindow()) );
connect(conductor_prop, SIGNAL(triggered()), this, SLOT(slot_editConductor()) ); connect(conductor_prop, SIGNAL(triggered()), this, SLOT(slot_editConductor()) );
connect(conductor_reset, SIGNAL(triggered()), this, SLOT(slot_resetConductors()) );
connect(infos_diagram, SIGNAL(triggered()), this, SLOT(slot_editInfos()) ); connect(infos_diagram, SIGNAL(triggered()), this, SLOT(slot_editInfos()) );
connect(add_column, SIGNAL(triggered()), this, SLOT(slot_addColumn()) ); connect(add_column, SIGNAL(triggered()), this, SLOT(slot_addColumn()) );
connect(remove_column, SIGNAL(triggered()), this, SLOT(slot_removeColumn()) ); connect(remove_column, SIGNAL(triggered()), this, SLOT(slot_removeColumn()) );
@@ -372,6 +375,7 @@ void QETDiagramEditor::menus() {
menu_edition -> addAction(rotate_selection); menu_edition -> addAction(rotate_selection);
menu_edition -> addSeparator(); menu_edition -> addSeparator();
menu_edition -> addAction(conductor_prop); menu_edition -> addAction(conductor_prop);
menu_edition -> addAction(conductor_reset);
menu_edition -> addSeparator(); menu_edition -> addSeparator();
menu_edition -> addAction(infos_diagram); menu_edition -> addAction(infos_diagram);
menu_edition -> addAction(add_column); menu_edition -> addAction(add_column);
@@ -653,6 +657,9 @@ void QETDiagramEditor::slot_updateActions() {
DiagramView *sv = currentDiagram(); DiagramView *sv = currentDiagram();
bool opened_document = (sv != 0); bool opened_document = (sv != 0);
// nombre de conducteurs selectionnes
int selected_conductors_count = opened_document ? sv -> diagram() -> selectedConductors().count() : 0;
// actions ayant juste besoin d'un document ouvert // actions ayant juste besoin d'un document ouvert
close_file -> setEnabled(opened_document); close_file -> setEnabled(opened_document);
save_file -> setEnabled(opened_document); save_file -> setEnabled(opened_document);
@@ -667,7 +674,8 @@ void QETDiagramEditor::slot_updateActions() {
zoom_out -> setEnabled(opened_document); zoom_out -> setEnabled(opened_document);
zoom_fit -> setEnabled(opened_document); zoom_fit -> setEnabled(opened_document);
zoom_reset -> setEnabled(opened_document); zoom_reset -> setEnabled(opened_document);
conductor_prop -> setEnabled(opened_document && sv -> diagram() -> selectedConductors().count() == 1); conductor_prop -> setEnabled(opened_document && selected_conductors_count == 1);
conductor_reset -> setEnabled(opened_document && selected_conductors_count);
infos_diagram -> setEnabled(opened_document); infos_diagram -> setEnabled(opened_document);
add_column -> setEnabled(opened_document); add_column -> setEnabled(opened_document);
remove_column -> setEnabled(opened_document); remove_column -> setEnabled(opened_document);
@@ -734,7 +742,7 @@ void QETDiagramEditor::addDiagramView(DiagramView *dv) {
// ajoute la fenetre // ajoute la fenetre
QWidget *p = workspace.addWindow(dv); QWidget *p = workspace.addWindow(dv);
connect(dv, SIGNAL(selectionChanged()), this, SLOT(slot_updateActions())); connect(dv -> diagram(), SIGNAL(selectionChanged()), this, SLOT(slot_updateActions()));
connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateActions())); connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateActions()));
// affiche la fenetre // affiche la fenetre
@@ -776,6 +784,7 @@ void QETDiagramEditor::slot_updateWindowsMenu() {
if (!windows.isEmpty()) windows_menu -> addSeparator(); if (!windows.isEmpty()) windows_menu -> addSeparator();
for (int i = 0 ; i < windows.size() ; ++ i) { for (int i = 0 ; i < windows.size() ; ++ i) {
DiagramView *dv = qobject_cast<DiagramView *>(windows.at(i)); DiagramView *dv = qobject_cast<DiagramView *>(windows.at(i));
if (!dv) continue;
QString dv_title = dv -> windowTitle().left(dv -> windowTitle().length() - 3); QString dv_title = dv -> windowTitle().left(dv -> windowTitle().length() - 3);
QAction *action = windows_menu -> addAction(dv_title); QAction *action = windows_menu -> addAction(dv_title);
action -> setStatusTip(tr("Active la fen\352tre ") + dv_title); action -> setStatusTip(tr("Active la fen\352tre ") + dv_title);
@@ -831,8 +840,20 @@ void QETDiagramEditor::slot_shrink() {
sv -> shrink(); sv -> shrink();
} }
/**
Edite les proprietes du conducteur selectionne
*/
void QETDiagramEditor::slot_editConductor() { void QETDiagramEditor::slot_editConductor() {
if (DiagramView *dv = currentDiagram()) { if (DiagramView *dv = currentDiagram()) {
dv -> editConductor(); dv -> editConductor();
} }
} }
/**
Reinitialise les conducteurs selectionnes
*/
void QETDiagramEditor::slot_resetConductors() {
if (DiagramView *dv = currentDiagram()) {
dv -> resetConductors();
}
}

View File

@@ -66,6 +66,7 @@ class QETDiagramEditor : public QMainWindow {
void slot_expand(); void slot_expand();
void slot_shrink(); void slot_shrink();
void slot_editConductor(); void slot_editConductor();
void slot_resetConductors();
// attributs // attributs
protected: protected:
@@ -92,6 +93,7 @@ class QETDiagramEditor : public QMainWindow {
QAction *delete_selection; QAction *delete_selection;
QAction *rotate_selection; QAction *rotate_selection;
QAction *conductor_prop; QAction *conductor_prop;
QAction *conductor_reset;
QAction *infos_diagram; QAction *infos_diagram;
QAction *add_column; QAction *add_column;
QAction *remove_column; QAction *remove_column;