element editor: add dialog for edit element properties (master, slave etc...)

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3102 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun 2014-06-03 20:21:19 +00:00
parent ff5b82d61a
commit 74732bb54b
9 changed files with 488 additions and 116 deletions

View File

@ -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/

View File

@ -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,10 +419,17 @@ 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");
root.appendChild(informations_element);
@ -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();

View File

@ -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();

View File

@ -146,6 +146,7 @@ void QETElementEditor::setupActions() {
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);
@ -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<QString, QString> QETWarning;
QList<QETWarning> warnings;
QList<QETWarning> 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"),
@ -659,17 +668,32 @@ bool QETElementEditor::checkElement() {
);
}
if (!warnings.count()) return(true);
///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"));
}
}
// affiche les avertissements
if (!errors.count() && !warnings.count()) return(true);
QList<QETWarning> total = warnings << errors;
// 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 += "<ol>";
foreach(QETWarning warning, warnings) {
foreach(QETWarning warning, total) {
warning_message += "<li>";
warning_message += QString(
tr("<b>%1</b>\240: %2", "warning title: warning description")
@ -678,14 +702,11 @@ bool QETElementEditor::checkElement() {
}
warning_message += "</ol>";
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,8 +997,8 @@ void QETElementEditor::slot_reload() {
@see slot_saveAs()
*/
bool QETElementEditor::slot_save() {
// verification avant d'enregistrer le fichier
checkElement();
// 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());
@ -993,11 +1014,16 @@ bool QETElementEditor::slot_save() {
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() {
// Check element befor writing
if (checkElement()) {
// demande une localisation a l'utilisateur
ElementsLocation location = ElementDialog::getSaveElementLocation(this);
if (location.isNull()) return(false);
@ -1012,11 +1038,16 @@ bool QETElementEditor::slot_saveAs() {
// 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() {
// Check element befor writing
if (checkElement()) {
// demande un nom de fichier a l'utilisateur pour enregistrer l'element
QString fn = QFileDialog::getSaveFileName(
this,
@ -1042,6 +1073,9 @@ bool QETElementEditor::slot_saveAsFile() {
// 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;
}
/**
@return true si l'element peut etre ferme.

View File

@ -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;

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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);
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef ELEMENTPROPERTIESEDITORWIDGET_H
#define ELEMENTPROPERTIESEDITORWIDGET_H
#include <QDialog>
#include <QAbstractButton>
#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

View File

@ -0,0 +1,141 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ElementPropertiesEditorWidget</class>
<widget class="QDialog" name="ElementPropertiesEditorWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Propriété de l'élément</string>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Type de base :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="m_base_type_cb"/>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="m_slave_gb">
<property name="title">
<string>Élément esclave</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<widget class="QSpinBox" name="m_number_ctc">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Nombre de contact représenté</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Type de contact</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>État du contact</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="m_state_cb"/>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="m_type_cb"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>m_buttonBox</sender>
<signal>accepted()</signal>
<receiver>ElementPropertiesEditorWidget</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_buttonBox</sender>
<signal>rejected()</signal>
<receiver>ElementPropertiesEditorWidget</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -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()){