mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Terminal strip can now be edited and managed by undo command
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright 2006-2021 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 "changeterminalstripdata.h"
|
||||
|
||||
ChangeTerminalStripData::ChangeTerminalStripData(TerminalStrip *strip,
|
||||
const TerminalStripData &data,
|
||||
QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
m_strip(strip),
|
||||
m_new_data(data)
|
||||
{
|
||||
setText(QObject::tr("Modifier les proriétés d'un groupe de bornes"));
|
||||
m_old_data = strip->data();
|
||||
}
|
||||
|
||||
void ChangeTerminalStripData::undo()
|
||||
{
|
||||
if (m_strip) {
|
||||
m_strip->setData(m_old_data);
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeTerminalStripData::redo()
|
||||
{
|
||||
if (m_strip) {
|
||||
m_strip->setData(m_new_data);
|
||||
}
|
||||
}
|
||||
41
sources/TerminalStrip/UndoCommand/changeterminalstripdata.h
Normal file
41
sources/TerminalStrip/UndoCommand/changeterminalstripdata.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright 2006-2021 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 CHANGETERMINALSTRIPDATA_H
|
||||
#define CHANGETERMINALSTRIPDATA_H
|
||||
|
||||
#include <QUndoCommand>
|
||||
#include "../terminalstripdata.h"
|
||||
#include "../terminalstrip.h"
|
||||
|
||||
/**
|
||||
* @brief The ChangeTerminalStripData class
|
||||
*/
|
||||
class ChangeTerminalStripData : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
ChangeTerminalStripData(TerminalStrip *strip, const TerminalStripData &data, QUndoCommand *parent = nullptr);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
private:
|
||||
QPointer<TerminalStrip> m_strip;
|
||||
TerminalStripData m_old_data, m_new_data;
|
||||
};
|
||||
|
||||
#endif // CHANGETERMINALSTRIPDATA_H
|
||||
@@ -318,6 +318,29 @@ void TerminalStrip::setDescription(const QString &description) {
|
||||
m_data.m_description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::data
|
||||
* @return The internal data of this strip
|
||||
*/
|
||||
TerminalStripData TerminalStrip::data() const {
|
||||
return m_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::setData
|
||||
* The internal data of this strip to data.
|
||||
* the uuid of the new data is set to the uuid
|
||||
* of the previous data to keep the uuid
|
||||
* of the terminal strip unchanged
|
||||
* @param data
|
||||
*/
|
||||
void TerminalStrip::setData(const TerminalStripData &data)
|
||||
{
|
||||
auto uuid_ = m_data.m_uuid;
|
||||
m_data = data;
|
||||
m_data.m_uuid = uuid_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::addTerminal
|
||||
* Add terminal to this terminal strip
|
||||
|
||||
@@ -59,6 +59,9 @@ class TerminalStrip : public QObject
|
||||
QString description() const {return m_data.m_description;}
|
||||
QUuid uuid() const {return m_data.m_uuid;}
|
||||
|
||||
TerminalStripData data() const;
|
||||
void setData(const TerminalStripData &data);
|
||||
|
||||
bool addTerminal (Element *terminal);
|
||||
bool removeTerminal (Element *terminal);
|
||||
bool haveTerminal (Element *terminal);
|
||||
|
||||
@@ -80,6 +80,18 @@ bool TerminalStripData::fromXml(const QDomElement &xml_element)
|
||||
return true;
|
||||
}
|
||||
|
||||
TerminalStripData &TerminalStripData::operator=(const TerminalStripData &other)
|
||||
{
|
||||
m_installation = other.m_installation;
|
||||
m_location = other.m_location;
|
||||
m_name = other.m_name;
|
||||
m_comment = other.m_comment;
|
||||
m_description = other.m_description;
|
||||
m_uuid = other.m_uuid;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
QDomElement TerminalStripData::infoToXml(QDomDocument &xml_doc, const QString &name, const QString &value)
|
||||
{
|
||||
auto xml_elmt = xml_doc.createElement("information");
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
class TerminalStripData : public PropertiesInterface
|
||||
{
|
||||
friend class TerminalStrip;
|
||||
friend class TerminalStripEditor;
|
||||
|
||||
public:
|
||||
TerminalStripData();
|
||||
@@ -37,6 +38,8 @@ class TerminalStripData : public PropertiesInterface
|
||||
|
||||
static QString xmlTagName() {return QStringLiteral("terminal_strip_data");}
|
||||
|
||||
TerminalStripData &operator= (const TerminalStripData &other);
|
||||
|
||||
private :
|
||||
static QDomElement infoToXml(QDomDocument &xml_doc, const QString &name, const QString &value);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "../qetgraphicsitem/terminalelement.h"
|
||||
#include "../UndoCommand/addterminalstripcommand.h"
|
||||
#include "../UndoCommand/addterminaltostripcommand.h"
|
||||
#include "../UndoCommand/changeterminalstripdata.h"
|
||||
#include "terminalstriptreewidget.h"
|
||||
#include "../../qeticons.h"
|
||||
|
||||
@@ -242,6 +243,7 @@ void TerminalStripEditor::clearDataTab()
|
||||
ui->m_name_le ->clear();
|
||||
ui->m_comment_le ->clear();
|
||||
ui->m_description_te ->clear();
|
||||
m_current_strip = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,6 +338,7 @@ void TerminalStripEditor::on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetI
|
||||
}
|
||||
|
||||
if (strip_) {
|
||||
m_current_strip = strip_;
|
||||
ui->m_installation_le ->setText(strip_->installation());
|
||||
ui->m_location_le ->setText(strip_->location());
|
||||
ui->m_name_le ->setText(strip_->name());
|
||||
@@ -345,3 +348,22 @@ void TerminalStripEditor::on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetI
|
||||
clearDataTab();
|
||||
}
|
||||
}
|
||||
|
||||
void TerminalStripEditor::on_m_apply_data_pb_clicked(QAbstractButton *button)
|
||||
{
|
||||
Q_UNUSED(button)
|
||||
|
||||
if (m_current_strip)
|
||||
{
|
||||
TerminalStripData data;
|
||||
data.m_installation = ui->m_installation_le->text();
|
||||
data.m_location = ui->m_location_le->text();
|
||||
data.m_name = ui->m_name_le->text();
|
||||
data.m_comment = ui->m_comment_le->text();
|
||||
data.m_description = ui->m_description_te->toPlainText();
|
||||
|
||||
m_project->undoStack()->push(new ChangeTerminalStripData(m_current_strip, data, nullptr));
|
||||
}
|
||||
|
||||
on_m_reload_pb_clicked();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ class QETProject;
|
||||
class TerminalStrip;
|
||||
class QTreeWidgetItem;
|
||||
class TerminalElement;
|
||||
class QAbstractButton;
|
||||
|
||||
/**
|
||||
* @brief The TerminalStripEditor class
|
||||
@@ -54,6 +55,7 @@ class TerminalStripEditor : public QDialog
|
||||
void on_m_remove_terminal_strip_pb_clicked();
|
||||
void on_m_reload_pb_clicked();
|
||||
void on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
void on_m_apply_data_pb_clicked(QAbstractButton *button);
|
||||
|
||||
private:
|
||||
Ui::TerminalStripEditor *ui;
|
||||
@@ -62,6 +64,7 @@ class TerminalStripEditor : public QDialog
|
||||
QHash<QTreeWidgetItem *, TerminalStrip *> m_item_strip_H;
|
||||
QHash<QUuid, QPointer<TerminalElement>> m_uuid_terminal_H;
|
||||
QHash<QUuid, QPointer<TerminalStrip>> m_uuid_strip_H;
|
||||
TerminalStrip *m_current_strip = nullptr;
|
||||
};
|
||||
|
||||
#endif // TERMINALSTRIPEDITOR_H
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>706</width>
|
||||
<height>396</height>
|
||||
<width>951</width>
|
||||
<height>491</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -146,6 +146,13 @@
|
||||
<string>Propriétés</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
@@ -160,12 +167,8 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Nom :</string>
|
||||
</property>
|
||||
</widget>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="m_name_le"/>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="Line" name="line">
|
||||
@@ -174,6 +177,22 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QPlainTextEdit" name="m_description_te"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Nom :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="m_location_le"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="m_installation_le"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
@@ -181,28 +200,47 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="m_location_le"/>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QPlainTextEdit" name="m_description_te"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="m_installation_le"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="m_name_le"/>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="m_comment_le"/>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="m_apply_data_pb">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Apply</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
Reference in New Issue
Block a user