From b36178887358f723c6fd5ab57b90c6b3cd66c68a Mon Sep 17 00:00:00 2001 From: blacksun Date: Wed, 12 Feb 2014 17:36:35 +0000 Subject: [PATCH] Add ability to store informations for element like label, manufacturer, ref etc.... Add widget to edit it, save/load works Informations are stored in a diagramcontext, this class was modified (new feature) to store information but keep compatibilty with older version. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2850 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/diagramcontext.cpp | 23 ++++++- sources/diagramcontext.h | 6 +- sources/qetapp.cpp | 30 +++++++++ sources/qetapp.h | 2 + sources/qetgraphicsitem/element.cpp | 9 +++ sources/qetgraphicsitem/element.h | 40 ++++++++---- sources/ui/elementinfopartwidget.cpp | 75 +++++++++++++++++++++ sources/ui/elementinfopartwidget.h | 46 +++++++++++++ sources/ui/elementinfopartwidget.ui | 62 ++++++++++++++++++ sources/ui/elementinfowidget.cpp | 90 ++++++++++++++++++++++++++ sources/ui/elementinfowidget.h | 54 ++++++++++++++++ sources/ui/elementinfowidget.ui | 79 ++++++++++++++++++++++ sources/ui/elementpropertieswidget.cpp | 8 ++- sources/ui/elementpropertieswidget.h | 2 + 14 files changed, 510 insertions(+), 16 deletions(-) create mode 100644 sources/ui/elementinfopartwidget.cpp create mode 100644 sources/ui/elementinfopartwidget.h create mode 100644 sources/ui/elementinfopartwidget.ui create mode 100644 sources/ui/elementinfowidget.cpp create mode 100644 sources/ui/elementinfowidget.h create mode 100644 sources/ui/elementinfowidget.ui diff --git a/sources/diagramcontext.cpp b/sources/diagramcontext.cpp index eaf155962..18bec9eeb 100644 --- a/sources/diagramcontext.cpp +++ b/sources/diagramcontext.cpp @@ -53,16 +53,20 @@ const QVariant DiagramContext::operator[](const QString &key) const { /** @param key key to insert in the context - the key may only contain lowercase - letters and dashes + letters and dashes. + If embedded key is set, key must be find it else value is not added. @see DiagramContext::keyIsAcceptable() @param value value to insert in the context + @param show if value is used to be show on the diagram or somewhere else, + we can specify if he is show(true) or not(false) @return true if the insertion succeeds, false otherwise */ -bool DiagramContext::addValue(const QString &key, const QVariant &value) { +bool DiagramContext::addValue(const QString &key, const QVariant &value, bool show) { if (keyIsAcceptable(key)) { content_.insert(key, value); + content_show.insert(key, show); return(true); - } + } return(false); } @@ -71,6 +75,7 @@ bool DiagramContext::addValue(const QString &key, const QVariant &value) { */ void DiagramContext::clear() { content_.clear(); + content_show.clear(); } /** @@ -80,6 +85,16 @@ int DiagramContext::count() { return(content_.count()); } +/** + * @brief DiagramContext::keyMustShow + * @return the value pairs with key, if key no found, return false + */ +bool DiagramContext::keyMustShow(const QString &key) const { + if (content_show.contains(key)) + return content_show[key]; + return false; +} + bool DiagramContext::operator==(const DiagramContext &dc) const { return(content_ == dc.content_); } @@ -96,6 +111,7 @@ void DiagramContext::toXml(QDomElement &e, const QString &tag_name) const { foreach (QString key, keys()) { QDomElement property = e.ownerDocument().createElement(tag_name); property.setAttribute("name", key); + property.setAttribute("show",content_show[key]); QDomText value = e.ownerDocument().createTextNode(content_[key].toString()); property.appendChild(value); e.appendChild(property); @@ -110,6 +126,7 @@ void DiagramContext::fromXml(const QDomElement &e, const QString &tag_name) { foreach (QDomElement property, QET::findInDomElement(e, tag_name)) { if (!property.hasAttribute("name")) continue; addValue(property.attribute("name"), QVariant(property.text())); + content_show.insert(property.attribute("name"), property.attribute("show", "1").toInt()); } } diff --git a/sources/diagramcontext.h b/sources/diagramcontext.h index 44eaea1f9..49fc0b4b9 100644 --- a/sources/diagramcontext.h +++ b/sources/diagramcontext.h @@ -22,6 +22,7 @@ #include #include #include +#include /** This class represents a diagram context, i.e. the data (a list of key/value pairs) of a diagram at a given time. It is notably used by titleblock templates @@ -34,12 +35,14 @@ class DiagramContext { Alphabetical, DecreasingLength }; + QList keys(KeyOrder = None) const; bool contains(const QString &) const; const QVariant operator[](const QString &) const; - bool addValue(const QString &, const QVariant &); + bool addValue(const QString &, const QVariant &, bool show = true); void clear(); int count(); + bool keyMustShow (const QString &) const; bool operator==(const DiagramContext &) const; bool operator!=(const DiagramContext &) const; @@ -56,5 +59,6 @@ class DiagramContext { bool keyIsAcceptable(const QString &) const; /// Diagram context data (key/value pairs) QHash content_; + QHash content_show; }; #endif diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index 8933243a3..a77b73e2a 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -337,6 +337,36 @@ ElementsCollectionCache *QETApp::collectionCache() { return(collections_cache_); } +/** + * @brief QETApp::elementInfoKeys + * @return all available key for describe an element + */ +QStringList QETApp::elementInfoKeys() { + QStringList info_list; + info_list << "label" + << "comment" + << "manufacturer" + << "manufacturer-reference" + << "machine-manufacturer-reference"; + return info_list; +} + +/** + * @brief ElementsProperties::translatedInfo + * Return the translated information key given by @info + * If @info don't match, return an empty string + * @param info the key to be translated + * @return + */ +QString QETApp::elementTranslatedInfoKey(QString &info) { + if (info == "label") return tr("Label"); + else if (info == "comment") return tr("Commentaire"); + else if (info == "manufacturer") return tr("Fabriquant"); + else if (info == "manufacturer-reference") return tr("R\351f\351rence fabriquant"); + else if (info == "machine-manufacturer-reference") return tr("R\351f\351rence fabriquant machine"); + return (info); +} + /** @return the common title block templates collection, i.e. the one provided by QElecrotTech diff --git a/sources/qetapp.h b/sources/qetapp.h index aaa0a8264..337ab0a3a 100644 --- a/sources/qetapp.h +++ b/sources/qetapp.h @@ -74,6 +74,8 @@ class QETApp : public QETSingleApplication { static ElementsCollection *customElementsCollection(); static QList availableCollections(); static ElementsCollectionCache *collectionCache(); + static QStringList elementInfoKeys(); + static QString elementTranslatedInfoKey(QString &); static TitleBlockTemplatesFilesCollection *commonTitleBlockTemplatesCollection(); static TitleBlockTemplatesFilesCollection *customTitleBlockTemplatesCollection(); diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 5ad326769..09797a2ed 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -24,6 +24,7 @@ #include #include #include "elementprovider.h" +#include "elementsproperties.h" /** Constructeur pour un element sans scene ni parent @@ -395,6 +396,9 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool //uuid of this element uuid_= QUuid(e.attribute("uuid", QUuid::createUuid().toString())); + //load informations + informations_.fromXml(e.firstChildElement("informations"), "information"); + // position, selection setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble()); setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); @@ -473,6 +477,11 @@ QDomElement Element::toXml(QDomDocument &document, QHash &table } element.appendChild(links_uuids); } + + //save information of this element + QDomElement infos = document.createElement("informations"); + informations_.toXml(infos, "information"); + element.appendChild(infos); return(element); } diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index b4c10b540..108b79059 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -21,6 +21,7 @@ #include "terminal.h" #include "qetgraphicsitem.h" #include +#include "elementsproperties.h" class Diagram; class ElementTextItem; @@ -35,8 +36,7 @@ class Element : public QetGraphicsItem { // constructors, destructor public: Element(QGraphicsItem * = 0, Diagram * = 0); - virtual ~Element(); - + virtual ~Element(); private: Element(const Element &); @@ -55,15 +55,11 @@ class Element : public QetGraphicsItem { AllSlave = 48, Bornier = 64}; - protected: - QList connected_elements; - QList tmp_uuids_link; - private: QSize dimensions; QPoint hotspot_coord; QPixmap preview; - QUuid uuid_; + // methods public: @@ -98,19 +94,41 @@ class Element : public QetGraphicsItem { /// @return the maximum number of terminals for this element virtual int maxTerminalsCount() const = 0; - // related method for link between element + + /** + *related method and attributes, + *about none graphic thing + *like the linked element or information about this element + */ + //METHODS related to linked element + public: bool isFree () const; virtual void linkToElement(Element *) {} virtual void unlinkAllElements() {} - virtual void unlinkElement(Element *elmt) {} + virtual void unlinkElement(Element *) {} void initLink(QETProject *); QList linkedElements () const; - //create new uuid for this element - void newUuid() {uuid_ = QUuid::createUuid();} + void newUuid() {uuid_ = QUuid::createUuid();} //create new uuid for this element + + //ATTRIBUTES related to linked element + protected: + QList connected_elements; + QList tmp_uuids_link; + QUuid uuid_; + + //METHODS related to information + public: + DiagramContext informations()const {return informations_;} + void setInformations(DiagramContext dc) {informations_ = dc;} + + //ATTRIBUTES + protected: + DiagramContext informations_; /** Draw this element */ + public: virtual void paint(QPainter *, const QStyleOptionGraphicsItem *) = 0; /// @return This element type ID virtual QString typeId() const = 0; diff --git a/sources/ui/elementinfopartwidget.cpp b/sources/ui/elementinfopartwidget.cpp new file mode 100644 index 000000000..94ec29832 --- /dev/null +++ b/sources/ui/elementinfopartwidget.cpp @@ -0,0 +1,75 @@ +/* + 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 "elementinfopartwidget.h" +#include "ui_elementinfopartwidget.h" + + +/** + * @brief ElementInfoPartWidget::ElementInfoPartWidget + * Constructor + * @param key the string key what represent this info part + * @param translated_key the string key translated + * @param parent parent widget + */ +ElementInfoPartWidget::ElementInfoPartWidget(QString key, QString translated_key, QWidget *parent): + QWidget(parent), + ui(new Ui::ElementInfoPartWidget), + key_(key) +{ + ui->setupUi(this); + ui->label_->setText(translated_key); + if(key == "label") ui->checkBox->setChecked(true); +} + +/** + * @brief ElementInfoPartWidget::~ElementInfoPartWidget + * destructor + */ +ElementInfoPartWidget::~ElementInfoPartWidget() +{ + delete ui; +} + +/** + * @brief ElementInfoPartWidget::setText + * Set text to line edit + * @param txt + */ +void ElementInfoPartWidget::setText(const QString &txt) { + ui->line_edit->setText(txt); +} + +/** + * @brief ElementInfoPartWidget::text + * @return the text in the line edit + */ +QString ElementInfoPartWidget::text() const { + return (ui->line_edit->text()); +} + +/** + * @brief ElementInfoPartWidget::mustShow + * @return return true if the value must be show, else false + */ +bool ElementInfoPartWidget::mustShow() const { + return (ui->checkBox->isChecked()); +} + +void ElementInfoPartWidget::setShow(bool s) { + ui->checkBox->setChecked(s); +} diff --git a/sources/ui/elementinfopartwidget.h b/sources/ui/elementinfopartwidget.h new file mode 100644 index 000000000..515f31498 --- /dev/null +++ b/sources/ui/elementinfopartwidget.h @@ -0,0 +1,46 @@ +/* + 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 ELEMENTINFOPARTWIDGET_H +#define ELEMENTINFOPARTWIDGET_H + +#include + +namespace Ui { + class ElementInfoPartWidget; +} + +class ElementInfoPartWidget : public QWidget { + Q_OBJECT + + //METHODS + public: + explicit ElementInfoPartWidget(QString key, QString translated_key, QWidget *parent = 0); + ~ElementInfoPartWidget(); + QString key() const {return key_;} + void setText(const QString &); + QString text() const; + bool mustShow() const; + void setShow(bool); + + //ATTRIBUTES + private: + Ui::ElementInfoPartWidget *ui; + QString key_; +}; + +#endif // ELEMENTINFOPARTWIDGET_H diff --git a/sources/ui/elementinfopartwidget.ui b/sources/ui/elementinfopartwidget.ui new file mode 100644 index 000000000..9b924816c --- /dev/null +++ b/sources/ui/elementinfopartwidget.ui @@ -0,0 +1,62 @@ + + + ElementInfoPartWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + QLayout::SetMinimumSize + + + 0 + + + 2 + + + 0 + + + 2 + + + 0 + + + 2 + + + + + TextLabel + + + + + + + Visible + + + + + + + + + + + + + + diff --git a/sources/ui/elementinfowidget.cpp b/sources/ui/elementinfowidget.cpp new file mode 100644 index 000000000..0342c8c7c --- /dev/null +++ b/sources/ui/elementinfowidget.cpp @@ -0,0 +1,90 @@ +/* + 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 "elementinfowidget.h" +#include "ui_elementinfowidget.h" +#include "qetapp.h" + +/** + * @brief ElementInfoWidget::ElementInfoWidget + * Constructor + * @param elmt element to edit information + * @param parent parent widget + */ +ElementInfoWidget::ElementInfoWidget(Element *elmt, QWidget *parent) : + QWidget(parent), + ui(new Ui::ElementInfoWidget), + element_(elmt), + elmt_info(elmt->informations()) +{ + ui->setupUi(this); + buildInterface(); + fillInfo(); +} + +/** + * @brief ElementInfoWidget::~ElementInfoWidget + * Destructor + */ +ElementInfoWidget::~ElementInfoWidget() +{ + qDeleteAll(eipw_list); + delete ui; +} + +/** + * @brief ElementInfoWidget::apply + * Apply the new information + */ +void ElementInfoWidget::apply() { + DiagramContext dc; + foreach (ElementInfoPartWidget *eipw, eipw_list) { + //add value only if they're something to store + if (!eipw->text().isEmpty()) + dc.addValue(eipw->key(), + eipw->text(), + eipw->mustShow()); + } + element_->setInformations(dc); +} + +/** + * @brief ElementInfoWidget::buildInterface + * Build the widget + */ +void ElementInfoWidget::buildInterface() { + foreach (QString str, QETApp::elementInfoKeys()) { + ElementInfoPartWidget *eipw = new ElementInfoPartWidget(str, QETApp::elementTranslatedInfoKey(str), this); + ui->scroll_vlayout->addWidget(eipw); + eipw_list << eipw; + } +} + +/** + * @brief ElementInfoWidget::fillInfo + * fill information fetch in elmt_info to the + * corresponding line edit + */ +void ElementInfoWidget::fillInfo() { + foreach (ElementInfoPartWidget *eipw, eipw_list) { + eipw->setText(elmt_info[eipw->key()].toString()); + eipw->setShow(elmt_info.keyMustShow(eipw->key())); + //check "show" if this eipw is label and if elmt_info haven't got value for label. + if (eipw->key() == "label" && (elmt_info["label"].toString().isEmpty())) + eipw->setShow(true); + } +} diff --git a/sources/ui/elementinfowidget.h b/sources/ui/elementinfowidget.h new file mode 100644 index 000000000..686ef4bd3 --- /dev/null +++ b/sources/ui/elementinfowidget.h @@ -0,0 +1,54 @@ +/* + 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 ELEMENTINFOWIDGET_H +#define ELEMENTINFOWIDGET_H + +#include +#include "qetgraphicsitem/element.h" +#include "diagramcontext.h" +#include "elementinfopartwidget.h" + +namespace Ui { + class ElementInfoWidget; +} + +/** + * @brief The ElementInfoWidget class + * this class is a widget to edit an element informations. + */ +class ElementInfoWidget : public QWidget { + Q_OBJECT + + //METHODS + public: + explicit ElementInfoWidget(Element *elmt, QWidget *parent = 0); + ~ElementInfoWidget(); + void apply(); + private: + void buildInterface(); + void fillInfo(); + + //ATTRIBUTES + private: + Ui::ElementInfoWidget *ui; + Element *element_; + DiagramContext elmt_info; + QList eipw_list; +}; + +#endif // ELEMENTINFOWIDGET_H diff --git a/sources/ui/elementinfowidget.ui b/sources/ui/elementinfowidget.ui new file mode 100644 index 000000000..c4e5cd2cb --- /dev/null +++ b/sources/ui/elementinfowidget.ui @@ -0,0 +1,79 @@ + + + ElementInfoWidget + + + + 0 + 0 + 443 + 300 + + + + + 0 + 0 + + + + Form + + + + 0 + + + + + + 0 + 0 + + + + true + + + + + 0 + 0 + 423 + 280 + + + + + 0 + 280 + + + + + 2 + + + QLayout::SetMinimumSize + + + 0 + + + 2 + + + 0 + + + 4 + + + + + + + + + + diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertieswidget.cpp index 729d9721b..352a50cdf 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertieswidget.cpp @@ -32,6 +32,7 @@ elementpropertieswidget::elementpropertieswidget(Element *elmt, QWidget *parent) diagram_ (elmt->diagram()) { frp_ = 0; + eiw_ = 0; buildInterface(); } @@ -109,6 +110,8 @@ void elementpropertieswidget::buildInterface() { //Add tab according to the element switch (element_ -> linkType()) { case Element::Simple: + eiw_ = new ElementInfoWidget(element_, this); + tab_ -> addTab(eiw_, tr("Information")); break; case Element::NextReport: frp_ = new FolioReportProperties(element_, this); @@ -119,6 +122,8 @@ void elementpropertieswidget::buildInterface() { tab_ -> addTab(frp_, tr("Report de folio")); break; case Element::Master: + eiw_ = new ElementInfoWidget(element_, this); + tab_ -> addTab(eiw_, tr("Information")); break; case Element::SlaveNC: break; @@ -153,7 +158,8 @@ void elementpropertieswidget::standardButtonClicked(QAbstractButton *button) { case QDialogButtonBox::ResetRole: break; case QDialogButtonBox::ApplyRole: - if (frp_) frp_->Apply(); + if (frp_) frp_->Apply(); //folio report widget + else if (eiw_) eiw_->apply(); //element information widget this->accept(); case QDialogButtonBox::RejectRole: this->reject(); diff --git a/sources/ui/elementpropertieswidget.h b/sources/ui/elementpropertieswidget.h index 57948437c..f2bd3d119 100644 --- a/sources/ui/elementpropertieswidget.h +++ b/sources/ui/elementpropertieswidget.h @@ -22,6 +22,7 @@ #include #include #include +#include class elementpropertieswidget : public QDialog { @@ -46,6 +47,7 @@ class elementpropertieswidget : public QDialog private: FolioReportProperties *frp_; + ElementInfoWidget *eiw_; QDialogButtonBox *dbb; Element *element_; Diagram *diagram_;