2021-04-29 20:31:53 +02:00
|
|
|
|
/*
|
2021-04-02 20:52:38 +02:00
|
|
|
|
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 "terminalstripeditor.h"
|
|
|
|
|
#include "ui_terminalstripeditor.h"
|
2021-04-03 15:48:07 +02:00
|
|
|
|
#include "terminalstripcreatordialog.h"
|
|
|
|
|
#include "../../qetproject.h"
|
|
|
|
|
#include "../terminalstrip.h"
|
2021-04-04 19:42:02 +02:00
|
|
|
|
#include "../elementprovider.h"
|
|
|
|
|
#include "../qetgraphicsitem/terminalelement.h"
|
2021-04-06 20:06:20 +02:00
|
|
|
|
#include "../UndoCommand/addterminalstripcommand.h"
|
2021-04-28 20:35:39 +02:00
|
|
|
|
#include "../UndoCommand/addterminaltostripcommand.h"
|
2021-05-05 22:34:11 +02:00
|
|
|
|
#include "../UndoCommand/changeterminalstripdata.h"
|
2021-04-09 11:48:40 +02:00
|
|
|
|
#include "terminalstriptreewidget.h"
|
2021-04-09 14:16:22 +02:00
|
|
|
|
#include "../../qeticons.h"
|
2021-06-07 19:26:41 +02:00
|
|
|
|
#include "terminalstripmodel.h"
|
2021-04-02 20:52:38 +02:00
|
|
|
|
|
2021-04-03 15:48:07 +02:00
|
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief TerminalStripEditor::TerminalStripEditor
|
|
|
|
|
* @param project : Project to manage the terminal strip
|
|
|
|
|
* @param parent : paent widget
|
|
|
|
|
*/
|
2021-04-02 20:52:38 +02:00
|
|
|
|
TerminalStripEditor::TerminalStripEditor(QETProject *project, QWidget *parent) :
|
|
|
|
|
QDialog(parent),
|
|
|
|
|
ui(new Ui::TerminalStripEditor),
|
|
|
|
|
m_project(project)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2021-07-13 12:27:08 +02:00
|
|
|
|
ui->m_table_widget->setItemDelegate(new TerminalStripModelDelegate(ui->m_terminal_strip_tw));
|
2021-05-11 18:46:12 +02:00
|
|
|
|
ui->m_remove_terminal_strip_pb->setDisabled(true);
|
2021-04-03 15:48:07 +02:00
|
|
|
|
buildTree();
|
2021-04-29 20:31:53 +02:00
|
|
|
|
ui->m_terminal_strip_tw->expandRecursively(ui->m_terminal_strip_tw->rootIndex());
|
2021-04-28 20:35:39 +02:00
|
|
|
|
setUpUndoConnections();
|
2021-04-02 20:52:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 15:48:07 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief TerminalStripEditor::~TerminalStripEditor
|
|
|
|
|
*/
|
|
|
|
|
TerminalStripEditor::~TerminalStripEditor() {
|
2021-04-02 20:52:38 +02:00
|
|
|
|
delete ui;
|
|
|
|
|
}
|
2021-04-03 15:48:07 +02:00
|
|
|
|
|
2021-04-28 20:35:39 +02:00
|
|
|
|
void TerminalStripEditor::setUpUndoConnections()
|
|
|
|
|
{
|
|
|
|
|
connect(ui->m_terminal_strip_tw, &TerminalStripTreeWidget::terminalAddedToStrip,
|
|
|
|
|
[this](QUuid terminal_uuid, QUuid strip_uuid)
|
|
|
|
|
{
|
|
|
|
|
auto terminal = m_uuid_terminal_H.value(terminal_uuid);
|
|
|
|
|
auto strip = m_uuid_strip_H.value(strip_uuid);
|
|
|
|
|
|
|
|
|
|
if (!terminal || !strip) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto undo = new AddTerminalToStripCommand(terminal, strip);
|
|
|
|
|
m_project->undoStack()->push(undo);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(ui->m_terminal_strip_tw, &TerminalStripTreeWidget::terminalMovedFromStripToStrip,
|
|
|
|
|
[this] (QUuid terminal_uuid, QUuid old_strip_uuid, QUuid new_strip_uuid)
|
|
|
|
|
{
|
|
|
|
|
auto terminal = m_uuid_terminal_H.value(terminal_uuid);
|
|
|
|
|
auto old_strip = m_uuid_strip_H.value(old_strip_uuid);
|
|
|
|
|
auto new_strip = m_uuid_strip_H.value(new_strip_uuid);
|
|
|
|
|
|
|
|
|
|
if (!terminal || !old_strip || !new_strip) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto undo = new AddTerminalToStripCommand(terminal, old_strip, new_strip);
|
|
|
|
|
m_project->undoStack()->push(undo);
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-04 19:04:06 +02:00
|
|
|
|
connect(ui->m_terminal_strip_tw, &TerminalStripTreeWidget::terminalRemovedFromStrip,
|
|
|
|
|
[this] (QUuid terminal_uuid, QUuid old_strip_uuid)
|
|
|
|
|
{
|
|
|
|
|
auto terminal_ = m_uuid_terminal_H.value(terminal_uuid);
|
|
|
|
|
auto strip_ = m_uuid_strip_H.value(old_strip_uuid);
|
|
|
|
|
|
|
|
|
|
if (!terminal_ || !strip_) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto undo = new RemoveTerminalFromStripCommand(terminal_, strip_);
|
|
|
|
|
m_project->undoStack()->push(undo);
|
|
|
|
|
});
|
2021-04-28 20:35:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 15:48:07 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief TerminalStripEditor::buildTree
|
|
|
|
|
* Build the tree widget use to explore terminal strip
|
|
|
|
|
*/
|
|
|
|
|
void TerminalStripEditor::buildTree()
|
|
|
|
|
{
|
|
|
|
|
ui->m_terminal_strip_tw->clear();
|
|
|
|
|
|
|
|
|
|
auto title = m_project->title();
|
|
|
|
|
if (title.isEmpty()) {
|
2021-04-04 19:42:02 +02:00
|
|
|
|
title = tr("Projet sans titre");
|
2021-04-03 15:48:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList strl{title};
|
2021-04-09 11:48:40 +02:00
|
|
|
|
new QTreeWidgetItem(ui->m_terminal_strip_tw, strl, TerminalStripTreeWidget::Root);
|
2021-04-04 19:42:02 +02:00
|
|
|
|
|
|
|
|
|
QStringList ftstrl(tr("Bornes indépendante"));
|
2021-04-09 14:16:22 +02:00
|
|
|
|
new QTreeWidgetItem(ui->m_terminal_strip_tw, ftstrl, TerminalStripTreeWidget::FreeTerminal);
|
2021-04-03 15:48:07 +02:00
|
|
|
|
|
2021-04-06 20:06:20 +02:00
|
|
|
|
auto ts_vector = m_project->terminalStrip();
|
|
|
|
|
std::sort(ts_vector.begin(), ts_vector.end(), [](TerminalStrip *a, TerminalStrip *b) {
|
|
|
|
|
return a->name() < b->name();});
|
|
|
|
|
|
|
|
|
|
for (const auto ts : qAsConst(ts_vector)) {
|
2021-04-03 15:48:07 +02:00
|
|
|
|
addTerminalStrip(ts);
|
|
|
|
|
}
|
2021-04-04 19:42:02 +02:00
|
|
|
|
addFreeTerminal();
|
2021-04-03 15:48:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief TerminalStripEditor::addTerminalStrip
|
|
|
|
|
* Add a new terminal strip to the list of displayed terminal strip
|
|
|
|
|
* in the tree widget
|
|
|
|
|
* @param terminal_strip
|
|
|
|
|
* @return the QTreeWidgetItem who represent the terminal strip
|
2021-04-06 20:06:20 +02:00
|
|
|
|
* both if created or already exist
|
2021-04-03 15:48:07 +02:00
|
|
|
|
*/
|
|
|
|
|
QTreeWidgetItem* TerminalStripEditor::addTerminalStrip(TerminalStrip *terminal_strip)
|
|
|
|
|
{
|
2021-04-28 20:35:39 +02:00
|
|
|
|
if (auto item = m_item_strip_H.key(terminal_strip)) {
|
2021-04-06 20:06:20 +02:00
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 15:48:07 +02:00
|
|
|
|
auto root_item = ui->m_terminal_strip_tw->topLevelItem(0);
|
|
|
|
|
|
|
|
|
|
//Check if installation already exist
|
|
|
|
|
//if not create a new one
|
|
|
|
|
auto installation_str = terminal_strip->installation();
|
|
|
|
|
QTreeWidgetItem *inst_qtwi = nullptr;
|
|
|
|
|
for (int i = 0 ; i<root_item->childCount() ; ++i) {
|
|
|
|
|
auto child_inst = root_item->child(i);
|
|
|
|
|
if (child_inst->data(0, Qt::DisplayRole).toString() == installation_str) {
|
|
|
|
|
inst_qtwi = child_inst;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!inst_qtwi) {
|
|
|
|
|
QStringList inst_strl{installation_str};
|
2021-04-09 14:16:22 +02:00
|
|
|
|
inst_qtwi = new QTreeWidgetItem(root_item, inst_strl, TerminalStripTreeWidget::Installation);
|
2021-04-03 15:48:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Check if location already exist
|
|
|
|
|
//if not create a new one
|
|
|
|
|
auto location_str = terminal_strip->location();
|
|
|
|
|
QTreeWidgetItem *loc_qtwi = nullptr;
|
|
|
|
|
for (int i = 0 ; i<inst_qtwi->childCount() ; ++i) {
|
|
|
|
|
auto child_loc = inst_qtwi->child(i);
|
|
|
|
|
if (child_loc->data(0, Qt::DisplayRole).toString() == location_str) {
|
|
|
|
|
loc_qtwi = child_loc;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!loc_qtwi) {
|
|
|
|
|
QStringList loc_strl{location_str};
|
2021-04-09 14:16:22 +02:00
|
|
|
|
loc_qtwi = new QTreeWidgetItem(inst_qtwi, loc_strl, TerminalStripTreeWidget::Location);
|
2021-04-03 15:48:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Add the terminal strip
|
|
|
|
|
QStringList name{terminal_strip->name()};
|
2021-04-29 20:31:53 +02:00
|
|
|
|
auto strip_item = new QTreeWidgetItem(loc_qtwi, name, TerminalStripTreeWidget::Strip);
|
|
|
|
|
strip_item->setData(0, TerminalStripTreeWidget::UUID_USER_ROLE, terminal_strip->uuid());
|
|
|
|
|
strip_item->setIcon(0, QET::Icons::TerminalStrip);
|
2021-04-28 20:35:39 +02:00
|
|
|
|
|
2021-04-29 20:31:53 +02:00
|
|
|
|
//Add child terminal of the strip
|
|
|
|
|
for (auto i=0 ; i<terminal_strip->physicalTerminalCount() ; ++i)
|
|
|
|
|
{
|
|
|
|
|
auto index = terminal_strip->index(i);
|
|
|
|
|
auto term_item = new QTreeWidgetItem(strip_item, QStringList(index.label()), TerminalStripTreeWidget::Terminal);
|
|
|
|
|
term_item->setData(0, TerminalStripTreeWidget::UUID_USER_ROLE, index.uuid().toString());
|
|
|
|
|
term_item->setIcon(0, QET::Icons::ElementTerminal);
|
2021-05-03 22:25:43 +02:00
|
|
|
|
|
|
|
|
|
if (index.isElement()) {
|
|
|
|
|
m_uuid_terminal_H.insert(index.uuid(), index.element());
|
|
|
|
|
}
|
2021-04-29 20:31:53 +02:00
|
|
|
|
}
|
2021-04-28 20:35:39 +02:00
|
|
|
|
|
2021-04-29 20:31:53 +02:00
|
|
|
|
m_item_strip_H.insert(strip_item, terminal_strip);
|
2021-04-28 20:35:39 +02:00
|
|
|
|
m_uuid_strip_H.insert(terminal_strip->uuid(), terminal_strip);
|
2021-04-29 20:31:53 +02:00
|
|
|
|
return strip_item;
|
2021-04-03 15:48:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-04 19:42:02 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief TerminalStripEditor::addFreeTerminal
|
|
|
|
|
* Add free terminal (aka terminal which not belong to a terminal strip)
|
|
|
|
|
* in the tree widget
|
|
|
|
|
*/
|
|
|
|
|
void TerminalStripEditor::addFreeTerminal()
|
|
|
|
|
{
|
|
|
|
|
ElementProvider ep(m_project);
|
|
|
|
|
auto vector_ = ep.freeTerminal();
|
|
|
|
|
|
|
|
|
|
if (vector_.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Sort the terminal element by label
|
|
|
|
|
std::sort(vector_.begin(), vector_.end(), [](TerminalElement *a, TerminalElement *b) {
|
|
|
|
|
return a->actualLabel() < b->actualLabel();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
auto free_terminal_item = ui->m_terminal_strip_tw->topLevelItem(1);
|
|
|
|
|
|
|
|
|
|
for (const auto terminal : qAsConst(vector_))
|
|
|
|
|
{
|
2021-04-28 20:35:39 +02:00
|
|
|
|
QUuid uuid_ = terminal->uuid();
|
2021-04-04 19:42:02 +02:00
|
|
|
|
QStringList strl{terminal->actualLabel()};
|
2021-04-09 14:16:22 +02:00
|
|
|
|
auto item = new QTreeWidgetItem(free_terminal_item, strl, TerminalStripTreeWidget::Terminal);
|
2021-04-28 20:35:39 +02:00
|
|
|
|
item->setData(0, TerminalStripTreeWidget::UUID_USER_ROLE, uuid_.toString());
|
2021-04-09 14:16:22 +02:00
|
|
|
|
item->setIcon(0, QET::Icons::ElementTerminal);
|
2021-04-28 20:35:39 +02:00
|
|
|
|
|
|
|
|
|
m_uuid_terminal_H.insert(uuid_, terminal);
|
2021-04-04 19:42:02 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-05 21:40:36 +02:00
|
|
|
|
/**
|
2021-06-07 19:26:41 +02:00
|
|
|
|
* @brief TerminalStripEditor::setCurrentStrip
|
|
|
|
|
* Set the current terminal strip edited to \p strip_
|
|
|
|
|
* @param strip_
|
2021-05-05 21:40:36 +02:00
|
|
|
|
*/
|
2021-06-07 19:26:41 +02:00
|
|
|
|
void TerminalStripEditor::setCurrentStrip(TerminalStrip *strip_)
|
2021-05-05 21:40:36 +02:00
|
|
|
|
{
|
2021-06-07 19:26:41 +02:00
|
|
|
|
if (strip_ == m_current_strip) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strip_)
|
|
|
|
|
{
|
|
|
|
|
ui->m_installation_le ->clear();
|
|
|
|
|
ui->m_location_le ->clear();
|
|
|
|
|
ui->m_name_le ->clear();
|
|
|
|
|
ui->m_comment_le ->clear();
|
|
|
|
|
ui->m_description_te ->clear();
|
|
|
|
|
m_current_strip = nullptr;
|
|
|
|
|
|
|
|
|
|
ui->m_table_widget->setModel(nullptr);
|
|
|
|
|
if (m_model) {
|
|
|
|
|
m_model->deleteLater();
|
|
|
|
|
m_model = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->m_installation_le ->setText(strip_->installation());
|
|
|
|
|
ui->m_location_le ->setText(strip_->location());
|
|
|
|
|
ui->m_name_le ->setText(strip_->name());
|
|
|
|
|
ui->m_comment_le ->setText(strip_->comment());
|
|
|
|
|
ui->m_description_te ->setPlainText(strip_->description());
|
|
|
|
|
m_current_strip = strip_;
|
|
|
|
|
|
|
|
|
|
if (m_model)
|
|
|
|
|
m_model->deleteLater();
|
|
|
|
|
|
|
|
|
|
m_model = new TerminalStripModel(strip_, this);
|
|
|
|
|
ui->m_table_widget->setModel(m_model);
|
|
|
|
|
}
|
2021-05-05 21:40:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 15:48:07 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief TerminalStripEditor::on_m_add_terminal_strip_pb_clicked
|
|
|
|
|
* Action when user click on add terminal strip button
|
|
|
|
|
*/
|
|
|
|
|
void TerminalStripEditor::on_m_add_terminal_strip_pb_clicked()
|
|
|
|
|
{
|
|
|
|
|
QScopedPointer<TerminalStripCreatorDialog> dialog(new TerminalStripCreatorDialog(m_project, this));
|
|
|
|
|
|
|
|
|
|
if (auto item = ui->m_terminal_strip_tw->currentItem())
|
|
|
|
|
{
|
2021-04-09 11:48:40 +02:00
|
|
|
|
if (item->type() == TerminalStripTreeWidget::Strip) {
|
2021-04-03 15:48:07 +02:00
|
|
|
|
item = item->parent();
|
|
|
|
|
}
|
2021-04-09 14:16:22 +02:00
|
|
|
|
if (item->type() == TerminalStripTreeWidget::Location) {
|
2021-04-03 15:48:07 +02:00
|
|
|
|
dialog->setLocation(item->data(0, Qt::DisplayRole).toString());
|
|
|
|
|
item = item->parent();
|
|
|
|
|
}
|
2021-04-09 14:16:22 +02:00
|
|
|
|
if (item->type() == TerminalStripTreeWidget::Installation) {
|
2021-04-03 15:48:07 +02:00
|
|
|
|
dialog->setInstallation(item->data(0, Qt::DisplayRole).toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
|
{
|
2021-04-06 20:06:20 +02:00
|
|
|
|
auto ts = dialog->generatedTerminalStrip();
|
|
|
|
|
m_project->undoStack()->push(new AddTerminalStripCommand(ts, m_project));
|
|
|
|
|
|
|
|
|
|
auto item = addTerminalStrip(ts);
|
2021-04-03 15:48:07 +02:00
|
|
|
|
ui->m_terminal_strip_tw->setCurrentItem(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-06 20:06:20 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief TerminalStripEditor::on_m_remove_terminal_strip_pb_clicked
|
|
|
|
|
* Action when user click on remove terminal strip button
|
|
|
|
|
*/
|
|
|
|
|
void TerminalStripEditor::on_m_remove_terminal_strip_pb_clicked()
|
|
|
|
|
{
|
|
|
|
|
auto item = ui->m_terminal_strip_tw->currentItem();
|
2021-04-28 20:35:39 +02:00
|
|
|
|
if (auto strip = m_item_strip_H.value(item))
|
2021-04-06 20:06:20 +02:00
|
|
|
|
{
|
2021-04-28 20:35:39 +02:00
|
|
|
|
m_item_strip_H.remove(item);
|
|
|
|
|
m_uuid_strip_H.remove(strip->uuid());
|
2021-04-06 20:06:20 +02:00
|
|
|
|
delete item;
|
|
|
|
|
|
|
|
|
|
m_project->undoStack()->push(new RemoveTerminalStripCommand(strip, m_project));
|
|
|
|
|
}
|
2021-04-30 19:26:42 +02:00
|
|
|
|
|
|
|
|
|
on_m_reload_pb_clicked();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-05 21:40:36 +02:00
|
|
|
|
/**
|
|
|
|
|
* @brief TerminalStripEditor::on_m_reload_pb_clicked
|
|
|
|
|
*/
|
2021-04-30 19:26:42 +02:00
|
|
|
|
void TerminalStripEditor::on_m_reload_pb_clicked()
|
|
|
|
|
{
|
2021-05-11 18:46:12 +02:00
|
|
|
|
auto current_ = m_current_strip;
|
|
|
|
|
|
2021-04-30 19:26:42 +02:00
|
|
|
|
ui->m_terminal_strip_tw->clear();
|
|
|
|
|
m_item_strip_H.clear();
|
|
|
|
|
m_uuid_terminal_H.clear();
|
|
|
|
|
m_uuid_strip_H.clear();
|
|
|
|
|
|
2021-06-07 19:26:41 +02:00
|
|
|
|
qDeleteAll(m_item_strip_H.keyBegin(), m_item_strip_H.keyEnd());
|
2021-04-30 19:26:42 +02:00
|
|
|
|
|
|
|
|
|
buildTree();
|
2021-05-05 21:40:36 +02:00
|
|
|
|
ui->m_terminal_strip_tw->expandRecursively(ui->m_terminal_strip_tw->rootIndex());
|
2021-05-11 18:46:12 +02:00
|
|
|
|
|
|
|
|
|
//Reselect the tree widget item of the current edited strip
|
|
|
|
|
auto item = m_item_strip_H.key(current_);
|
|
|
|
|
if (item) {
|
|
|
|
|
ui->m_terminal_strip_tw->setCurrentItem(item);
|
|
|
|
|
}
|
2021-05-05 21:40:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief TerminalStripEditor::on_m_terminal_strip_tw_currentItemChanged
|
|
|
|
|
* @param current
|
|
|
|
|
* @param previous
|
|
|
|
|
*/
|
|
|
|
|
void TerminalStripEditor::on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(previous)
|
|
|
|
|
|
|
|
|
|
if (!current) {
|
2021-06-07 19:26:41 +02:00
|
|
|
|
setCurrentStrip(nullptr);
|
2021-05-11 18:46:12 +02:00
|
|
|
|
ui->m_remove_terminal_strip_pb->setDisabled(true);
|
2021-05-05 21:40:36 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TerminalStrip *strip_ = nullptr;
|
|
|
|
|
if (current->type() == TerminalStripTreeWidget::Strip) {
|
|
|
|
|
strip_ = m_item_strip_H.value(current);
|
2021-05-11 18:46:12 +02:00
|
|
|
|
ui->m_remove_terminal_strip_pb->setEnabled(true);
|
2021-05-05 21:40:36 +02:00
|
|
|
|
}
|
|
|
|
|
else if (current->type() == TerminalStripTreeWidget::Terminal
|
|
|
|
|
&& current->parent()
|
|
|
|
|
&& current->parent()->type() == TerminalStripTreeWidget::Strip) {
|
|
|
|
|
strip_ = m_item_strip_H.value(current->parent());
|
2021-05-11 18:46:12 +02:00
|
|
|
|
ui->m_remove_terminal_strip_pb->setDisabled(true);
|
|
|
|
|
} else {
|
|
|
|
|
ui->m_remove_terminal_strip_pb->setDisabled(true);
|
2021-05-05 21:40:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-07 19:26:41 +02:00
|
|
|
|
setCurrentStrip(strip_);
|
2021-04-06 20:06:20 +02:00
|
|
|
|
}
|
2021-05-05 22:34:11 +02:00
|
|
|
|
|
2021-07-12 19:16:01 +02:00
|
|
|
|
void TerminalStripEditor::on_m_dialog_button_box_clicked(QAbstractButton *button)
|
2021-05-05 22:34:11 +02:00
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(button)
|
|
|
|
|
|
2021-07-12 19:16:01 +02:00
|
|
|
|
auto role = ui->m_dialog_button_box->buttonRole(button);
|
|
|
|
|
|
2021-07-13 12:27:08 +02:00
|
|
|
|
if (role == QDialogButtonBox::ApplyRole) {
|
2021-07-12 19:16:01 +02:00
|
|
|
|
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));
|
|
|
|
|
}
|
2021-05-05 22:34:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
on_m_reload_pb_clicked();
|
|
|
|
|
}
|