diff --git a/sources/diagram.cpp b/sources/diagram.cpp index d6db7c30b..0c7284dfe 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -47,13 +47,13 @@ QColor Diagram::background_color = Qt::white; */ Diagram::Diagram(QObject *parent) : QGraphicsScene(parent), + project_(0), + diagram_qet_version_(-1), draw_grid_(true), use_border_(true), draw_terminals_(true), draw_colored_conductors_(true), - project_(0), - read_only_(false), - diagram_qet_version_(-1) + read_only_(false) { qgi_manager_ = new QGIManager(this); setBackgroundBrush(Qt::white); @@ -204,6 +204,22 @@ void Diagram::keyReleaseEvent(QKeyEvent *e) { } } +/** + * @brief Diagram::conductorsAutonumName + * @return the name of autonum to use. + */ +QString Diagram::conductorsAutonumName() const { + return m_conductors_autonum_name; +} + +/** + * @brief Diagram::setConductorsAutonumName + * @param name, name of autonum to use. + */ +void Diagram::setConductorsAutonumName(const QString &name) { + m_conductors_autonum_name= name; +} + /** Exporte le schema vers une image @return Une QImage representant le schema @@ -327,13 +343,6 @@ QDomDocument Diagram::toXml(bool whole_content) { QDomElement default_conductor = document.createElement("defaultconductor"); defaultConductorProperties.toXml(default_conductor); racine.appendChild(default_conductor); - - //autonumerotation of conductor - if (!getNumerotation(Diagram::Conductors).isEmpty()) { - QDomElement autonum = document.createElement("autonum"); - autonum.appendChild(getNumerotation(Diagram::Conductors).toXml(document, "conductor")); - racine.appendChild(autonum); - } } document.appendChild(racine); @@ -504,16 +513,6 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf if (!default_conductor_elmt.isNull()) { defaultConductorProperties.fromXml(default_conductor_elmt); } - // find the first element autonum - QDomElement num_auto = root.firstChildElement("autonum"); - if (!num_auto.isNull()) { - QDomElement num_conductor = num_auto.firstChildElement("conductor"); - //set the auto-numerotation of conductor - if (!num_conductor.isNull()) { - NumerotationContext nc(num_conductor); - setNumerotation(Diagram::Conductors, nc); - } - } } // si la racine n'a pas d'enfant : le chargement est fini (schema vide) diff --git a/sources/diagram.h b/sources/diagram.h index e9396004b..af03d0797 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -58,63 +58,72 @@ class Diagram : public QGraphicsScene { private: Diagram(const Diagram &diagram); - // attributes + // ATTRIBUTES public: - /** - Represents available options when rendering a particular diagram: - * EmptyBorder: display border only - * TitleBlock: display title block - * Columns: display columns - */ - enum BorderOptions { EmptyBorder, TitleBlock, Columns }; - /// Represents available option of Numerotation type. - enum NumerotationType { Conductors }; - /// Default properties for new conductors - ConductorProperties defaultConductorProperties; - /// Diagram dimensions and title block - BorderTitleBlock border_and_titleblock; - /// abscissa grid step size - static const int xGrid; - /// ordinate grid step size - static const int yGrid; - /// margin around the diagram - static const qreal margin; - /// background color of diagram - static QColor background_color; + /** + Represents available options when rendering a particular diagram: + * EmptyBorder: display border only + * TitleBlock: display title block + * Columns: display columns + */ + enum BorderOptions { EmptyBorder, TitleBlock, Columns }; + /// Represents available option of Numerotation type. + enum NumerotationType { Conductors }; + /// Default properties for new conductors + ConductorProperties defaultConductorProperties; + /// Diagram dimensions and title block + BorderTitleBlock border_and_titleblock; + /// abscissa grid step size + static const int xGrid; + /// ordinate grid step size + static const int yGrid; + /// margin around the diagram + static const qreal margin; + /// background color of diagram + static QColor background_color; + private: - QGraphicsLineItem *conductor_setter_; - ElementsMover *elements_mover_; - ElementTextsMover *element_texts_mover_; - bool draw_grid_; - bool use_border_; - QGIManager *qgi_manager_; - bool draw_terminals_; - bool draw_colored_conductors_; - QDomDocument xml_document_; - QETProject *project_; - bool read_only_; - qreal diagram_qet_version_; - QHash numerotation_; + QGraphicsLineItem *conductor_setter_; + ElementsMover *elements_mover_; + ElementTextsMover *element_texts_mover_; + QGIManager *qgi_manager_; + QETProject *project_; + + QDomDocument xml_document_; + + qreal diagram_qet_version_; + + bool draw_grid_; + bool use_border_; + bool draw_terminals_; + bool draw_colored_conductors_; + bool read_only_; + + QString m_conductors_autonum_name; - // methods + // METHODS protected: - virtual void drawBackground(QPainter *, const QRectF &); - virtual void keyPressEvent(QKeyEvent *); - virtual void keyReleaseEvent(QKeyEvent *); + virtual void drawBackground(QPainter *, const QRectF &); + virtual void keyPressEvent(QKeyEvent *); + virtual void keyReleaseEvent(QKeyEvent *); public: - QString defaultReportProperties () const {return project_ -> defaultReportProperties();} - XRefProperties defaultXRefProperties (const QString &str) const {return project_ -> defaultXRefProperties(str);} - static bool clipboardMayContainDiagram(); - bool setNumerotation (NumerotationType, NumerotationContext); - NumerotationContext getNumerotation (NumerotationType) const; + //methods related to xref properties + QString defaultReportProperties () const {return project_ -> defaultReportProperties();} + XRefProperties defaultXRefProperties (const QString &str) const {return project_ -> defaultXRefProperties(str);} + + //methods related to autonum + QString conductorsAutonumName() const; + void setConductorsAutonumName(const QString &name); + + static bool clipboardMayContainDiagram(); - // methods related to parent project - QETProject *project() const; - void setProject(QETProject *); - int folioIndex() const; - qreal declaredQElectroTechVersion(bool = true) const; - void showMe() {emit showDiagram(this);} + // methods related to parent project + QETProject *project() const; + void setProject(QETProject *); + int folioIndex() const; + qreal declaredQElectroTechVersion(bool = true) const; + void showMe() {emit showDiagram(this);} // methods related to read only mode bool isReadOnly() const; @@ -217,31 +226,6 @@ class Diagram : public QGraphicsScene { }; Q_DECLARE_METATYPE(Diagram *) -/** - * @brief Diagram::setNumerotation, store a numerotation type - * @return true if storage is available - */ -inline bool Diagram::setNumerotation(Diagram::NumerotationType type, NumerotationContext context) { - switch (type) { - case Conductors: - numerotation_.insert(type, context); - return true; - break; - default: - return false; - break; - } -} - -/** - * @brief Diagram::getNumerotation - * @return the NumerotationContext associated with the key. - * If numerotation_ contains no item with the key, the function returns a default-constructed NumerotationContext - */ -inline NumerotationContext Diagram::getNumerotation(Diagram::NumerotationType type) const { - return numerotation_.value(type); -} - /** Display or hide the conductor setter, i.e. a dashed conductor stub which appears when creating a conductor between two terminals. @param pf true pour ajouter le poseur de conducteur, false pour l'enlever diff --git a/sources/diagramcommands.h b/sources/diagramcommands.h index 50062e841..2c2e7d2ef 100644 --- a/sources/diagramcommands.h +++ b/sources/diagramcommands.h @@ -147,22 +147,22 @@ class AddShapeCommand : public QUndoCommand { class AddConductorCommand : public QUndoCommand { // constructors, destructor public: - AddConductorCommand(Diagram *, Conductor *, QUndoCommand * = 0); - virtual ~AddConductorCommand(); + AddConductorCommand(Diagram *, Conductor *, QUndoCommand * = 0); + virtual ~AddConductorCommand(); private: - AddConductorCommand(const AddConductorCommand &); + AddConductorCommand(const AddConductorCommand &); // methods public: - virtual void undo(); - virtual void redo(); + virtual void undo(); + virtual void redo(); // attributes private: - /// added conductor - Conductor *conductor; - /// diagram the conductor is added to - Diagram *diagram; + /// added conductor + Conductor *conductor; + /// diagram the conductor is added to + Diagram *diagram; }; /** diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index d498a703b..cd1e2cda7 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -1289,7 +1289,6 @@ void DiagramView::contextMenuEvent(QContextMenuEvent *e) { context_menu -> addAction(paste_here); context_menu -> addSeparator(); context_menu -> addAction(qde -> infos_diagram); - context_menu -> addAction(qde -> prj_diagramNum); context_menu -> addActions(qde -> m_row_column_actions_group.actions()); } else { context_menu -> addAction(qde -> cut); diff --git a/sources/projectconfigpages.cpp b/sources/projectconfigpages.cpp index 6e1f4832b..d96dfdee6 100644 --- a/sources/projectconfigpages.cpp +++ b/sources/projectconfigpages.cpp @@ -25,6 +25,8 @@ #include #include "ui/reportpropertiewidget.h" #include "ui/xrefpropertieswidget.h" +#include "selectautonumw.h" +#include "numerotationcontext.h" /** Constructor @@ -89,6 +91,8 @@ void ProjectConfigPage::init() { } } +//######################################################################################// + /** Constructor @param project Project this page is editing. @@ -201,6 +205,8 @@ void ProjectMainConfigPage::adjustReadOnly() { title_value_ -> setReadOnly(is_read_only); } +//######################################################################################// + /** Constructor @param project Project this page is editing. @@ -335,3 +341,134 @@ void ProjectNewDiagramConfigPage::adjustReadOnly() { conductor_ -> setReadOnly(is_read_only); xref_ -> setReadOnly(is_read_only); } + +//######################################################################################// + +/** + * @brief ProjectAutoNumConfigPage::ProjectAutoNumConfigPage + * Default constructor + * @param project, project to edit + * @param parent, parent widget + */ +ProjectAutoNumConfigPage::ProjectAutoNumConfigPage (QETProject *project, QWidget *parent) : + ProjectConfigPage(project, parent) +{ + initWidgets(); + initLayout(); + buildConnections(); + readValuesFromProject(); +} + +/** + * @brief ProjectAutoNumConfigPage::title + * Title of this config page + * @return + */ +QString ProjectAutoNumConfigPage::title() const { + return tr("Auto numerotation"); +} + +/** + * @brief ProjectAutoNumConfigPage::icon + * Icon of this config pafe + * @return + */ +QIcon ProjectAutoNumConfigPage::icon() const { + return QIcon (); +} + +/** + * @brief ProjectAutoNumConfigPage::applyProjectConf + */ +void ProjectAutoNumConfigPage::applyProjectConf() {} + +/** + * @brief ProjectAutoNumConfigPage::initWidgets + * Init some widget of this page + */ +void ProjectAutoNumConfigPage::initWidgets() { + m_label = new QLabel(tr("Num\351rotations disponibles :", "availables numerotations"), this); + m_context_cb = new QComboBox(this); + m_context_cb->addItem(tr("Nouveau")); + m_name_le = new QLineEdit(this); + m_name_le->setPlaceholderText(tr("Nom de la nouvelle num\351rotation")); + + m_saw = new SelectAutonumW(this); +} + +/** + * @brief ProjectAutoNumConfigPage::initLayout + * Init the layout of this page + */ +void ProjectAutoNumConfigPage::initLayout() { + QHBoxLayout *context_layout = new QHBoxLayout(); + context_layout -> addWidget (m_label); + context_layout -> addWidget (m_context_cb); + context_layout -> addWidget (m_name_le); + + QVBoxLayout *main_layout = new QVBoxLayout(this); + this -> setLayout (main_layout); + main_layout -> addLayout (context_layout); + main_layout -> addWidget (m_saw); +} + +/** + * @brief ProjectAutoNumConfigPage::readValuesFromProject + * Read value stored on project, and update display + */ +void ProjectAutoNumConfigPage::readValuesFromProject() { + QList keys = project_->conductorAutoNum().keys(); + if (keys.isEmpty()) return; + foreach (QString str, keys) { m_context_cb -> addItem(str); } +} + +/** + * @brief ProjectAutoNumConfigPage::adjustReadOnly + * set this config page disable if project is read only + */ +void ProjectAutoNumConfigPage::adjustReadOnly() { +} + +/** + * @brief ProjectAutoNumConfigPage::buildConnections + * setup some connections + */ +void ProjectAutoNumConfigPage::buildConnections() { + connect(m_context_cb, SIGNAL (currentIndexChanged(QString)), this, SLOT (updateContext(QString))); + connect(m_saw, SIGNAL (applyPressed()), this, SLOT (saveContext())); +} + +/** + * @brief ProjectAutoNumConfigPage::updateContext + * Display the current selected context + * @param str, key of context stored in project + */ +void ProjectAutoNumConfigPage::updateContext(QString str) { + if (str == tr("Nouveau")) { + m_saw -> setContext(NumerotationContext()); + m_name_le -> setText(QString()); + m_name_le ->setEnabled(true); + } + else { + m_saw ->setContext(project_->conductorAutoNum(str)); + m_name_le -> setText(str); + m_name_le -> setDisabled(true); + } +} + +/** + * @brief ProjectAutoNumConfigPage::saveContext + * Save the current displayed context in project + */ +void ProjectAutoNumConfigPage::saveContext() { + if (m_context_cb->currentText() == tr("Nouveau")) { + if (m_name_le->text().isEmpty()) { + m_name_le->setText(tr("Nouvel num\351rotation")); + } + project_->addConductorAutoNum(m_name_le -> text(), m_saw -> toNumContext()); + m_context_cb -> addItem(m_name_le -> text()); + } + else { + project_->addConductorAutoNum (m_context_cb -> currentText(), m_saw -> toNumContext()); + } +} diff --git a/sources/projectconfigpages.h b/sources/projectconfigpages.h index 9358ab226..cd1c78071 100644 --- a/sources/projectconfigpages.h +++ b/sources/projectconfigpages.h @@ -1,3 +1,5 @@ + + /* Copyright 2006-2014 The QElectroTech Team This file is part of QElectroTech. @@ -27,6 +29,8 @@ class ConductorPropertiesWidget; class DiagramContextWidget; class ReportPropertieWidget; class XRefPropertiesWidget; +class SelectAutonumW; +class QComboBox; /** This class, derived from ConfigPage, aims at providing the basic skeleton @@ -148,4 +152,37 @@ class ProjectNewDiagramConfigPage : public ProjectConfigPage { XRefPropertiesWidget *xref_; }; +class ProjectAutoNumConfigPage : public ProjectConfigPage { + Q_OBJECT + + //Methods + public: + ProjectAutoNumConfigPage (QETProject *project, QWidget *parent = 0); + + virtual QString title() const; + virtual QIcon icon() const; + virtual void applyProjectConf(); + + protected: + virtual void initWidgets(); + virtual void initLayout(); + virtual void readValuesFromProject(); + virtual void adjustReadOnly(); + + private: + void buildConnections(); + + private slots: + void updateContext(QString); + void saveContext(); + + //Attributes + private: + QLabel *m_label; + QLineEdit *m_name_le; + QComboBox *m_context_cb; + SelectAutonumW *m_saw; + +}; + #endif diff --git a/sources/projectview.cpp b/sources/projectview.cpp index 54e6b03e0..5de4776ae 100644 --- a/sources/projectview.cpp +++ b/sources/projectview.cpp @@ -447,8 +447,9 @@ void ProjectView::editProjectProperties() { ConfigDialog properties_dialog(parentWidget()); properties_dialog.setWindowTitle(tr("Propri\351t\351s du projet", "window title")); - properties_dialog.addPage(new ProjectMainConfigPage(project_)); - properties_dialog.addPage(new ProjectNewDiagramConfigPage(project_)); + properties_dialog.addPage(new ProjectMainConfigPage (project_)); + properties_dialog.addPage(new ProjectNewDiagramConfigPage (project_)); + properties_dialog.addPage(new ProjectAutoNumConfigPage (project_)); properties_dialog.exec(); } diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 25bba28d5..e56116c74 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -208,7 +208,6 @@ void QETDiagramEditor::actions() { prj_add_diagram = new QAction(QET::Icons::DiagramAdd, tr("Ajouter un sch\351ma"), this); prj_del_diagram = new QAction(QET::Icons::DiagramDelete, tr("Supprimer le sch\351ma"), this); prj_clean = new QAction(QET::Icons::EditClear, tr("Nettoyer le projet"), this); - prj_diagramNum = new QAction(QET::Icons::ConductorSettings, tr("Annoter les sch\351mas"), this); prj_diagramList = new QAction(QET::Icons::listDrawings, tr("Ajouter un sommaire"), this); prj_nomenclature = new QAction(QET::Icons::DocumentExport, tr("Exporter une nomenclature (beta)"), this); tabbed_view_mode = new QAction( tr("en utilisant des onglets"), this); @@ -424,7 +423,6 @@ void QETDiagramEditor::actions() { connect(prj_add_diagram, SIGNAL(triggered()), this, SLOT(addDiagramToProject()) ); connect(prj_del_diagram, SIGNAL(triggered()), this, SLOT(removeDiagramFromProject()) ); connect(prj_clean, SIGNAL(triggered()), this, SLOT(cleanCurrentProject()) ); - connect(prj_diagramNum, SIGNAL(triggered()), this, SLOT(diagramNumProject()) ); connect(prj_diagramList, SIGNAL(triggered()), this, SLOT(addDiagramFolioListToProject())); connect(prj_nomenclature, SIGNAL(triggered()), this, SLOT(nomenclatureProject()) ); connect(print, SIGNAL(triggered()), this, SLOT(printDialog()) ); @@ -512,7 +510,6 @@ void QETDiagramEditor::menus() { menu_project -> addAction(prj_del_diagram); menu_project -> addAction(prj_clean); menu_project -> addSeparator(); - menu_project -> addAction(prj_diagramNum); menu_project -> addAction(prj_diagramList); menu_project -> addAction(prj_nomenclature); @@ -1152,7 +1149,6 @@ void QETDiagramEditor::slot_updateActions() { //prj_add_diagram_foliolist -> setEnabled(editable_project); prj_del_diagram -> setEnabled(editable_project); prj_clean -> setEnabled(editable_project); - prj_diagramNum -> setEnabled(editable_project); prj_diagramList -> setEnabled(opened_project); prj_nomenclature -> setEnabled(editable_project); export_diagram -> setEnabled(opened_diagram); @@ -1207,7 +1203,6 @@ void QETDiagramEditor::slot_updateComplexActions() { delete_selection -> setEnabled(editable_diagram && deletable_items); rotate_selection -> setEnabled(editable_diagram && dv -> diagram() -> canRotateSelection()); selection_prop -> setEnabled(deletable_items); - prj_diagramNum -> setEnabled(editable_diagram); // actions ayant besoin de textes selectionnes int selected_texts = dv ? (dv -> diagram() -> selectedTexts().count()) : 0; @@ -1810,17 +1805,6 @@ void QETDiagramEditor::cleanCurrentProject() { } } -/** - * @brief launch dialog for numerate diagram - */ -void QETDiagramEditor::diagramNumProject() { - DialogAutoNum *dg = new DialogAutoNum(currentDiagram()->diagram(), this); - dg->setModal(true); - dg->exec(); - - delete dg; -} - /** * @brief export nomemclature of schema */ diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index 6e6995fef..d0716916f 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -157,7 +157,6 @@ class QETDiagramEditor : public QETMainWindow { void moveDiagramUp(Diagram *); void moveDiagramDown(Diagram *); void cleanCurrentProject(); - void diagramNumProject(); void nomenclatureProject(); void diagramWasAdded(DiagramView *); void diagramIsAboutToBeRemoved(DiagramView *); @@ -194,7 +193,6 @@ class QETDiagramEditor : public QETMainWindow { QAction *prj_add_diagram; ///< Add a diagram to the current project. QAction *prj_del_diagram; ///< Delete a diagram from the current project QAction *prj_clean; ///< Clean the content of the curent project by removing useless items - QAction *prj_diagramNum; ///< Numerotation des schemas QAction *prj_diagramList; ///< Sommaire des schemas QAction *prj_nomenclature; ///< generate nomenclature QAction *tile_window; ///< Show MDI subwindows as tile diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 275d0211e..386deded3 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -23,9 +23,9 @@ #include "element.h" #include "diagram.h" #include "diagramcommands.h" -#include "conductorautonumerotation.h" #include "qetdiagrameditor.h" #include "terminal.h" +#include "conductorautonumerotation.h" #define PR(x) qDebug() << #x " = " << x; bool Conductor::pen_and_brush_initialized = false; @@ -984,7 +984,7 @@ bool Conductor::fromXml(QDomElement &e) { segments_y << segment_length; } } - + // s'il n'y a pas de segments, on renvoie true if (!segments_x.size()) return(true); // les longueurs recueillies doivent etre coherentes avec les positions des bornes @@ -1320,11 +1320,6 @@ QSet Conductor::relatedConductors() const { return(other_conductors); } -/** - * @param t_list terminaux a ne pas inclure dans la recherche - * @return les conducteurs avec lesquels ce conducteur partage - * le meme potentiel electrique a l'exception de lui même - */ /** * @brief Conductor::relatedPotentialConductors * Return all conductors at the same potential of this conductor, this conductor isn't @@ -1340,9 +1335,8 @@ QSet Conductor::relatedPotentialConductors(QList *t_li } QSet other_conductors; - // QList this_terminal{terminal1, terminal2}; QList this_terminal; - this_terminal << terminal1 << terminal2; + this_terminal << terminal1 << terminal2; // Return all conductor of terminal 1 and 2 foreach (Terminal *terminal, this_terminal) { diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 5dc92d7a6..075b5f964 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -30,6 +30,7 @@ #include "qetmessagebox.h" #include "titleblocktemplate.h" #include "ui/dialogwaiting.h" +#include "numerotationcontext.h" QString QETProject::integration_category_name = "import"; @@ -461,6 +462,36 @@ void QETProject::setDefaultXRefProperties(QHash hash) { emit XRefPropertiesChanged(); } +/** + * @brief QETProject::conductorAutoNum + * @return All value of conductor autonum stored in project + */ +QHash QETProject::conductorAutoNum() const { + return m_conductor_autonum; +} + +/** + * @brief QETProject::addConductorAutoNum + * Add a new numerotation context. If key already exist, + * replace old context by the new context + * @param key + * @param context + */ +void QETProject::addConductorAutoNum(QString key, NumerotationContext context) { + m_conductor_autonum.insert(key, context); +} + +/** + * @brief QETProject::conductorAutoNum + * Return the numerotation context stored with @key. + * If key is not found, return an empty numerotation context + * @param key + */ +NumerotationContext QETProject::conductorAutoNum (const QString &key) const { + if (m_conductor_autonum.contains(key)) return m_conductor_autonum[key]; + else return NumerotationContext(); +} + /** @return un document XML representant le projet */ @@ -1167,7 +1198,7 @@ void QETProject::readDefaultPropertiesXml() { m_default_xref_properties = QETDiagramEditor::defaultXRefProperties(); //Read values indicate in project - QDomElement border_elmt, titleblock_elmt, conductors_elmt, report_elmt, xref_elmt; + QDomElement border_elmt, titleblock_elmt, conductors_elmt, report_elmt, xref_elmt, conds_autonums; for (QDomNode child = newdiagrams_elmt.firstChild() ; !child.isNull() ; child = child.nextSibling()) { QDomElement child_elmt = child.toElement(); @@ -1182,10 +1213,12 @@ void QETProject::readDefaultPropertiesXml() { report_elmt = child_elmt; } else if (child_elmt.tagName() == "xrefs") { xref_elmt = child_elmt; + } else if (child_elmt.tagName() == "conductors_autonums") { + conds_autonums = child_elmt; } } - // size, titleblock, conductor, report + // size, titleblock, conductor, report, conductor autonum if (!border_elmt.isNull()) default_border_properties_.fromXml(border_elmt); if (!titleblock_elmt.isNull()) default_titleblock_properties_.fromXml(titleblock_elmt); if (!conductors_elmt.isNull()) default_conductor_properties_.fromXml(conductors_elmt); @@ -1197,6 +1230,13 @@ void QETProject::readDefaultPropertiesXml() { m_default_xref_properties.insert(elmt.attribute("type"), xrp); } } + if (!conds_autonums.isNull()) { + foreach (QDomElement elmt, QET::findInDomElement(conds_autonums, "conductor_autonum")) { + NumerotationContext nc; + nc.fromXml(elmt); + m_conductor_autonum.insert(elmt.attribute("title"), nc); + } + } } @@ -1241,8 +1281,16 @@ void QETProject::writeDefaultPropertiesXml(QDomElement &xml_element) { defaultXRefProperties()[key].toXml(xref_elmt); xrefs_elmt.appendChild(xref_elmt); } - xml_element.appendChild(xrefs_elmt); + + //Export conductors autonums + QDomElement conds_autonums = xml_document.createElement("conductors_autonums"); + foreach (QString key, conductorAutoNum().keys()) { + QDomElement cond_autonum = conductorAutoNum(key).toXml(xml_document, "conductor_autonum"); + cond_autonum.setAttribute("title", key); + conds_autonums.appendChild(cond_autonum); + } + xml_element.appendChild(conds_autonums); } /** diff --git a/sources/qetproject.h b/sources/qetproject.h index b9d204213..7735dde8b 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -37,6 +37,7 @@ class TitleBlockTemplate; class XmlElementsCollection; class MoveElementsHandler; class MoveTitleBlockTemplatesHandler; +class NumerotationContext; /** This class represents a QET project. Typically saved as a .qet file, it @@ -96,17 +97,25 @@ class QETProject : public QObject { ///DEFAULT PROPERTIES BorderProperties defaultBorderProperties() const; void setDefaultBorderProperties(const BorderProperties &); + TitleBlockProperties defaultTitleBlockProperties() const; void setDefaultTitleBlockProperties(const TitleBlockProperties &); + ConductorProperties defaultConductorProperties() const; void setDefaultConductorProperties(const ConductorProperties &); + QString defaultReportProperties() const; void setDefaultReportProperties (const QString &properties); + XRefProperties defaultXRefProperties (const QString &type) const {return m_default_xref_properties[type];} QHash defaultXRefProperties() const {return m_default_xref_properties;} void setDefaultXRefProperties(const QString type, const XRefProperties &properties); void setDefaultXRefProperties(QHash hash); + QHash conductorAutoNum() const; + void addConductorAutoNum (QString key, NumerotationContext context); + NumerotationContext conductorAutoNum(const QString &key) const; + QDomDocument toXml(); bool close(); QETResult write(); @@ -218,6 +227,8 @@ class QETProject : public QObject { DiagramContext project_properties_; /// undo stack for this project QUndoStack *undo_stack_; + /// Conductor auto numerotation + QHash m_conductor_autonum; }; Q_DECLARE_METATYPE(QETProject *) #endif diff --git a/sources/ui/autonumselectorwidget.cpp b/sources/ui/autonumselectorwidget.cpp new file mode 100644 index 000000000..2dc60c98c --- /dev/null +++ b/sources/ui/autonumselectorwidget.cpp @@ -0,0 +1,74 @@ +/* + Copyright 2006-2014 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 . +*/ +#include "autonumselectorwidget.h" +#include "ui_autonumselectorwidget.h" + +/** + * @brief AutonumSelectorWidget::AutonumSelectorWidget + * default constructor + * @param parent, parent widget + */ +AutonumSelectorWidget::AutonumSelectorWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::AutonumSelectorWidget) +{ + ui->setupUi(this); + ui->m_edit_autonum_pb->setDisabled(true); +} + +/** + * @brief AutonumSelectorWidget::AutonumSelectorWidget + * Constructor with texts to fill the combo box + * @param text, texts for fill the combo box + * @param parent, parent widget + */ +AutonumSelectorWidget::AutonumSelectorWidget(const QList &text, QWidget *parent) : + QWidget(parent), + ui(new Ui::AutonumSelectorWidget) +{ + ui->setupUi(this); + ui -> m_available_autonum_cb -> addItems(text); + ui->m_edit_autonum_pb->setDisabled(true); +} + +/** + * @brief AutonumSelectorWidget::~AutonumSelectorWidget + * Destructor + */ +AutonumSelectorWidget::~AutonumSelectorWidget() +{ + delete ui; +} + +/** + * @brief AutonumSelectorWidget::setCurrentItem + * Set the combo box current index by text. + * If text doesn't exist, set current index -1 + * @param text, text of index + */ +void AutonumSelectorWidget::setCurrentItem(const QString &text) { + ui -> m_available_autonum_cb -> setCurrentIndex( ui -> m_available_autonum_cb -> findText(text)); +} + +/** + * @brief AutonumSelectorWidget::text + * @return the current displayed text + */ +QString AutonumSelectorWidget::text() const { + return ui -> m_available_autonum_cb -> currentText(); +} diff --git a/sources/ui/autonumselectorwidget.h b/sources/ui/autonumselectorwidget.h new file mode 100644 index 000000000..d3ab86443 --- /dev/null +++ b/sources/ui/autonumselectorwidget.h @@ -0,0 +1,49 @@ +/* + Copyright 2006-2014 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 . +*/ +#ifndef AUTONUMSELECTORWIDGET_H +#define AUTONUMSELECTORWIDGET_H + +#include + +namespace Ui { + class AutonumSelectorWidget; +} + +/** + * @brief The AutonumSelectorWidget class + * This widget show a combobox to select an autonum and a button to edit the autonum + * The combo box is empty and the button isn't linked with anything, it's the role of caller + * of this class to fill the combo box and edit the connection with the button. + */ +class AutonumSelectorWidget : public QWidget +{ + Q_OBJECT + + public: + explicit AutonumSelectorWidget(QWidget *parent = 0); + explicit AutonumSelectorWidget(const QList &text, QWidget *parent = 0); + ~AutonumSelectorWidget(); + + void setCurrentItem (const QString &text); + QString text() const; + + private: + Ui::AutonumSelectorWidget *ui; +}; + +#endif // AUTONUMSELECTORWIDGET_H diff --git a/sources/ui/autonumselectorwidget.ui b/sources/ui/autonumselectorwidget.ui new file mode 100644 index 000000000..631c6e8c8 --- /dev/null +++ b/sources/ui/autonumselectorwidget.ui @@ -0,0 +1,63 @@ + + + AutonumSelectorWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 0 + + + + + Autonumérotation : + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + éditer les numérotations + + + + + + + :/ico/16x16/configure.png:/ico/16x16/configure.png + + + + + + + + + + diff --git a/sources/ui/conductorpropertieswidget.cpp b/sources/ui/conductorpropertieswidget.cpp index c1e0f4431..0858b6595 100644 --- a/sources/ui/conductorpropertieswidget.cpp +++ b/sources/ui/conductorpropertieswidget.cpp @@ -115,6 +115,10 @@ void ConductorPropertiesWidget::setReadOnly(const bool &ro) { this->setDisabled(ro); } +void ConductorPropertiesWidget::addAutonumWidget(QWidget *widget) { + ui->m_autonum_layout->addWidget(widget); +} + /** * @brief ConductorPropertiesWidget::initWidget */ diff --git a/sources/ui/conductorpropertieswidget.h b/sources/ui/conductorpropertieswidget.h index 7d574db15..a66f2eafd 100644 --- a/sources/ui/conductorpropertieswidget.h +++ b/sources/ui/conductorpropertieswidget.h @@ -40,6 +40,8 @@ class ConductorPropertiesWidget : public QWidget ConductorProperties properties() const; void setReadOnly(const bool &ro); + void addAutonumWidget (QWidget *widget); + private: void initWidget(); void setConductorType(ConductorProperties::ConductorType type); diff --git a/sources/ui/conductorpropertieswidget.ui b/sources/ui/conductorpropertieswidget.ui index b7a8639aa..cd3d09e25 100644 --- a/sources/ui/conductorpropertieswidget.ui +++ b/sources/ui/conductorpropertieswidget.ui @@ -57,7 +57,7 @@ - Texte : + Texte par defaut : @@ -83,6 +83,9 @@ + + + diff --git a/sources/ui/diagrampropertiesdialog.cpp b/sources/ui/diagrampropertiesdialog.cpp index 70e1fdcea..cc018b2fb 100644 --- a/sources/ui/diagrampropertiesdialog.cpp +++ b/sources/ui/diagrampropertiesdialog.cpp @@ -20,6 +20,7 @@ #include "titleblockpropertieswidget.h" #include "conductorpropertieswidget.h" #include "diagramcommands.h" +#include "autonumselectorwidget.h" /** * @brief DiagramPropertiesDialog::DiagramPropertiesDialog @@ -62,6 +63,11 @@ DiagramPropertiesDialog::DiagramPropertiesDialog(Diagram *diagram, QWidget *pare ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget(conductors, this); cpw -> setReadOnly(diagram_is_read_only); + //Conductor autonum + AutonumSelectorWidget *asw = new AutonumSelectorWidget(diagram -> project() -> conductorAutoNum().keys(), this); + asw -> setCurrentItem(diagram -> conductorsAutonumName()); + cpw->addAutonumWidget(asw); + // Buttons QDialogButtonBox boutons(diagram_is_read_only ? QDialogButtonBox::Ok : QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(&boutons, SIGNAL(accepted()), this, SLOT(accept())); @@ -70,7 +76,7 @@ DiagramPropertiesDialog::DiagramPropertiesDialog(Diagram *diagram, QWidget *pare QGridLayout glayout(this); glayout.addWidget(border_infos,0,0); glayout.addWidget(titleblock_infos, 1, 0); - glayout.addWidget(cpw, 0, 1, 0 ,1, Qt::AlignTop); + glayout.addWidget(cpw, 0, 1, 0, 1, Qt::AlignTop); glayout.addWidget(&boutons, 2, 1); // if dialog is accepted @@ -94,6 +100,11 @@ DiagramPropertiesDialog::DiagramPropertiesDialog(Diagram *diagram, QWidget *pare /// TODO implement an undo command to allow the user to undo/redo this action diagram -> defaultConductorProperties = new_conductors; } + + // Conductor autonum name + if (asw -> text() != diagram -> conductorsAutonumName()) { + diagram -> setConductorsAutonumName (asw -> text()); + } } } diff --git a/sources/ui/dialogautonum.cpp b/sources/ui/dialogautonum.cpp index f36229e4a..040e41a4b 100644 --- a/sources/ui/dialogautonum.cpp +++ b/sources/ui/dialogautonum.cpp @@ -18,7 +18,7 @@ #include "dialogautonum.h" #include "ui_dialogautonum.h" -#include "conductorautonumerotation.h" +//#include "conductorautonumerotation.h" #include "qetmessagebox.h" #include "ui/selectautonumw.h" @@ -34,7 +34,7 @@ DialogAutoNum::DialogAutoNum(Diagram *dg, QWidget *parent) : { ui -> setupUi(this); - ui -> configuration_layout -> addWidget (new SelectAutonumW(dg_ -> project() -> diagrams(), dg, ui -> configuration_tab)); + ui -> configuration_layout -> addWidget (new SelectAutonumW()); dgselect_ = new diagramselection( dg_ -> project(), ui -> annotation_tab); ui -> verticalLayout_Selection -> addWidget(dgselect_); @@ -74,8 +74,8 @@ void DialogAutoNum::on_pushButton_delete_clicked() { // if yes remove all if( answer == QMessageBox::Yes) { for(int i=0; i +#include "qdebug.h" /** * Constructor */ -SelectAutonumW::SelectAutonumW(const QList &diagrams, Diagram *current_diagram ,QWidget *parent) : +SelectAutonumW::SelectAutonumW(QWidget *parent) : QWidget(parent), - ui(new Ui::SelectAutonumW), - diagram_list(diagrams) + ui(new Ui::SelectAutonumW) { ui->setupUi(this); + setContext(NumerotationContext()); +} - initDiagramChooser(); - if (current_diagram) ui -> diagram_chooser -> setCurrentIndex (diagram_list.indexOf(current_diagram)); - setCurrentContext(); +SelectAutonumW::SelectAutonumW(const NumerotationContext &context, QWidget *parent) : + QWidget(parent), + ui(new Ui::SelectAutonumW) +{ + ui->setupUi(this); + setContext(context); } /** @@ -42,36 +48,32 @@ SelectAutonumW::~SelectAutonumW() delete ui; } -/** - * @brief SelectAutonumW::setDiagramChooser - * build the content of QComboBox @diagram_chooser. - */ -void SelectAutonumW::initDiagramChooser() { - for (int i=0; i title(); - if (diagram_title.isEmpty()) diagram_title = (tr("Sch\351ma sans titre")); - ui -> diagram_chooser -> addItem(diagram_title); - } -} - /** * @brief SelectAutonumW::setCurrentContext * build the context of current diagram selected in the @diagram_chooser QcomboBox */ -void SelectAutonumW::setCurrentContext() { - NumerotationContext nc = diagram_list.at(ui->diagram_chooser->currentIndex()) -> getNumerotation(Diagram::Conductors); +void SelectAutonumW::setContext(const NumerotationContext &context) { + m_context = context; - if (nc.size() == 0) { //@nc contain nothing, build a default numPartEditor + qDeleteAll(num_part_list_); + num_part_list_.clear(); + + if (m_context.size() == 0) { //@context contain nothing, build a default numPartEditor on_add_button_clicked(); - applyEnable(false); - return; } - for (int i=0; i editor_layout -> addWidget(part); + else { + for (int i=0; i editor_layout -> addWidget(part); + } } + + num_part_list_.size() == 1 ? + ui -> remove_button -> setDisabled(true): + ui -> remove_button -> setEnabled (true); + applyEnable(false); } @@ -95,6 +97,7 @@ void SelectAutonumW::on_add_button_clicked() { connect (part, SIGNAL(changed()), this, SLOT(applyEnable())); num_part_list_ << part; ui -> editor_layout -> addWidget(part); + ui -> remove_button -> setEnabled(true); } /** @@ -107,20 +110,13 @@ void SelectAutonumW::on_remove_button_clicked() { NumPartEditorW *part = num_part_list_.takeLast(); disconnect(part, SIGNAL(changed()), this, SLOT(applyEnable())); delete part; + if (num_part_list_.size() == 1) { + ui -> remove_button -> setDisabled(true); + } } applyEnable(); } -/** - * @brief SelectAutonumW::on_diagram_chooser_activated - * Action on diagram_chooser - */ -void SelectAutonumW::on_diagram_chooser_activated() { - foreach(NumPartEditorW *npew, num_part_list_) delete npew; - num_part_list_.clear(); - setCurrentContext(); -} - /** * @brief SelectAutonumW::on_buttonBox_clicked * Action on @buttonBox clicked @@ -130,10 +126,9 @@ void SelectAutonumW::on_buttonBox_clicked(QAbstractButton *button) { int answer = ui -> buttonBox -> buttonRole(button); switch (answer) { - //reset the displayed context to default context of @diagram_chooser. + //Reset the curent context case QDialogButtonBox::ResetRole: - on_diagram_chooser_activated(); - applyEnable(false); + setContext(m_context); break; //help dialog case QDialogButtonBox::HelpRole: @@ -157,9 +152,8 @@ void SelectAutonumW::on_buttonBox_clicked(QAbstractButton *button) { //apply the context in the diagram displayed by @diagram_chooser. case QDialogButtonBox::ApplyRole: - NumerotationContext nc = toNumContext(); - diagram_list.at(ui -> diagram_chooser -> currentIndex()) -> setNumerotation(Diagram::Conductors, nc); applyEnable(false); + emit applyPressed(); break; }; } diff --git a/sources/ui/selectautonumw.h b/sources/ui/selectautonumw.h index ce503014a..a74346f4e 100644 --- a/sources/ui/selectautonumw.h +++ b/sources/ui/selectautonumw.h @@ -19,8 +19,10 @@ #define SELECTAUTONUMW_H #include -#include "diagram.h" -#include "ui/numparteditorw.h" +#include "numerotationcontext.h" + +class NumPartEditorW; +class QAbstractButton; namespace Ui { class SelectAutonumW; @@ -32,27 +34,28 @@ class SelectAutonumW : public QWidget //METHODS public: - explicit SelectAutonumW(const QList &, Diagram * = 0, QWidget *parent = 0); - ~SelectAutonumW(); - - private: - void initDiagramChooser(); - void setCurrentContext (); - NumerotationContext toNumContext() const; + explicit SelectAutonumW(QWidget *parent = 0); + explicit SelectAutonumW(const NumerotationContext &context, QWidget *parent = 0); + ~SelectAutonumW(); + + void setContext (const NumerotationContext &context); + NumerotationContext toNumContext() const; + + signals: + void applyPressed(); //SLOT private slots: - void on_add_button_clicked(); - void on_remove_button_clicked(); - void on_diagram_chooser_activated(); - void on_buttonBox_clicked(QAbstractButton *); - void applyEnable (bool = true); + void on_add_button_clicked(); + void on_remove_button_clicked(); + void on_buttonBox_clicked(QAbstractButton *); + void applyEnable (bool = true); //ATTRIBUTS private: - Ui::SelectAutonumW *ui; - const QList diagram_list; - QList num_part_list_; + Ui::SelectAutonumW *ui; + QList num_part_list_; + NumerotationContext m_context; }; #endif // SELECTAUTONUMW_H diff --git a/sources/ui/selectautonumw.ui b/sources/ui/selectautonumw.ui index a73187c7f..0a5525022 100644 --- a/sources/ui/selectautonumw.ui +++ b/sources/ui/selectautonumw.ui @@ -13,84 +13,54 @@ Form - - - - - 0 - - - - - Folio: - - - - - - - <html><head/><body><p>Choisir le folio</p></body></html> - - - 5 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - <html><head/><body><p>Supprimer une variable de numérotation</p></body></html> - - - - - - - :/ico/22x22/list-remove.png:/ico/22x22/list-remove.png - - - false - - - - - - - <html><head/><body><p>Ajouter une variable de numérotation</p></body></html> - - - - - - - :/ico/22x22/list-add.png:/ico/22x22/list-add.png - - - false - - - - - + Définition + + + + 0 + + + + + <html><head/><body><p>Supprimer une variable de numérotation</p></body></html> + + + + + + + :/ico/22x22/list-remove.png:/ico/22x22/list-remove.png + + + false + + + + + + + <html><head/><body><p>Ajouter une variable de numérotation</p></body></html> + + + + + + + :/ico/22x22/list-add.png:/ico/22x22/list-add.png + + + false + + + + +