mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
element master widget property: improve gui.
add slave element class. element class: replace diagramcontext informations by elementInformations because informations is already used in xml file for element. minor improvement. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2869 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "qetgraphicsitem/simpleelement.h"
|
||||
#include "qetgraphicsitem/reportelement.h"
|
||||
#include "qetgraphicsitem/masterelement.h"
|
||||
#include "qetgraphicsitem/slaveelement.h"
|
||||
|
||||
ElementFactory* ElementFactory::factory_ = 0;
|
||||
/**
|
||||
@@ -48,6 +49,7 @@ Element * ElementFactory::createElement(const ElementsLocation &location, QGraph
|
||||
QString link_type = element_definition->xml().attribute("link_type");
|
||||
if (link_type == "next_report" || link_type == "previous_report") return (new ReportElement(location, link_type, qgi, s, state));
|
||||
if (link_type == "master") return (new MasterElement(location, qgi, s, state));
|
||||
if (link_type == "slave") return (new SlaveElement (location, qgi, s, state));
|
||||
}
|
||||
|
||||
//default if nothing match for link_type
|
||||
|
||||
@@ -33,7 +33,7 @@ Element::Element(QGraphicsItem *parent, Diagram *scene) :
|
||||
internal_connections_(false),
|
||||
must_highlight_(false)
|
||||
{
|
||||
link_type_ = 0;
|
||||
link_type_ = Simple;
|
||||
uuid_ = QUuid::createUuid();
|
||||
setZValue(10);
|
||||
}
|
||||
@@ -397,7 +397,9 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
||||
uuid_= QUuid(e.attribute("uuid", QUuid::createUuid().toString()));
|
||||
|
||||
//load informations
|
||||
informations_.fromXml(e.firstChildElement("informations"), "information");
|
||||
element_informations_.fromXml(e.firstChildElement("elementInformations"), "elementInformation");
|
||||
//load kind informations
|
||||
kind_informations_.fromXml(e.firstChildElement("kindInformations"), "kindInformation");
|
||||
|
||||
// position, selection
|
||||
setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
|
||||
@@ -479,9 +481,19 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
||||
}
|
||||
|
||||
//save information of this element
|
||||
QDomElement infos = document.createElement("informations");
|
||||
informations_.toXml(infos, "information");
|
||||
if (! element_informations_.keys().isEmpty()) {
|
||||
QDomElement infos = document.createElement("elementInformations");
|
||||
element_informations_.toXml(infos, "elementInformation");
|
||||
element.appendChild(infos);
|
||||
}
|
||||
|
||||
//save kind_informations of this element
|
||||
if (! kind_informations_.keys().isEmpty()) {
|
||||
QDomElement kind_infos = document.createElement("kindInformations");
|
||||
kind_informations_.toXml(kind_infos, "kindInformation");
|
||||
element.appendChild(kind_infos);
|
||||
}
|
||||
|
||||
|
||||
return(element);
|
||||
}
|
||||
|
||||
@@ -44,15 +44,13 @@ class Element : public QetGraphicsItem {
|
||||
enum { Type = UserType + 1000 };
|
||||
// this enum is use to know the kind of element and
|
||||
// to use flag for element provider class
|
||||
enum {Simple = 1,
|
||||
enum kind {Simple = 1,
|
||||
NextReport = 2,
|
||||
PreviousReport = 4,
|
||||
AllReport = 6,
|
||||
Master = 8,
|
||||
SlaveNO = 16,
|
||||
SlaveNC = 32,
|
||||
AllSlave = 48,
|
||||
Bornier = 64};
|
||||
Slave = 16,
|
||||
Bornier = 32};
|
||||
|
||||
private:
|
||||
QSize dimensions;
|
||||
@@ -115,16 +113,19 @@ class Element : public QetGraphicsItem {
|
||||
QList <Element *> connected_elements;
|
||||
QList <QUuid> tmp_uuids_link;
|
||||
QUuid uuid_;
|
||||
int link_type_;
|
||||
kind link_type_;
|
||||
|
||||
//METHODS related to information
|
||||
public:
|
||||
DiagramContext informations()const {return informations_;}
|
||||
void setInformations(DiagramContext dc) {informations_ = dc;}
|
||||
DiagramContext elementInformations()const {return element_informations_;}
|
||||
void setElementInformations(DiagramContext dc) {element_informations_ = dc;}
|
||||
DiagramContext kindInformations() const {return kind_informations_;} //@kind_information_ is used to store more information
|
||||
//about the herited class like contactelement for know
|
||||
// kind of contact (simple tempo) or number of contact show by the element.
|
||||
|
||||
//ATTRIBUTES
|
||||
protected:
|
||||
DiagramContext informations_;
|
||||
DiagramContext element_informations_, kind_informations_;
|
||||
|
||||
/**
|
||||
Draw this element
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
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 "masterelement.h"
|
||||
|
||||
/**
|
||||
@@ -29,11 +46,8 @@ MasterElement::~MasterElement() {
|
||||
* @param elmt
|
||||
*/
|
||||
void MasterElement::linkToElement(Element *elmt) {
|
||||
// check if this element is already linked
|
||||
if (connected_elements.contains(elmt)) return;
|
||||
|
||||
//check if elmt is a slave
|
||||
if (elmt->linkType() == SlaveNO || elmt->linkType() == SlaveNC) {
|
||||
// check if element is slave and if isn't already linked
|
||||
if (elmt->linkType() == Slave && !connected_elements.contains(elmt)) {
|
||||
///TODO create the cross ref and connection
|
||||
connected_elements << elmt;
|
||||
elmt->linkToElement(this);
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
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 MASTERELEMENT_H
|
||||
#define MASTERELEMENT_H
|
||||
|
||||
|
||||
81
sources/qetgraphicsitem/slaveelement.cpp
Normal file
81
sources/qetgraphicsitem/slaveelement.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
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 "slaveelement.h"
|
||||
|
||||
/**
|
||||
* @brief SlaveElement::SlaveElement
|
||||
* Default constructor
|
||||
* @param location location of xml definition
|
||||
* @param qgi parent QGraphicItem
|
||||
* @param s parent diagram
|
||||
* @param state int used to know if the creation of element have error
|
||||
*/
|
||||
SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
|
||||
CustomElement(location, qgi, s, state)
|
||||
{
|
||||
link_type_ = Slave;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SlaveElement::~SlaveElement
|
||||
* default destructor
|
||||
*/
|
||||
SlaveElement::~SlaveElement() {
|
||||
unlinkAllElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SlaveElement::linkToElement
|
||||
* Link this slave to another element
|
||||
* For this class element must be a master
|
||||
* @param elmt
|
||||
*/
|
||||
void SlaveElement::linkToElement(Element *elmt) {
|
||||
// check if element is master and if isn't already linked
|
||||
if (elmt->linkType() == Master && !connected_elements.contains(elmt)) {
|
||||
if(!isFree()) unlinkAllElements();
|
||||
connected_elements << elmt;
|
||||
elmt->linkToElement(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SlaveElement::unlinkAllElements
|
||||
* Unlink all of the element in the QList connected_elements
|
||||
*/
|
||||
void SlaveElement::unlinkAllElements() {
|
||||
// if this element is free no need to do something
|
||||
if (!isFree()) {
|
||||
foreach(Element *elmt, connected_elements) {
|
||||
unlinkElement(elmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SlaveElement::unlinkElement
|
||||
* Unlink the given elmt in parametre
|
||||
* @param elmt
|
||||
*/
|
||||
void SlaveElement::unlinkElement(Element *elmt) {
|
||||
//Ensure elmt is linked to this element
|
||||
if (connected_elements.contains(elmt)) {
|
||||
connected_elements.removeOne(elmt);
|
||||
elmt->unlinkElement(this);
|
||||
}
|
||||
}
|
||||
39
sources/qetgraphicsitem/slaveelement.h
Normal file
39
sources/qetgraphicsitem/slaveelement.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
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 SLAVEELEMENT_H
|
||||
#define SLAVEELEMENT_H
|
||||
|
||||
#include "customelement.h"
|
||||
|
||||
class SlaveElement : public CustomElement
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SlaveElement (const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0);
|
||||
~SlaveElement();
|
||||
virtual void linkToElement(Element *elmt);
|
||||
virtual void unlinkAllElements();
|
||||
virtual void unlinkElement(Element *elmt);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // SLAVEELEMENT_H
|
||||
@@ -29,7 +29,7 @@ ElementInfoWidget::ElementInfoWidget(Element *elmt, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ElementInfoWidget),
|
||||
element_(elmt),
|
||||
elmt_info(elmt->informations())
|
||||
elmt_info(elmt->elementInformations())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
buildInterface();
|
||||
@@ -59,7 +59,7 @@ void ElementInfoWidget::apply() {
|
||||
eipw->text(),
|
||||
eipw->mustShow());
|
||||
}
|
||||
element_->setInformations(dc);
|
||||
element_->setElementInformations(dc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -122,14 +122,12 @@ void elementpropertieswidget::buildInterface() {
|
||||
tab_ -> addTab(frp_, tr("Report de folio"));
|
||||
break;
|
||||
case Element::Master:
|
||||
mpw_ = new MasterPropertiesWidget(this);
|
||||
tab_ -> addTab(mpw_, tr("R\351f\351rence crois\351 (maitre)"));
|
||||
mpw_ = new MasterPropertiesWidget(element_, this);
|
||||
tab_ -> addTab(mpw_, tr("R\351f\351rence crois\351e (maitre)"));
|
||||
eiw_ = new ElementInfoWidget(element_, this);
|
||||
tab_ -> addTab(eiw_, tr("Information"));
|
||||
break;
|
||||
case Element::SlaveNC:
|
||||
break;
|
||||
case Element::SlaveNO:
|
||||
case Element::Slave:
|
||||
break;
|
||||
case Element::Bornier:
|
||||
break;
|
||||
|
||||
@@ -1,14 +1,70 @@
|
||||
/*
|
||||
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 "masterpropertieswidget.h"
|
||||
#include "ui_masterpropertieswidget.h"
|
||||
#include <QListWidgetItem>
|
||||
#include <diagramposition.h>
|
||||
#include <elementprovider.h>
|
||||
|
||||
MasterPropertiesWidget::MasterPropertiesWidget(QWidget *parent) :
|
||||
MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::MasterPropertiesWidget)
|
||||
ui(new Ui::MasterPropertiesWidget),
|
||||
element_(elmt)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
buildInterface();
|
||||
}
|
||||
|
||||
MasterPropertiesWidget::~MasterPropertiesWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MasterPropertiesWidget::buildInterface() {
|
||||
ElementProvider elmt_prov(element_->diagram()->project());
|
||||
|
||||
foreach(Element *elmt, elmt_prov.freeElement(Element::Slave)) {
|
||||
//label for list widget
|
||||
QString widget_text;
|
||||
QString title = elmt->diagram()->title();
|
||||
if (title.isEmpty()) title = tr("Sans titre");
|
||||
widget_text += QString(tr("Folio\240 %1 (%2), position %3.")).arg(elmt->diagram()->folioIndex() + 1)
|
||||
.arg(title)
|
||||
.arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
|
||||
QListWidgetItem *lwi_ = new QListWidgetItem(elmt->pixmap(), widget_text);
|
||||
ui->free_list->addItem(lwi_);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MasterPropertiesWidget::on_link_button_clicked
|
||||
* move curent item in the free_list to linked_list
|
||||
*/
|
||||
void MasterPropertiesWidget::on_link_button_clicked() {
|
||||
//take the curent item from free_list and push it to linked_list
|
||||
ui->linked_list->addItem(
|
||||
ui->free_list->takeItem(
|
||||
ui->free_list->currentRow()));
|
||||
}
|
||||
|
||||
void MasterPropertiesWidget::on_unlink_button_clicked() {
|
||||
//take the curent item from linked_list and push it to free_list
|
||||
ui->free_list->addItem(
|
||||
ui->linked_list->takeItem(
|
||||
ui->linked_list->currentRow()));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,25 @@
|
||||
/*
|
||||
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 MASTERPROPERTIESWIDGET_H
|
||||
#define MASTERPROPERTIESWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <qetgraphicsitem/element.h>
|
||||
|
||||
namespace Ui {
|
||||
class MasterPropertiesWidget;
|
||||
@@ -12,11 +30,19 @@ class MasterPropertiesWidget : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MasterPropertiesWidget(QWidget *parent = 0);
|
||||
explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0);
|
||||
~MasterPropertiesWidget();
|
||||
|
||||
private:
|
||||
void buildInterface();
|
||||
|
||||
private slots:
|
||||
void on_link_button_clicked();
|
||||
void on_unlink_button_clicked();
|
||||
|
||||
private:
|
||||
Ui::MasterPropertiesWidget *ui;
|
||||
Element *element_;
|
||||
};
|
||||
|
||||
#endif // MASTERPROPERTIESWIDGET_H
|
||||
|
||||
@@ -1,21 +1,103 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<author/>
|
||||
<comment/>
|
||||
<exportmacro/>
|
||||
<class>MasterPropertiesWidget</class>
|
||||
<widget class="QWidget" name="MasterPropertiesWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>564</width>
|
||||
<height>318</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="1" column="1" rowspan="5">
|
||||
<widget class="QListWidget" name="free_list"/>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<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 row="4" column="2">
|
||||
<widget class="QPushButton" name="unlink_button">
|
||||
<property name="toolTip">
|
||||
<string>Délier l'élément séléctionné</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../qelectrotech.qrc">
|
||||
<normaloff>:/ico/16x16/arrow-left.png</normaloff>:/ico/16x16/arrow-left.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
<pixmapfunction/>
|
||||
</item>
|
||||
<item row="1" column="3" rowspan="5">
|
||||
<widget class="QListWidget" name="linked_list"/>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QPushButton" name="link_button">
|
||||
<property name="toolTip">
|
||||
<string>Lier l'élément séléctionné</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../qelectrotech.qrc">
|
||||
<normaloff>:/ico/16x16/arrow-right.png</normaloff>:/ico/16x16/arrow-right.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Éléments disponibles</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Éléments liés</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<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>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../qelectrotech.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user