mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Add toolbar and buttons
Add 'add terminal strip' button. Add 'remove terminal strip' button Add 'reload' button
This commit is contained in:
@@ -18,6 +18,10 @@
|
|||||||
#include "terminalstripeditorwindow.h"
|
#include "terminalstripeditorwindow.h"
|
||||||
#include "ui_terminalstripeditorwindow.h"
|
#include "ui_terminalstripeditorwindow.h"
|
||||||
#include "terminalstriptreedockwidget.h"
|
#include "terminalstriptreedockwidget.h"
|
||||||
|
#include "../terminalstrip.h"
|
||||||
|
#include "terminalstripcreatordialog.h"
|
||||||
|
#include "../UndoCommand/addterminalstripcommand.h"
|
||||||
|
#include "../../qetproject.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalStripEditorWindow::TerminalStripEditorWindow
|
* @brief TerminalStripEditorWindow::TerminalStripEditorWindow
|
||||||
@@ -30,7 +34,10 @@ TerminalStripEditorWindow::TerminalStripEditorWindow(QETProject *project, QWidge
|
|||||||
m_project(project)
|
m_project(project)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
ui->m_remove_terminal->setDisabled(true);
|
||||||
addTreeDockWidget();
|
addTreeDockWidget();
|
||||||
|
|
||||||
|
connect(m_tree_dock, &TerminalStripTreeDockWidget::currentStripChanged, this, &TerminalStripEditorWindow::currentStripChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,3 +58,71 @@ void TerminalStripEditorWindow::addTreeDockWidget()
|
|||||||
|
|
||||||
addDockWidget(Qt::LeftDockWidgetArea, m_tree_dock);
|
addDockWidget(Qt::LeftDockWidgetArea, m_tree_dock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripEditorWindow::currentStripChanged
|
||||||
|
* @param strip
|
||||||
|
*/
|
||||||
|
void TerminalStripEditorWindow::currentStripChanged(TerminalStrip *strip)
|
||||||
|
{
|
||||||
|
Q_UNUSED(strip)
|
||||||
|
ui->m_remove_terminal->setEnabled(m_tree_dock->currentIsStrip());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripEditorWindow::on_m_add_terminal_strip_triggered
|
||||||
|
* Action when user click on add terminal strip button
|
||||||
|
*/
|
||||||
|
void TerminalStripEditorWindow::on_m_add_terminal_strip_triggered()
|
||||||
|
{
|
||||||
|
QScopedPointer<TerminalStripCreatorDialog> dialog(new TerminalStripCreatorDialog(m_project, this));
|
||||||
|
|
||||||
|
dialog->setLocation(m_tree_dock->currentLocation());
|
||||||
|
dialog->setInstallation(m_tree_dock->currentInstallation());
|
||||||
|
|
||||||
|
if (dialog->exec() == QDialog::Accepted)
|
||||||
|
{
|
||||||
|
auto ts = dialog->generatedTerminalStrip();
|
||||||
|
m_project->undoStack()->push(new AddTerminalStripCommand(ts, m_project));
|
||||||
|
|
||||||
|
m_tree_dock->reload();
|
||||||
|
m_tree_dock->setSelectedStrip(ts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripEditorWindow::on_m_remove_terminal_triggered
|
||||||
|
*/
|
||||||
|
void TerminalStripEditorWindow::on_m_remove_terminal_triggered()
|
||||||
|
{
|
||||||
|
if (m_tree_dock->currentIsStrip())
|
||||||
|
{
|
||||||
|
if (auto strip_ = m_tree_dock->currentStrip())
|
||||||
|
{
|
||||||
|
m_project->undoStack()->push(new RemoveTerminalStripCommand(strip_, m_project));
|
||||||
|
m_tree_dock->reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// auto item = ui->m_tree_view->currentItem();
|
||||||
|
// if (auto strip = m_item_strip_H.value(item))
|
||||||
|
// {
|
||||||
|
// m_item_strip_H.remove(item);
|
||||||
|
// m_uuid_strip_H.remove(strip->uuid());
|
||||||
|
// delete item;
|
||||||
|
|
||||||
|
// m_project->undoStack()->push(new RemoveTerminalStripCommand(strip, m_project));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// on_m_reload_pb_clicked();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripEditorWindow::on_m_reload_triggered
|
||||||
|
*/
|
||||||
|
void TerminalStripEditorWindow::on_m_reload_triggered() {
|
||||||
|
m_tree_dock->reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
class QETProject;
|
class QETProject;
|
||||||
class TerminalStripTreeDockWidget;
|
class TerminalStripTreeDockWidget;
|
||||||
|
class TerminalStrip;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class TerminalStripEditorWindow;
|
class TerminalStripEditorWindow;
|
||||||
@@ -35,8 +36,14 @@ class TerminalStripEditorWindow : public QMainWindow
|
|||||||
explicit TerminalStripEditorWindow(QETProject *project, QWidget *parent = nullptr);
|
explicit TerminalStripEditorWindow(QETProject *project, QWidget *parent = nullptr);
|
||||||
~TerminalStripEditorWindow();
|
~TerminalStripEditorWindow();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_m_add_terminal_strip_triggered();
|
||||||
|
void on_m_remove_terminal_triggered();
|
||||||
|
void on_m_reload_triggered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addTreeDockWidget();
|
void addTreeDockWidget();
|
||||||
|
void currentStripChanged(TerminalStrip *strip);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::TerminalStripEditorWindow *ui;
|
Ui::TerminalStripEditorWindow *ui;
|
||||||
|
|||||||
@@ -25,7 +25,59 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
<widget class="QToolBar" name="toolBar">
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>toolBar</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="toolBarArea">
|
||||||
|
<enum>TopToolBarArea</enum>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="toolBarBreak">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
<addaction name="m_add_terminal_strip"/>
|
||||||
|
<addaction name="m_remove_terminal"/>
|
||||||
|
<addaction name="m_reload"/>
|
||||||
|
</widget>
|
||||||
|
<action name="m_add_terminal_strip">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../../qelectrotech.qrc">
|
||||||
|
<normaloff>:/ico/16x16/list-add.png</normaloff>:/ico/16x16/list-add.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Ajouter un bornier</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Ajouter un bornier au projet</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="m_remove_terminal">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../../qelectrotech.qrc">
|
||||||
|
<normaloff>:/ico/16x16/list-remove.png</normaloff>:/ico/16x16/list-remove.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Supprimer le bornier</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Supprimer le bornier du projet</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="m_reload">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../../qelectrotech.qrc">
|
||||||
|
<normaloff>:/ico/16x16/view-refresh.png</normaloff>:/ico/16x16/view-refresh.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Recharger</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Recharger les borniers</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources>
|
||||||
|
<include location="../../../qelectrotech.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
@@ -49,12 +49,132 @@ TerminalStripTreeDockWidget::~TerminalStripTreeDockWidget()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripTreeDockWidget::reload
|
||||||
|
*/
|
||||||
|
void TerminalStripTreeDockWidget::reload()
|
||||||
|
{
|
||||||
|
auto current_ = m_current_strip;
|
||||||
|
|
||||||
|
ui->m_tree_view->clear();
|
||||||
|
m_item_strip_H.clear();
|
||||||
|
m_uuid_terminal_H.clear();
|
||||||
|
m_uuid_strip_H.clear();
|
||||||
|
|
||||||
|
|
||||||
|
buildTree();
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
|
||||||
|
ui->m_tree_view->expandRecursively(ui->m_tree_view->rootIndex());
|
||||||
|
#else
|
||||||
|
ui->m_terminal_strip_tw->expandAll();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//Reselect the tree widget item of the current edited strip
|
||||||
|
auto item = m_item_strip_H.key(current_);
|
||||||
|
if (item) {
|
||||||
|
ui->m_tree_view->setCurrentItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripTreeDockWidget::currentIsStrip
|
||||||
|
* @return true if the current selected item is a terminal strip.
|
||||||
|
*/
|
||||||
|
bool TerminalStripTreeDockWidget::currentIsStrip() const {
|
||||||
|
return m_item_strip_H.contains(ui->m_tree_view->currentItem());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripTreeDockWidget::currentStrip
|
||||||
|
* @return The current selected strip or nullptr if there is
|
||||||
|
* no strip selected;
|
||||||
|
*/
|
||||||
|
TerminalStrip *TerminalStripTreeDockWidget::currentStrip() const {
|
||||||
|
return m_current_strip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripTreeDockWidget::currentInstallation
|
||||||
|
* @return the installation according to the current selection
|
||||||
|
*/
|
||||||
|
QString TerminalStripTreeDockWidget::currentInstallation() const
|
||||||
|
{
|
||||||
|
if (m_current_strip) {
|
||||||
|
return m_current_strip->installation();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto item = ui->m_tree_view->currentItem())
|
||||||
|
{
|
||||||
|
if (item->type() == TerminalStripTreeWidget::Location) {
|
||||||
|
item = item->parent();
|
||||||
|
}
|
||||||
|
if (item->type() == TerminalStripTreeWidget::Installation) {
|
||||||
|
return item->data(0, Qt::DisplayRole).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripTreeDockWidget::currentLocation
|
||||||
|
* @return the location according to the current selection
|
||||||
|
*/
|
||||||
|
QString TerminalStripTreeDockWidget::currentLocation() const
|
||||||
|
{
|
||||||
|
if (m_current_strip) {
|
||||||
|
return m_current_strip->location();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto item = ui->m_tree_view->currentItem()) {
|
||||||
|
if (item->type() == TerminalStripTreeWidget::Location) {
|
||||||
|
return item->data(0, Qt::DisplayRole).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripTreeDockWidget::setSelectedStrip
|
||||||
|
* @param strip
|
||||||
|
*/
|
||||||
|
void TerminalStripTreeDockWidget::setSelectedStrip(TerminalStrip *strip) {
|
||||||
|
ui->m_tree_view->setCurrentItem(m_item_strip_H.key(strip));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripTreeDockWidget::on_m_tree_view_currentItemChanged
|
||||||
|
* @param current
|
||||||
|
* @param previous
|
||||||
|
*/
|
||||||
|
void TerminalStripTreeDockWidget::on_m_tree_view_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
|
||||||
|
{
|
||||||
|
Q_UNUSED(previous)
|
||||||
|
|
||||||
|
if (!current) {
|
||||||
|
setCurrentStrip(nullptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TerminalStrip *strip_ = nullptr;
|
||||||
|
if (current->type() == TerminalStripTreeWidget::Strip) {
|
||||||
|
strip_ = m_item_strip_H.value(current);
|
||||||
|
}
|
||||||
|
else if (current->type() == TerminalStripTreeWidget::Terminal
|
||||||
|
&& current->parent()
|
||||||
|
&& current->parent()->type() == TerminalStripTreeWidget::Strip) {
|
||||||
|
strip_ = m_item_strip_H.value(current->parent());
|
||||||
|
}
|
||||||
|
setCurrentStrip(strip_);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalStripTreeDockWidget::buildTree
|
* @brief TerminalStripTreeDockWidget::buildTree
|
||||||
*/
|
*/
|
||||||
void TerminalStripTreeDockWidget::buildTree()
|
void TerminalStripTreeDockWidget::buildTree()
|
||||||
{
|
{
|
||||||
ui->m_tree_view->clear();
|
|
||||||
|
|
||||||
auto title_ = m_project->title();
|
auto title_ = m_project->title();
|
||||||
if (title_.isEmpty()) {
|
if (title_.isEmpty()) {
|
||||||
@@ -232,3 +352,9 @@ void TerminalStripTreeDockWidget::setupUndoConnections()
|
|||||||
m_project->undoStack()->push(undo);
|
m_project->undoStack()->push(undo);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TerminalStripTreeDockWidget::setCurrentStrip(TerminalStrip *strip)
|
||||||
|
{
|
||||||
|
emit currentStripChanged(strip);
|
||||||
|
m_current_strip = strip;
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#define TERMINALSTRIPTREEDOCKWIDGET_H
|
#define TERMINALSTRIPTREEDOCKWIDGET_H
|
||||||
|
|
||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
class QETProject;
|
class QETProject;
|
||||||
class QTreeWidgetItem;
|
class QTreeWidgetItem;
|
||||||
@@ -37,16 +38,30 @@ class TerminalStripTreeDockWidget : public QDockWidget
|
|||||||
explicit TerminalStripTreeDockWidget(QETProject *project, QWidget *parent = nullptr);
|
explicit TerminalStripTreeDockWidget(QETProject *project, QWidget *parent = nullptr);
|
||||||
~TerminalStripTreeDockWidget();
|
~TerminalStripTreeDockWidget();
|
||||||
|
|
||||||
void buildTree();
|
void reload();
|
||||||
|
bool currentIsStrip() const;
|
||||||
|
TerminalStrip* currentStrip() const;
|
||||||
|
QString currentInstallation() const;
|
||||||
|
QString currentLocation() const;
|
||||||
|
void setSelectedStrip(TerminalStrip *strip);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void currentStripChanged(TerminalStrip *strip);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_m_tree_view_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void buildTree();
|
||||||
QTreeWidgetItem* addTerminalStrip(TerminalStrip *terminal_strip);
|
QTreeWidgetItem* addTerminalStrip(TerminalStrip *terminal_strip);
|
||||||
void addFreeTerminal();
|
void addFreeTerminal();
|
||||||
void setupUndoConnections();
|
void setupUndoConnections();
|
||||||
|
void setCurrentStrip(TerminalStrip *strip);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::TerminalStripTreeDockWidget *ui;
|
Ui::TerminalStripTreeDockWidget *ui;
|
||||||
QETProject *m_project = nullptr;
|
QPointer<QETProject> m_project;
|
||||||
|
QPointer<TerminalStrip> m_current_strip;
|
||||||
|
|
||||||
QHash<QTreeWidgetItem *, TerminalStrip *> m_item_strip_H;
|
QHash<QTreeWidgetItem *, TerminalStrip *> m_item_strip_H;
|
||||||
QHash<QUuid, QSharedPointer<RealTerminal>> m_uuid_terminal_H;
|
QHash<QUuid, QSharedPointer<RealTerminal>> m_uuid_terminal_H;
|
||||||
|
|||||||
Reference in New Issue
Block a user