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-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-04-03 15:48:07 +02:00
|
|
|
buildTree();
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @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()) {
|
|
|
|
title = tr("Projet : sans titre");
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList strl{title};
|
|
|
|
new QTreeWidgetItem(ui->m_terminal_strip_tw, strl, TerminalStripEditor::Root);
|
|
|
|
|
|
|
|
const auto ts_vector = m_project->terminalStrip();
|
|
|
|
for (const auto ts : ts_vector) {
|
|
|
|
addTerminalStrip(ts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
QTreeWidgetItem* TerminalStripEditor::addTerminalStrip(TerminalStrip *terminal_strip)
|
|
|
|
{
|
|
|
|
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};
|
|
|
|
inst_qtwi = new QTreeWidgetItem(root_item, inst_strl, TerminalStripEditor::Inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
//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};
|
|
|
|
loc_qtwi = new QTreeWidgetItem(inst_qtwi, loc_strl, TerminalStripEditor::Loc);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Add the terminal strip
|
|
|
|
QStringList name{terminal_strip->name()};
|
|
|
|
return new QTreeWidgetItem(loc_qtwi, name, TerminalStripEditor::Strip);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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())
|
|
|
|
{
|
|
|
|
if (item->type() == TerminalStripEditor::Strip) {
|
|
|
|
item = item->parent();
|
|
|
|
}
|
|
|
|
if (item->type() == TerminalStripEditor::Loc) {
|
|
|
|
dialog->setLocation(item->data(0, Qt::DisplayRole).toString());
|
|
|
|
item = item->parent();
|
|
|
|
}
|
|
|
|
if (item->type() == TerminalStripEditor::Inst) {
|
|
|
|
dialog->setInstallation(item->data(0, Qt::DisplayRole).toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
auto item = addTerminalStrip(dialog->generatedTerminalStrip());
|
|
|
|
ui->m_terminal_strip_tw->setCurrentItem(item);
|
|
|
|
}
|
|
|
|
}
|