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
This commit is contained in:
blacksun
2014-02-12 17:36:35 +00:00
parent 2c8bf84795
commit b361788873
14 changed files with 510 additions and 16 deletions

View File

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

View File

@@ -22,6 +22,7 @@
#include <QSettings>
#include <QString>
#include <QVariant>
#include <QStringList>
/**
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<QString> 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<QString, QVariant> content_;
QHash<QString, bool> content_show;
};
#endif

View File

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

View File

@@ -74,6 +74,8 @@ class QETApp : public QETSingleApplication {
static ElementsCollection *customElementsCollection();
static QList<ElementsCollection *> availableCollections();
static ElementsCollectionCache *collectionCache();
static QStringList elementInfoKeys();
static QString elementTranslatedInfoKey(QString &);
static TitleBlockTemplatesFilesCollection *commonTitleBlockTemplatesCollection();
static TitleBlockTemplatesFilesCollection *customTitleBlockTemplatesCollection();

View File

@@ -24,6 +24,7 @@
#include <QtDebug>
#include <ui/elementpropertieswidget.h>
#include "elementprovider.h"
#include "elementsproperties.h"
/**
Constructeur pour un element sans scene ni parent
@@ -395,6 +396,9 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &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);
@@ -474,6 +478,11 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
element.appendChild(links_uuids);
}
//save information of this element
QDomElement infos = document.createElement("informations");
informations_.toXml(infos, "information");
element.appendChild(infos);
return(element);
}

View File

@@ -21,6 +21,7 @@
#include "terminal.h"
#include "qetgraphicsitem.h"
#include <QUuid>
#include "elementsproperties.h"
class Diagram;
class ElementTextItem;
@@ -36,7 +37,6 @@ class Element : public QetGraphicsItem {
public:
Element(QGraphicsItem * = 0, Diagram * = 0);
virtual ~Element();
private:
Element(const Element &);
@@ -55,15 +55,11 @@ class Element : public QetGraphicsItem {
AllSlave = 48,
Bornier = 64};
protected:
QList <Element *> connected_elements;
QList <QUuid> 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<Element *> 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 <Element *> connected_elements;
QList <QUuid> 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;

View File

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

View File

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

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ElementInfoPartWidget</class>
<widget class="QWidget" name="ElementInfoPartWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<property name="horizontalSpacing">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>2</number>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label_">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkBox">
<property name="toolTip">
<string>Visible</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLineEdit" name="line_edit"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

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

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef ELEMENTINFOWIDGET_H
#define ELEMENTINFOWIDGET_H
#include <QWidget>
#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 <ElementInfoPartWidget *> eipw_list;
};
#endif // ELEMENTINFOWIDGET_H

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ElementInfoWidget</class>
<widget class="QWidget" name="ElementInfoWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>443</width>
<height>300</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>423</width>
<height>280</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>280</height>
</size>
</property>
<layout class="QVBoxLayout" name="scroll_vlayout">
<property name="spacing">
<number>2</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

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

View File

@@ -22,6 +22,7 @@
#include <qetgraphicsitem/element.h>
#include <diagram.h>
#include <folioreportproperties.h>
#include <elementinfowidget.h>
class elementpropertieswidget : public QDialog
{
@@ -46,6 +47,7 @@ class elementpropertieswidget : public QDialog
private:
FolioReportProperties *frp_;
ElementInfoWidget *eiw_;
QDialogButtonBox *dbb;
Element *element_;
Diagram *diagram_;