diff --git a/qelectrotech.pro b/qelectrotech.pro index 0382ab7bf..e5b8bd445 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -65,12 +65,12 @@ INCLUDEPATH += sources sources/editor sources/titleblock sources/ui sources/qetg # Fichiers sources HEADERS += sources/*.h sources/ui/*.h sources/editor/*.h sources/titleblock/*.h sources/richtext/*.h sources/qetgraphicsitem/*.h sources/factory/*.cpp \ - sources/properties/propertiesinterface.h \ - sources/properties/xrefproperties.h + sources/properties/*.h \ + sources/editor/ui/*.h SOURCES += sources/*.cpp sources/editor/*.cpp sources/titleblock/*.cpp sources/richtext/*.cpp sources/ui/*.cpp sources/qetgraphicsitem/*.cpp sources/factory/*.cpp \ - sources/properties/propertiesinterface.cpp \ - sources/properties/xrefproperties.cpp + sources/properties/*.cpp \ + sources/editor/ui/*.cpp # Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt RESOURCES += qelectrotech.qrc @@ -85,9 +85,10 @@ TRANSLATIONS += lang/qet_en.ts lang/qet_es.ts lang/qet_fr.ts lang/qet_ru.ts lang QT += xml svg network sql # UI DESIGNER FILES AND GENERATION SOURCES FILES -FORMS += sources/richtext/addlinkdialog.ui sources/ui/*.ui \ - sources/ui/linksingleelementwidget.ui \ - sources/ui/xrefpropertieswidget.ui +FORMS += sources/richtext/*.ui \ + sources/ui/*.ui \ + sources/editor/ui/*.ui + UI_SOURCES_DIR = sources/ui/ UI_HEADERS_DIR = sources/ui/ diff --git a/sources/editor/elementscene.cpp b/sources/editor/elementscene.cpp index cd273d1ec..9d1d392fb 100644 --- a/sources/editor/elementscene.cpp +++ b/sources/editor/elementscene.cpp @@ -30,6 +30,7 @@ #include "editorcommands.h" #include "elementcontent.h" #include "nameslist.h" +#include "ui/elementpropertieseditorwidget.h" /** Constructeur @@ -40,7 +41,8 @@ ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) : QGraphicsScene(parent), qgi_manager(this), element_editor(editor), - decorator_(0) + decorator_(0), + m_elmt_type("simple") { setItemIndexMethod(NoIndex); current_polygon = NULL; @@ -417,9 +419,16 @@ const QDomDocument ElementScene::toXml(bool all_parts) { root.setAttribute("orientation", "dyyy"); //we keep the orientation for compatibility with previous version of qet root.setAttribute("version", QET::version); root.setAttribute("ic", "true"); //we keep the internal connection for compatibility with previous version of qet + root.setAttribute("link_type", m_elmt_type); // noms de l'element root.appendChild(_names.toXml(xml_document)); + + if (m_elmt_type == "slave") { + QDomElement kindInfo = xml_document.createElement("kindInformations"); + m_elmt_kindInfo.toXml(kindInfo, "kindInformation"); + root.appendChild(kindInfo); + } // informations complementaires de l'element QDomElement informations_element = xml_document.createElement("informations"); @@ -708,6 +717,15 @@ void ElementScene::slot_editAuthorInformations() { } } +/** + * @brief ElementScene::slot_editProperties + * Open dialog to edit the element properties + */ +void ElementScene::slot_editProperties() { + ElementPropertiesEditorWidget epew(m_elmt_type, m_elmt_kindInfo); + epew.exec(); +} + /** Lance un dialogue pour editer les noms de cet element */ @@ -918,7 +936,7 @@ QRectF ElementScene::elementContentBoundingRect(const ElementContent &content) c passee, false sinon. */ bool ElementScene::applyInformations(const QDomDocument &xml_document, QString *error_message) { - // la racine est supposee etre une definition d'element + // Root must be an element definition QDomElement root = xml_document.documentElement(); if (root.tagName() != "definition" || root.attribute("type") != "element") { if (error_message) { @@ -927,10 +945,14 @@ bool ElementScene::applyInformations(const QDomDocument &xml_document, QString * return(false); } - // extrait les noms de la definition XML + //Extract info about element type + m_elmt_type = root.attribute("link_type", "simple"); + m_elmt_kindInfo.fromXml(root.firstChildElement("kindInformations"), "kindInformation"); + + //Extract names of xml definition _names.fromXml(root); - // extrait les informations complementaires + //extract additional informations setInformations(QString()); for (QDomNode node = root.firstChild() ; !node.isNull() ; node = node.nextSibling()) { QDomElement elmt = node.toElement(); diff --git a/sources/editor/elementscene.h b/sources/editor/elementscene.h index 7eada884c..7cbc253f7 100644 --- a/sources/editor/elementscene.h +++ b/sources/editor/elementscene.h @@ -22,6 +22,7 @@ #include "nameslistwidget.h" #include "qgimanager.h" #include "elementcontent.h" +#include "diagramcontext.h" class CustomElementPart; class ElementEditionCommand; class ElementPrimitiveDecorator; @@ -66,6 +67,10 @@ class ElementScene : public QGraphicsScene { NamesList _names; /// Extra informations QString informations_; + /// element type + QString m_elmt_type; + /// element kind info + DiagramContext m_elmt_kindInfo; /// QGraphicsItem manager QGIManager qgi_manager; /// Undo stack @@ -111,6 +116,8 @@ class ElementScene : public QGraphicsScene { void setInternalConnections(bool); QString informations() const; void setInformations(const QString &); + QString elementType () const {return m_elmt_type;} + DiagramContext elementKindInfo () const {return m_elmt_kindInfo;} virtual int xGrid() const; virtual int yGrid() const; virtual void setGrid(int, int); @@ -172,6 +179,7 @@ class ElementScene : public QGraphicsScene { void slot_delete(); void slot_editNames(); void slot_editAuthorInformations(); + void slot_editProperties(); void slot_bringForward(); void slot_raise(); void slot_lower(); diff --git a/sources/editor/qetelementeditor.cpp b/sources/editor/qetelementeditor.cpp index fe75d302d..43598aa7b 100644 --- a/sources/editor/qetelementeditor.cpp +++ b/sources/editor/qetelementeditor.cpp @@ -122,43 +122,44 @@ void QETElementEditor::setFileName(const QString &fn) { Met en place les actions */ void QETElementEditor::setupActions() { - new_element = new QAction(QET::Icons::DocumentNew, tr("&Nouveau"), this); - open = new QAction(QET::Icons::DocumentOpen, tr("&Ouvrir"), this); - open_file = new QAction(QET::Icons::DocumentOpen, tr("&Ouvrir depuis un fichier"), this); - save = new QAction(QET::Icons::DocumentSave, tr("&Enregistrer"), this); - save_as = new QAction(QET::Icons::DocumentSaveAs, tr("Enregistrer sous"), this); - save_as_file = new QAction(QET::Icons::DocumentSaveAs, tr("Enregistrer dans un fichier"), this); - reload = new QAction(QET::Icons::ViewRefresh, tr("Recharger"), this); - quit = new QAction(QET::Icons::ApplicationExit, tr("&Quitter"), this); - selectall = new QAction(QET::Icons::EditSelectAll, tr("Tout s\351lectionner"), this); - deselectall = new QAction( tr("D\351s\351lectionner tout"), this); - cut = new QAction(QET::Icons::EditCut, tr("Co&uper"), this); - copy = new QAction(QET::Icons::EditCopy, tr("Cop&ier"), this); - paste = new QAction(QET::Icons::EditPaste, tr("C&oller"), this); - paste_in_area = new QAction(QET::Icons::EditPaste, tr("C&oller dans la zone..."), this); - paste_from_file = new QAction(QET::Icons::XmlTextFile, tr("un fichier"), this); - paste_from_elmt = new QAction(QET::Icons::Element, tr("un \351l\351ment"), this); - inv_select = new QAction( tr("Inverser la s\351lection"), this); - edit_delete = new QAction(QET::Icons::EditDelete, tr("&Supprimer"), this); - zoom_in = new QAction(QET::Icons::ZoomIn, tr("Zoom avant"), this); - zoom_out = new QAction(QET::Icons::ZoomOut, tr("Zoom arri\350re"), this); - zoom_fit = new QAction(QET::Icons::ZoomFitBest, tr("Zoom adapt\351"), this); - zoom_reset = new QAction(QET::Icons::ZoomOriginal, tr("Pas de zoom"), this); - edit_names = new QAction(QET::Icons::Names, tr("\311diter les noms"), this); - edit_author = new QAction(QET::Icons::UserInformations, tr("\311diter les informations sur l'auteur"), this); - edit_raise = new QAction(QET::Icons::Raise, tr("Rapprocher"), this); - edit_lower = new QAction(QET::Icons::Lower, tr("\311loigner"), this); - edit_backward = new QAction(QET::Icons::SendBackward, tr("Envoyer au fond"), this); - edit_forward = new QAction(QET::Icons::BringForward, tr("Amener au premier plan"), this); - move = new QAction(QET::Icons::PartSelect, tr("D\351placer un objet"), this); - add_line = new QAction(QET::Icons::PartLine, tr("Ajouter une ligne"), this); - add_rectangle = new QAction(QET::Icons::PartRectangle, tr("Ajouter un rectangle"), this); - add_ellipse = new QAction(QET::Icons::PartEllipse, tr("Ajouter une ellipse"), this); - add_polygon = new QAction(QET::Icons::PartPolygon, tr("Ajouter un polygone"), this); - add_text = new QAction(QET::Icons::PartText, tr("Ajouter du texte"), this); - add_arc = new QAction(QET::Icons::PartArc, tr("Ajouter un arc de cercle"), this); - add_terminal = new QAction(QET::Icons::Terminal, tr("Ajouter une borne"), this); - add_textfield = new QAction(QET::Icons::PartTextField, tr("Ajouter un champ de texte"), this); + new_element = new QAction(QET::Icons::DocumentNew, tr("&Nouveau"), this); + open = new QAction(QET::Icons::DocumentOpen, tr("&Ouvrir"), this); + open_file = new QAction(QET::Icons::DocumentOpen, tr("&Ouvrir depuis un fichier"), this); + save = new QAction(QET::Icons::DocumentSave, tr("&Enregistrer"), this); + save_as = new QAction(QET::Icons::DocumentSaveAs, tr("Enregistrer sous"), this); + save_as_file = new QAction(QET::Icons::DocumentSaveAs, tr("Enregistrer dans un fichier"), this); + reload = new QAction(QET::Icons::ViewRefresh, tr("Recharger"), this); + quit = new QAction(QET::Icons::ApplicationExit, tr("&Quitter"), this); + selectall = new QAction(QET::Icons::EditSelectAll, tr("Tout s\351lectionner"), this); + deselectall = new QAction( tr("D\351s\351lectionner tout"), this); + cut = new QAction(QET::Icons::EditCut, tr("Co&uper"), this); + copy = new QAction(QET::Icons::EditCopy, tr("Cop&ier"), this); + paste = new QAction(QET::Icons::EditPaste, tr("C&oller"), this); + paste_in_area = new QAction(QET::Icons::EditPaste, tr("C&oller dans la zone..."), this); + paste_from_file = new QAction(QET::Icons::XmlTextFile, tr("un fichier"), this); + paste_from_elmt = new QAction(QET::Icons::Element, tr("un \351l\351ment"), this); + inv_select = new QAction( tr("Inverser la s\351lection"), this); + edit_delete = new QAction(QET::Icons::EditDelete, tr("&Supprimer"), this); + zoom_in = new QAction(QET::Icons::ZoomIn, tr("Zoom avant"), this); + zoom_out = new QAction(QET::Icons::ZoomOut, tr("Zoom arri\350re"), this); + zoom_fit = new QAction(QET::Icons::ZoomFitBest, tr("Zoom adapt\351"), this); + zoom_reset = new QAction(QET::Icons::ZoomOriginal, tr("Pas de zoom"), this); + edit_names = new QAction(QET::Icons::Names, tr("\311diter les noms"), this); + edit_author = new QAction(QET::Icons::UserInformations, tr("\311diter les informations sur l'auteur"), this); + m_edit_properties = new QAction(QET::Icons::ElementEdit, tr("\311diter les propri\351t\351es de l'\351l\351ment)"), this); + edit_raise = new QAction(QET::Icons::Raise, tr("Rapprocher"), this); + edit_lower = new QAction(QET::Icons::Lower, tr("\311loigner"), this); + edit_backward = new QAction(QET::Icons::SendBackward, tr("Envoyer au fond"), this); + edit_forward = new QAction(QET::Icons::BringForward, tr("Amener au premier plan"), this); + move = new QAction(QET::Icons::PartSelect, tr("D\351placer un objet"), this); + add_line = new QAction(QET::Icons::PartLine, tr("Ajouter une ligne"), this); + add_rectangle = new QAction(QET::Icons::PartRectangle, tr("Ajouter un rectangle"), this); + add_ellipse = new QAction(QET::Icons::PartEllipse, tr("Ajouter une ellipse"), this); + add_polygon = new QAction(QET::Icons::PartPolygon, tr("Ajouter un polygone"), this); + add_text = new QAction(QET::Icons::PartText, tr("Ajouter du texte"), this); + add_arc = new QAction(QET::Icons::PartArc, tr("Ajouter un arc de cercle"), this); + add_terminal = new QAction(QET::Icons::Terminal, tr("Ajouter une borne"), this); + add_textfield = new QAction(QET::Icons::PartTextField, tr("Ajouter un champ de texte"), this); QString add_status_tip = tr("Maintenez la touche Shift enfonc\351e pour effectuer plusieurs ajouts d'affil\351e"); add_line -> setStatusTip(add_status_tip); @@ -234,6 +235,7 @@ void QETElementEditor::setupActions() { connect(edit_delete, SIGNAL(triggered()), ce_scene, SLOT(slot_delete())); connect(edit_names, SIGNAL(triggered()), ce_scene, SLOT(slot_editNames())); connect(edit_author, SIGNAL(triggered()), ce_scene, SLOT(slot_editAuthorInformations())); + connect(m_edit_properties, SIGNAL(triggered()), ce_scene, SLOT(slot_editProperties())); connect(edit_forward, SIGNAL(triggered()), ce_scene, SLOT(slot_bringForward())); connect(edit_raise, SIGNAL(triggered()), ce_scene, SLOT(slot_raise())); connect(edit_lower, SIGNAL(triggered()), ce_scene, SLOT(slot_lower())); @@ -312,9 +314,13 @@ void QETElementEditor::setupActions() { main_toolbar -> addAction(redo); main_toolbar -> addSeparator(); main_toolbar -> addAction(edit_delete); + view_toolbar -> addAction(zoom_fit); view_toolbar -> addAction(zoom_reset); + element_toolbar -> addAction(edit_names); + element_toolbar -> addAction(m_edit_properties); + depth_toolbar -> addAction(edit_forward); depth_toolbar -> addAction(edit_raise); depth_toolbar -> addAction(edit_lower); @@ -390,6 +396,7 @@ void QETElementEditor::setupMenus() { edit_menu -> addSeparator(); edit_menu -> addAction(edit_names); edit_menu -> addAction(edit_author); + edit_menu -> addAction(m_edit_properties); edit_menu -> addSeparator(); edit_menu -> addAction(edit_forward); edit_menu -> addAction(edit_raise); @@ -637,15 +644,17 @@ void QETElementEditor::xmlPreview() { } /** - Effectue diverses verifications sur l'element et en informe l'utilisateur. - @return true si la situation est ok, false sinon -*/ + * @brief QETElementEditor::checkElement + * Do several check about element. + * If error is occured return false + */ bool QETElementEditor::checkElement() { // liste les avertissements applicables typedef QPair QETWarning; QList warnings; + QList errors; - /// Avertissement #2 : si l'element ne comporte aucune borne + /// Warning #1: Element haven't got terminal if (!ce_scene -> containsTerminals()) { warnings << qMakePair( tr("Absence de borne", "warning title"), @@ -658,18 +667,33 @@ bool QETElementEditor::checkElement() { ) ); } + + ///Error #1: element is slave or master but havent got input tagged 'label' + if(ce_scene -> elementType() == "master" || ce_scene -> elementType() == "slave") { + bool wrng = true; + foreach (CustomElementPart *cep, ce_scene->primitives()) { + if (cep->property("tagg").toString() == "label") wrng = false; + } + if (wrng) { + errors << qMakePair( + tr("Absence de champ texte 'label'", "warning title"), + tr("Les \351l\351ments ma\356tres ou esclaves doivent poss\351der " + "un champ texte comportant le tagg 'label'", "warning description")); + } + } - if (!warnings.count()) return(true); + if (!errors.count() && !warnings.count()) return(true); + QList total = warnings << errors; - // affiche les avertissements + // Display warnings QString warning_message = tr( "La v\351rification de cet \351l\351ment a g\351n\351r\351 %n avertissement(s)\240:", "message box content", - warnings.count() + total.count() ); warning_message += "
    "; - foreach(QETWarning warning, warnings) { + foreach(QETWarning warning, total) { warning_message += "
  1. "; warning_message += QString( tr("%1\240: %2", "warning title: warning description") @@ -677,15 +701,12 @@ bool QETElementEditor::checkElement() { warning_message += "
  2. "; } warning_message += "
"; - - QMessageBox warnings_message_box(this); - warnings_message_box.setWindowModality(Qt::WindowModal); - warnings_message_box.setWindowFlags(warnings_message_box.windowFlags() | Qt::Sheet); - warnings_message_box.setTextFormat(Qt::RichText); - warnings_message_box.setWindowTitle(tr("Avertissements", "messagebox title")); - warnings_message_box.setText(warning_message); - warnings_message_box.exec(); - return(false); + + QMessageBox::warning(this, tr("Avertissements"), warning_message); + + //if error == 0 that means they are only warning, we return true. + if (errors.count() == 0) return(true); + return false; } /** @@ -976,71 +997,84 @@ void QETElementEditor::slot_reload() { @see slot_saveAs() */ bool QETElementEditor::slot_save() { - // verification avant d'enregistrer le fichier - checkElement(); - // si on ne connait pas le nom du fichier en cours, enregistrer revient a enregistrer sous - if (opened_from_file) { - if (filename_.isEmpty()) return(slot_saveAsFile()); - // sinon on enregistre dans le nom de fichier connu - bool result_save = toFile(filename_); - if (result_save) ce_scene -> undoStack().setClean(); - return(result_save); - } else { - if (location_.isNull()) return(slot_saveAs()); - // sinon on enregistre a l'emplacement connu - bool result_save = toLocation(location_); - if (result_save) ce_scene -> undoStack().setClean(); - return(result_save); + // Check element befor writing + if (checkElement()) { + // si on ne connait pas le nom du fichier en cours, enregistrer revient a enregistrer sous + if (opened_from_file) { + if (filename_.isEmpty()) return(slot_saveAsFile()); + // sinon on enregistre dans le nom de fichier connu + bool result_save = toFile(filename_); + if (result_save) ce_scene -> undoStack().setClean(); + return(result_save); + } else { + if (location_.isNull()) return(slot_saveAs()); + // sinon on enregistre a l'emplacement connu + bool result_save = toLocation(location_); + if (result_save) ce_scene -> undoStack().setClean(); + return(result_save); + } } + QMessageBox::critical(this, tr("Echec de l'enregistrement"), tr("L'enregistrement \340 \351chou\351,\nles conditions requises ne sont pas valides")); + return false; } /** Demande une localisation a l'utilisateur et enregistre l'element */ bool QETElementEditor::slot_saveAs() { - // demande une localisation a l'utilisateur - ElementsLocation location = ElementDialog::getSaveElementLocation(this); - if (location.isNull()) return(false); + // Check element befor writing + if (checkElement()) { + // demande une localisation a l'utilisateur + ElementsLocation location = ElementDialog::getSaveElementLocation(this); + if (location.isNull()) return(false); - // tente l'enregistrement - bool result_save = toLocation(location); - if (result_save) { - setLocation(location); - ce_scene -> undoStack().setClean(); + // tente l'enregistrement + bool result_save = toLocation(location); + if (result_save) { + setLocation(location); + ce_scene -> undoStack().setClean(); + } + + // retourne un booleen representatif de la reussite de l'enregistrement + return(result_save); } - - // retourne un booleen representatif de la reussite de l'enregistrement - return(result_save); + QMessageBox::critical(this, tr("Echec de l'enregistrement"), tr("L'enregistrement \340 \351chou\351,\nles conditions requises ne sont pas valides")); + return (false); } /** Demande un nom de fichier a l'utilisateur et enregistre l'element */ bool QETElementEditor::slot_saveAsFile() { - // demande un nom de fichier a l'utilisateur pour enregistrer l'element - QString fn = QFileDialog::getSaveFileName( - this, - tr("Enregistrer sous", "dialog title"), - filename_.isEmpty() ? QETApp::customElementsDir() : QDir(filename_).absolutePath(), - tr( - "\311l\351ments QElectroTech (*.elmt)", - "filetypes allowed when saving an element file" - ) - ); - // si aucun nom n'est entre, renvoie faux. - if (fn.isEmpty()) return(false); - // si le nom ne se termine pas par l'extension .elmt, celle-ci est ajoutee - if (!fn.endsWith(".elmt", Qt::CaseInsensitive)) fn += ".elmt"; - // tente d'enregistrer le fichier - bool result_save = toFile(fn); - // si l'enregistrement reussit, le nom du fichier est conserve - if (result_save) { - setFileName(fn); - QETApp::elementsRecentFiles() -> fileWasOpened(fn); - ce_scene -> undoStack().setClean(); + // Check element befor writing + if (checkElement()) { + // demande un nom de fichier a l'utilisateur pour enregistrer l'element + QString fn = QFileDialog::getSaveFileName( + this, + tr("Enregistrer sous", "dialog title"), + filename_.isEmpty() ? QETApp::customElementsDir() : QDir(filename_).absolutePath(), + tr( + "\311l\351ments QElectroTech (*.elmt)", + "filetypes allowed when saving an element file" + ) + ); + // si aucun nom n'est entre, renvoie faux. + if (fn.isEmpty()) return(false); + // si le nom ne se termine pas par l'extension .elmt, celle-ci est ajoutee + if (!fn.endsWith(".elmt", Qt::CaseInsensitive)) fn += ".elmt"; + // tente d'enregistrer le fichier + bool result_save = toFile(fn); + // si l'enregistrement reussit, le nom du fichier est conserve + if (result_save) { + setFileName(fn); + QETApp::elementsRecentFiles() -> fileWasOpened(fn); + ce_scene -> undoStack().setClean(); + } + // retourne un booleen representatif de la reussite de l'enregistrement + return(result_save); } - // retourne un booleen representatif de la reussite de l'enregistrement - return(result_save); + QMessageBox::critical(this, tr("Echec de l'enregistrement"), tr("L'enregistrement \340 \351chou\351,\nles conditions requises ne sont pas valides")); + return false; } /** diff --git a/sources/editor/qetelementeditor.h b/sources/editor/qetelementeditor.h index 98ec39ed0..3b136d37c 100644 --- a/sources/editor/qetelementeditor.h +++ b/sources/editor/qetelementeditor.h @@ -71,7 +71,7 @@ class QETElementEditor : public QETMainWindow { QAction *selectall, *deselectall, *inv_select; QAction *cut, *copy, *paste, *paste_in_area, *paste_from_file, *paste_from_elmt; QAction *undo, *redo; - QAction *edit_delete, *edit_size_hs, *edit_names, *edit_author; + QAction *edit_delete, *edit_size_hs, *edit_names, *edit_author, *m_edit_properties; QAction *edit_raise, *edit_lower, *edit_backward, *edit_forward; /// actions for the "display" menu QAction *zoom_in, *zoom_out, *zoom_fit, *zoom_reset; diff --git a/sources/editor/ui/elementpropertieseditorwidget.cpp b/sources/editor/ui/elementpropertieseditorwidget.cpp new file mode 100644 index 000000000..7cbec8c0d --- /dev/null +++ b/sources/editor/ui/elementpropertieseditorwidget.cpp @@ -0,0 +1,104 @@ +/* + 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 "elementpropertieseditorwidget.h" +#include "ui_elementpropertieseditorwidget.h" + +/** + * @brief ElementPropertiesEditorWidget::ElementPropertiesEditorWidget + * Default constructor + * @param basic_type : QString of the drawed element + * @param dc : DiagramContext to store kindInfo of drawed element + * @param parent : parent widget + */ +ElementPropertiesEditorWidget::ElementPropertiesEditorWidget(QString &basic_type, DiagramContext &dc, QWidget *parent) : + QDialog(parent), + ui(new Ui::ElementPropertiesEditorWidget), + m_basic_type(basic_type), + m_dc (dc) +{ + ui->setupUi(this); + setUpInterface(); + upDateInterface(); +} + +/** + * @brief ElementPropertiesEditorWidget::~ElementPropertiesEditorWidget + * Default destructor + */ +ElementPropertiesEditorWidget::~ElementPropertiesEditorWidget() +{ + delete ui; +} + +void ElementPropertiesEditorWidget::upDateInterface() { + ui -> m_base_type_cb -> setCurrentIndex (ui -> m_base_type_cb -> findData (QVariant(m_basic_type))); + ui -> m_state_cb -> setCurrentIndex (ui -> m_state_cb -> findData (m_dc["state"].toString())); + ui -> m_type_cb -> setCurrentIndex (ui -> m_type_cb -> findData (m_dc["type"].toString())); + ui -> m_number_ctc -> setValue (m_dc["number"].toInt()); + + on_m_base_type_cb_currentIndexChanged(ui->m_base_type_cb->currentIndex()); +} + +/** + * @brief ElementPropertiesEditorWidget::setUpInterface + */ +void ElementPropertiesEditorWidget::setUpInterface() { + // Type combo box + ui -> m_base_type_cb -> addItem (tr("Simple"), QVariant("simple")); + ui -> m_base_type_cb -> addItem (tr("Ma\356tre"), QVariant("master")); + ui -> m_base_type_cb -> addItem (tr("Esclave"), QVariant("slave")); + ui -> m_base_type_cb -> addItem (tr("Renvoi de folio suivant"), QVariant("next_report")); + ui -> m_base_type_cb -> addItem (tr("Renvoi de folio pr\351c\351dent"), QVariant("previous_report")); + + // Slave option + ui -> m_state_cb -> addItem(tr("Normalement ouvert"), QVariant("NO")); + ui -> m_state_cb -> addItem(tr("Normalement ferm\351"), QVariant("NC")); + ui -> m_type_cb -> addItem(tr("Simple"), QVariant("simple")); + ui -> m_type_cb -> addItem(tr("Puissance"), QVariant("power")); + ui -> m_type_cb -> addItem(tr("Temporis\351 travail"), QVariant("delayOn")); + ui -> m_type_cb -> addItem(tr("Temporis\351 repos"), QVariant("delayOff")); +} + +/** + * @brief ElementPropertiesEditorWidget::on_m_buttonBox_accepted + * Action on button accepted : the new information is set + */ +void ElementPropertiesEditorWidget::on_m_buttonBox_accepted() +{ + m_basic_type = ui -> m_base_type_cb -> itemData(ui -> m_base_type_cb -> currentIndex()).toString(); + if (m_basic_type == "slave") { + m_dc.addValue("state", ui -> m_state_cb -> itemData(ui -> m_state_cb -> currentIndex())); + m_dc.addValue("type", ui -> m_type_cb -> itemData(ui -> m_type_cb -> currentIndex())); + m_dc.addValue("number", QVariant(ui -> m_number_ctc -> value())); + } + this->close(); +} + +/** + * @brief ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged + * @param index : Action when combo-box base type index change + */ +void ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged(int index) +{ + if (ui->m_base_type_cb->itemData(index).toString() == "slave") { + ui->m_slave_gb->setEnabled(true); + } else { + ui->m_slave_gb->setEnabled(false); + } + +} diff --git a/sources/editor/ui/elementpropertieseditorwidget.h b/sources/editor/ui/elementpropertieseditorwidget.h new file mode 100644 index 000000000..716409326 --- /dev/null +++ b/sources/editor/ui/elementpropertieseditorwidget.h @@ -0,0 +1,60 @@ +/* + 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 ELEMENTPROPERTIESEDITORWIDGET_H +#define ELEMENTPROPERTIESEDITORWIDGET_H + +#include +#include +#include "diagramcontext.h" + +namespace Ui { + class ElementPropertiesEditorWidget; +} + +/** + * @brief The ElementPropertiesEditorWidget class + * This class provide a dialog for edit various property of element, like + * the type (master, slave, report etc....) and kind info. + */ +class ElementPropertiesEditorWidget : public QDialog +{ + Q_OBJECT + + //METHODS + public: + explicit ElementPropertiesEditorWidget(QString &basic_type, DiagramContext &dc, QWidget *parent = 0); + ~ElementPropertiesEditorWidget(); + + void upDateInterface(); + + private: + void setUpInterface(); + + //SLOTS + private slots: + void on_m_buttonBox_accepted(); + void on_m_base_type_cb_currentIndexChanged(int index); + + //ATTRIBUTES + private: + Ui::ElementPropertiesEditorWidget *ui; + QString &m_basic_type; + DiagramContext &m_dc; +}; + +#endif // ELEMENTPROPERTIESEDITORWIDGET_H diff --git a/sources/editor/ui/elementpropertieseditorwidget.ui b/sources/editor/ui/elementpropertieseditorwidget.ui new file mode 100644 index 000000000..522985e0e --- /dev/null +++ b/sources/editor/ui/elementpropertieseditorwidget.ui @@ -0,0 +1,141 @@ + + + ElementPropertiesEditorWidget + + + + 0 + 0 + 400 + 300 + + + + Propriété de l'élément + + + false + + + + + + + + Type de base : + + + + + + + + + + + + Élément esclave + + + + + + + + 1 + + + + + + + Nombre de contact représenté + + + + + + + Type de contact + + + + + + + État du contact + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + m_buttonBox + accepted() + ElementPropertiesEditorWidget + accept() + + + 248 + 254 + + + 157 + 274 + + + + + m_buttonBox + rejected() + ElementPropertiesEditorWidget + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sources/qetgraphicsitem/reportelement.cpp b/sources/qetgraphicsitem/reportelement.cpp index 1cbf703bf..34ed7777c 100644 --- a/sources/qetgraphicsitem/reportelement.cpp +++ b/sources/qetgraphicsitem/reportelement.cpp @@ -23,7 +23,8 @@ ReportElement::ReportElement(const ElementsLocation &location, QString link_type,QGraphicsItem *qgi, Diagram *s, int *state) : CustomElement(location, qgi, s, state) { - texts().at(0)->setNoEditable(); + if (!texts().isEmpty()) + texts().first()->setNoEditable(); link_type == "next_report"? link_type_=NextReport : link_type_=PreviousReport; link_type == "next_report"? inverse_report=PreviousReport : inverse_report=NextReport; if (s) { @@ -108,6 +109,7 @@ void ReportElement::setLabel(QString label) { * ie the folio and position of the linked folio report */ void ReportElement::updateLabel() { + if (texts().isEmpty()) return; ElementTextItem *text = texts().first(); if (!connected_elements.isEmpty()){