mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-03-17 15:49:59 +01:00
Merge branch 'terminal_strip'
* terminal_strip: Terminal strip item can saved / loaded to .qet file See previous commit... Move terminal strip drawer class in is own file Fix wrong use of QStringLiteral and QLatin1String Double click a TerminalStripItem open the editor Minor change about checkable QAction of QetDiagramEditor Minor : corrects a minor aesthetic defect when unbridge terminals Revamp code Add and move terminal strip item are now managed by undo command TerminalStripItem : Draw terminal bridge Terminal strip item can be added to diagram Minor : add QGIUtility namespace
This commit is contained in:
88
sources/TerminalStrip/ui/addterminalstripitemdialog.cpp
Normal file
88
sources/TerminalStrip/ui/addterminalstripitemdialog.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright 2006-2022 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 "addterminalstripitemdialog.h"
|
||||
#include "ui_addterminalstripitemdialog.h"
|
||||
|
||||
#include "../../undocommand/addgraphicsobjectcommand.h"
|
||||
#include "../terminalstrip.h"
|
||||
#include "../GraphicsItem/terminalstripitem.h"
|
||||
#include "../../diagram.h"
|
||||
|
||||
void AddTerminalStripItemDialog::openDialog(Diagram *diagram, QWidget *parent)
|
||||
{
|
||||
AddTerminalStripItemDialog d(diagram->project(), parent);
|
||||
if (d.exec())
|
||||
{
|
||||
const auto strip_{d.selectedTerminalStrip()};
|
||||
if (strip_)
|
||||
{
|
||||
auto item_ = new TerminalStripItem(strip_);
|
||||
diagram->addItem(item_);
|
||||
item_->setPos(50, 50);
|
||||
|
||||
diagram->project()->undoStack()->push(new AddGraphicsObjectCommand(item_, diagram, QPointF{50, 50}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AddTerminalStripItemDialog::AddTerminalStripItemDialog(QETProject *project, QWidget *parent) :
|
||||
QDialog{parent},
|
||||
m_project{project},
|
||||
ui{new Ui::AddTerminalStripItemDialog}
|
||||
{
|
||||
ui->setupUi(this);
|
||||
fillComboBox();
|
||||
}
|
||||
|
||||
AddTerminalStripItemDialog::~AddTerminalStripItemDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AddTerminalStripItemDialog::selectedTerminalStrip
|
||||
* @return The selected terminal strip or nullptr if no one is selected
|
||||
* or error encounted.
|
||||
*/
|
||||
TerminalStrip *AddTerminalStripItemDialog::selectedTerminalStrip() const
|
||||
{
|
||||
if (m_project)
|
||||
{
|
||||
const QUuid uuid_{ui->m_terminal_strip_cb->currentData().toUuid()};
|
||||
for (auto &&strip_ : m_project->terminalStrip())
|
||||
{
|
||||
if (strip_->uuid() == uuid_) {
|
||||
return strip_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void AddTerminalStripItemDialog::fillComboBox()
|
||||
{
|
||||
if (m_project)
|
||||
{
|
||||
for (auto &&strip_ : m_project->terminalStrip())
|
||||
{
|
||||
const auto text{strip_->installation() + " " + strip_->location() + " " + strip_->name()};
|
||||
ui->m_terminal_strip_cb->addItem(text, strip_->uuid());
|
||||
}
|
||||
}
|
||||
}
|
||||
51
sources/TerminalStrip/ui/addterminalstripitemdialog.h
Normal file
51
sources/TerminalStrip/ui/addterminalstripitemdialog.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright 2006-2022 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/>.
|
||||
*/
|
||||
#ifndef ADDTERMINALSTRIPITEMDIALOG_H
|
||||
#define ADDTERMINALSTRIPITEMDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPointer>
|
||||
|
||||
class Diagram;
|
||||
class QETDiagramEditor;
|
||||
class QETProject;
|
||||
class TerminalStrip;
|
||||
|
||||
namespace Ui {
|
||||
class AddTerminalStripItemDialog;
|
||||
}
|
||||
|
||||
class AddTerminalStripItemDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static void openDialog(Diagram *diagram, QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
explicit AddTerminalStripItemDialog(QETProject *project, QWidget *parent = nullptr);
|
||||
~AddTerminalStripItemDialog();
|
||||
TerminalStrip *selectedTerminalStrip() const;
|
||||
void fillComboBox();
|
||||
|
||||
private:
|
||||
QPointer<QETProject> m_project;
|
||||
Ui::AddTerminalStripItemDialog *ui;
|
||||
};
|
||||
|
||||
#endif // ADDTERMINALSTRIPITEMDIALOG_H
|
||||
87
sources/TerminalStrip/ui/addterminalstripitemdialog.ui
Normal file
87
sources/TerminalStrip/ui/addterminalstripitemdialog.ui
Normal file
@@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AddTerminalStripItemDialog</class>
|
||||
<widget class="QDialog" name="AddTerminalStripItemDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>326</width>
|
||||
<height>100</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Ajouter le plan de bornes suivant :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="m_terminal_strip_cb"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AddTerminalStripItemDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AddTerminalStripItemDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -333,7 +333,7 @@ QWidget *FreeTerminalModelDelegate::createEditor(QWidget *parent, const QStyleOp
|
||||
{
|
||||
if (index.column() == TYPE_CELL) {
|
||||
auto qcb = new QComboBox(parent);
|
||||
qcb->setObjectName(QLatin1String("terminal_type"));
|
||||
qcb->setObjectName(QStringLiteral("terminal_type"));
|
||||
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTGeneric), ElementData::TTGeneric);
|
||||
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTFuse), ElementData::TTFuse);
|
||||
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTSectional), ElementData::TTSectional);
|
||||
@@ -344,7 +344,7 @@ QWidget *FreeTerminalModelDelegate::createEditor(QWidget *parent, const QStyleOp
|
||||
}
|
||||
if (index.column() == FUNCTION_CELL) {
|
||||
auto qcb = new QComboBox(parent);
|
||||
qcb->setObjectName(QLatin1String("terminal_function"));
|
||||
qcb->setObjectName(QStringLiteral("terminal_function"));
|
||||
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFGeneric), ElementData::TFGeneric);
|
||||
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFPhase), ElementData::TFPhase);
|
||||
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFNeutral), ElementData::TFNeutral);
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "../UndoCommand/addterminalstripcommand.h"
|
||||
#include "freeterminaleditor.h"
|
||||
#include "../../qetapp.h"
|
||||
#include "../../qetdiagrameditor.h"
|
||||
#include "../../qetproject.h"
|
||||
#include "../realterminal.h"
|
||||
#include "../terminalstrip.h"
|
||||
@@ -27,6 +29,8 @@
|
||||
#include "terminalstripeditorwindow.h"
|
||||
#include "terminalstriptreedockwidget.h"
|
||||
|
||||
QPointer<TerminalStripEditorWindow> TerminalStripEditorWindow::window_;
|
||||
|
||||
static const int EMPTY_PAGE = 0;
|
||||
static const int FREE_TERMINAL_PAGE = 1;
|
||||
static const int TERMINAL_STRIP_PAGE = 2;
|
||||
@@ -35,6 +39,16 @@ static const int TERMINAL_STRIP_PAGE = 2;
|
||||
* @param project
|
||||
* @param parent
|
||||
*/
|
||||
void TerminalStripEditorWindow::edit(TerminalStrip *strip)
|
||||
{
|
||||
if (const auto project_ = strip->project())
|
||||
{
|
||||
auto editor_ = TerminalStripEditorWindow::instance(project_, QETApp::diagramEditor(project_));
|
||||
editor_->setCurrentStrip(strip);
|
||||
editor_->show();
|
||||
}
|
||||
}
|
||||
|
||||
TerminalStripEditorWindow::TerminalStripEditorWindow(QETProject *project, QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::TerminalStripEditorWindow),
|
||||
@@ -59,7 +73,11 @@ TerminalStripEditorWindow::TerminalStripEditorWindow(QETProject *project, QWidge
|
||||
*/
|
||||
TerminalStripEditorWindow::~TerminalStripEditorWindow()
|
||||
{
|
||||
delete ui;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void TerminalStripEditorWindow::setCurrentStrip(TerminalStrip *strip) {
|
||||
m_tree_dock->setSelectedStrip(strip);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#define TERMINALSTRIPEDITORWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QMutex>
|
||||
#include <QPointer>
|
||||
|
||||
class QETProject;
|
||||
class TerminalStripTreeDockWidget;
|
||||
@@ -35,16 +37,47 @@ class TerminalStripEditorWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
private:
|
||||
//We need to use a QPointer instead of a raw pointer because when window_
|
||||
//have got a parent widget, the parent widget can delete the window_
|
||||
//instance in her destrucor and then window_ become a dangling pointer.
|
||||
static QPointer<TerminalStripEditorWindow> window_;
|
||||
|
||||
public:
|
||||
static TerminalStripEditorWindow* instance(QETProject *project, QWidget *parent = nullptr) {
|
||||
static QMutex mutex_;
|
||||
if (!window_) {
|
||||
mutex_.lock();
|
||||
if (!window_)
|
||||
window_ = new TerminalStripEditorWindow{project, parent};
|
||||
mutex_.unlock();
|
||||
}
|
||||
return window_;
|
||||
}
|
||||
|
||||
static void dropInstance () {
|
||||
static QMutex mutex;
|
||||
if (window_) {
|
||||
mutex.lock();
|
||||
window_->deleteLater();
|
||||
window_.clear();
|
||||
mutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
static void edit(TerminalStrip *strip);
|
||||
|
||||
public:
|
||||
explicit TerminalStripEditorWindow(QETProject *project, QWidget *parent = nullptr);
|
||||
~TerminalStripEditorWindow();
|
||||
|
||||
void setCurrentStrip(TerminalStrip *strip);
|
||||
|
||||
private slots:
|
||||
void on_m_add_terminal_strip_triggered();
|
||||
void on_m_remove_terminal_triggered();
|
||||
void on_m_reload_triggered();
|
||||
void on_m_button_box_clicked(QAbstractButton *button);
|
||||
|
||||
void on_m_stacked_widget_currentChanged(int arg1);
|
||||
|
||||
private:
|
||||
|
||||
@@ -794,7 +794,7 @@ QWidget *TerminalStripModelDelegate::createEditor(QWidget *parent, const QStyleO
|
||||
{
|
||||
if (index.column() == TYPE_CELL) {
|
||||
auto qcb = new QComboBox(parent);
|
||||
qcb->setObjectName(QLatin1String("terminal_type"));
|
||||
qcb->setObjectName(QStringLiteral("terminal_type"));
|
||||
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTGeneric), ElementData::TTGeneric);
|
||||
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTFuse), ElementData::TTFuse);
|
||||
qcb->addItem(ElementData::translatedTerminalType(ElementData::TTSectional), ElementData::TTSectional);
|
||||
@@ -805,7 +805,7 @@ QWidget *TerminalStripModelDelegate::createEditor(QWidget *parent, const QStyleO
|
||||
}
|
||||
if (index.column() == FUNCTION_CELL) {
|
||||
auto qcb = new QComboBox(parent);
|
||||
qcb->setObjectName(QLatin1String("terminal_function"));
|
||||
qcb->setObjectName(QStringLiteral("terminal_function"));
|
||||
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFGeneric), ElementData::TFGeneric);
|
||||
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFPhase), ElementData::TFPhase);
|
||||
qcb->addItem(ElementData::translatedTerminalFunction(ElementData::TFNeutral), ElementData::TFNeutral);
|
||||
|
||||
Reference in New Issue
Block a user