mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Terminal strip add/remove is managed by undo stack
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#include "../terminalstrip.h"
|
#include "../terminalstrip.h"
|
||||||
#include "../elementprovider.h"
|
#include "../elementprovider.h"
|
||||||
#include "../qetgraphicsitem/terminalelement.h"
|
#include "../qetgraphicsitem/terminalelement.h"
|
||||||
|
#include "../UndoCommand/addterminalstripcommand.h"
|
||||||
|
|
||||||
#include <QTreeWidgetItem>
|
#include <QTreeWidgetItem>
|
||||||
|
|
||||||
@@ -65,8 +66,11 @@ void TerminalStripEditor::buildTree()
|
|||||||
QStringList ftstrl(tr("Bornes indépendante"));
|
QStringList ftstrl(tr("Bornes indépendante"));
|
||||||
new QTreeWidgetItem(ui->m_terminal_strip_tw, ftstrl, TerminalStripEditor::FreeTerminal);
|
new QTreeWidgetItem(ui->m_terminal_strip_tw, ftstrl, TerminalStripEditor::FreeTerminal);
|
||||||
|
|
||||||
const auto ts_vector = m_project->terminalStrip();
|
auto ts_vector = m_project->terminalStrip();
|
||||||
for (const auto ts : ts_vector) {
|
std::sort(ts_vector.begin(), ts_vector.end(), [](TerminalStrip *a, TerminalStrip *b) {
|
||||||
|
return a->name() < b->name();});
|
||||||
|
|
||||||
|
for (const auto ts : qAsConst(ts_vector)) {
|
||||||
addTerminalStrip(ts);
|
addTerminalStrip(ts);
|
||||||
}
|
}
|
||||||
addFreeTerminal();
|
addFreeTerminal();
|
||||||
@@ -78,9 +82,14 @@ void TerminalStripEditor::buildTree()
|
|||||||
* in the tree widget
|
* in the tree widget
|
||||||
* @param terminal_strip
|
* @param terminal_strip
|
||||||
* @return the QTreeWidgetItem who represent the terminal strip
|
* @return the QTreeWidgetItem who represent the terminal strip
|
||||||
|
* both if created or already exist
|
||||||
*/
|
*/
|
||||||
QTreeWidgetItem* TerminalStripEditor::addTerminalStrip(TerminalStrip *terminal_strip)
|
QTreeWidgetItem* TerminalStripEditor::addTerminalStrip(TerminalStrip *terminal_strip)
|
||||||
{
|
{
|
||||||
|
if (auto item = m_H_item_strip.key(terminal_strip)) {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
auto root_item = ui->m_terminal_strip_tw->topLevelItem(0);
|
auto root_item = ui->m_terminal_strip_tw->topLevelItem(0);
|
||||||
|
|
||||||
//Check if installation already exist
|
//Check if installation already exist
|
||||||
@@ -117,7 +126,9 @@ QTreeWidgetItem* TerminalStripEditor::addTerminalStrip(TerminalStrip *terminal_s
|
|||||||
|
|
||||||
//Add the terminal strip
|
//Add the terminal strip
|
||||||
QStringList name{terminal_strip->name()};
|
QStringList name{terminal_strip->name()};
|
||||||
return new QTreeWidgetItem(loc_qtwi, name, TerminalStripEditor::Strip);
|
auto item = new QTreeWidgetItem(loc_qtwi, name, TerminalStripEditor::Strip);
|
||||||
|
m_H_item_strip.insert(item, terminal_strip);
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,7 +183,26 @@ void TerminalStripEditor::on_m_add_terminal_strip_pb_clicked()
|
|||||||
|
|
||||||
if (dialog->exec() == QDialog::Accepted)
|
if (dialog->exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
auto item = addTerminalStrip(dialog->generatedTerminalStrip());
|
auto ts = dialog->generatedTerminalStrip();
|
||||||
|
m_project->undoStack()->push(new AddTerminalStripCommand(ts, m_project));
|
||||||
|
|
||||||
|
auto item = addTerminalStrip(ts);
|
||||||
ui->m_terminal_strip_tw->setCurrentItem(item);
|
ui->m_terminal_strip_tw->setCurrentItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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();
|
||||||
|
if (auto strip = m_H_item_strip.value(item))
|
||||||
|
{
|
||||||
|
m_H_item_strip.remove(item);
|
||||||
|
delete item;
|
||||||
|
|
||||||
|
m_project->undoStack()->push(new RemoveTerminalStripCommand(strip, m_project));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -57,10 +57,13 @@ class TerminalStripEditor : public QDialog
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_m_add_terminal_strip_pb_clicked();
|
void on_m_add_terminal_strip_pb_clicked();
|
||||||
|
void on_m_remove_terminal_strip_pb_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::TerminalStripEditor *ui;
|
Ui::TerminalStripEditor *ui;
|
||||||
QETProject *m_project = nullptr;
|
QETProject *m_project = nullptr;
|
||||||
|
|
||||||
|
QHash<QTreeWidgetItem *, TerminalStrip *> m_H_item_strip;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TERMINALSTRIPEDITOR_H
|
#endif // TERMINALSTRIPEDITOR_H
|
||||||
|
|||||||
Reference in New Issue
Block a user