mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-03-18 08:09:58 +01:00
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:
75
sources/ui/elementinfopartwidget.cpp
Normal file
75
sources/ui/elementinfopartwidget.cpp
Normal 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);
|
||||
}
|
||||
46
sources/ui/elementinfopartwidget.h
Normal file
46
sources/ui/elementinfopartwidget.h
Normal 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
|
||||
62
sources/ui/elementinfopartwidget.ui
Normal file
62
sources/ui/elementinfopartwidget.ui
Normal 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>
|
||||
90
sources/ui/elementinfowidget.cpp
Normal file
90
sources/ui/elementinfowidget.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
54
sources/ui/elementinfowidget.h
Normal file
54
sources/ui/elementinfowidget.h
Normal 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
|
||||
79
sources/ui/elementinfowidget.ui
Normal file
79
sources/ui/elementinfowidget.ui
Normal 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>
|
||||
@@ -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();
|
||||
|
||||
@@ -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_;
|
||||
|
||||
Reference in New Issue
Block a user