mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
Add dialog to create terminal strip + display existing terminal strip
This commit is contained in:
@@ -17,16 +17,128 @@
|
||||
*/
|
||||
#include "terminalstripeditor.h"
|
||||
#include "ui_terminalstripeditor.h"
|
||||
#include "terminalstripcreatordialog.h"
|
||||
#include "../../qetproject.h"
|
||||
#include "../terminalstrip.h"
|
||||
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
/**
|
||||
* @brief TerminalStripEditor::TerminalStripEditor
|
||||
* @param project : Project to manage the terminal strip
|
||||
* @param parent : paent widget
|
||||
*/
|
||||
TerminalStripEditor::TerminalStripEditor(QETProject *project, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::TerminalStripEditor),
|
||||
m_project(project)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
buildTree();
|
||||
}
|
||||
|
||||
TerminalStripEditor::~TerminalStripEditor()
|
||||
{
|
||||
/**
|
||||
* @brief TerminalStripEditor::~TerminalStripEditor
|
||||
*/
|
||||
TerminalStripEditor::~TerminalStripEditor() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user