mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 08:10:52 +01:00
Double click a TerminalStripItem open the editor
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
#include "terminalstripitem.h"
|
||||
#include "../../qetgraphicsitem/qgraphicsitemutility.h"
|
||||
#include "../terminalstrip.h"
|
||||
#include "../ui/terminalstripeditorwindow.h"
|
||||
|
||||
TerminalStripItem::TerminalStripItem(QPointer<TerminalStrip> strip, QGraphicsItem *parent) :
|
||||
QetGraphicsItem{parent},
|
||||
@@ -55,3 +57,10 @@ QRectF TerminalStripItem::boundingRect() const
|
||||
QString TerminalStripItem::name() const {
|
||||
return tr("plan de bornes");
|
||||
}
|
||||
|
||||
void TerminalStripItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED (event);
|
||||
|
||||
TerminalStripEditorWindow::edit(m_strip);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ class TerminalStripItem : public QetGraphicsItem
|
||||
QRectF boundingRect() const override;
|
||||
QString name() const override;
|
||||
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
QPointer<TerminalStrip> m_strip;
|
||||
TerminalStripDrawer m_drawer;
|
||||
|
||||
@@ -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),
|
||||
@@ -62,6 +76,10 @@ TerminalStripEditorWindow::~TerminalStripEditorWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void TerminalStripEditorWindow::setCurrentStrip(TerminalStrip *strip) {
|
||||
m_tree_dock->setSelectedStrip(strip);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStripEditorWindow::addTreeDockWidget
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
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:
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "ui/aboutqetdialog.h"
|
||||
#include "ui/configpage/generalconfigurationpage.h"
|
||||
#include "machine_info.h"
|
||||
#include "TerminalStrip/ui/terminalstripeditorwindow.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
@@ -159,6 +160,7 @@ QETApp::~QETApp()
|
||||
ElementFactory::dropInstance();
|
||||
ElementPictureFactory::dropInstance();
|
||||
MachineInfo::dropInstance();
|
||||
TerminalStripEditorWindow::dropInstance();
|
||||
}
|
||||
|
||||
|
||||
@@ -1131,6 +1133,27 @@ QList<QETDiagramEditor *> QETApp::diagramEditors()
|
||||
return(QETApp::instance() -> detectWindows<QETDiagramEditor>());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETApp::diagramEditor
|
||||
* @param project
|
||||
* @return The diagram editor of @a project or nullptr.
|
||||
*/
|
||||
QETDiagramEditor *QETApp::diagramEditor(QETProject *project)
|
||||
{
|
||||
for (const auto &editor : QETApp::instance()->detectWindows<QETDiagramEditor>())
|
||||
{
|
||||
for (const auto &project_view : editor->openedProjects())
|
||||
{
|
||||
if (project_view->project() == project)
|
||||
{
|
||||
return editor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETApp::elementEditors
|
||||
@return element editors
|
||||
|
||||
@@ -149,6 +149,7 @@ class QETApp : public QObject
|
||||
static QETDiagramEditor *diagramEditorForFile(const QString &);
|
||||
static QETDiagramEditor *diagramEditorAncestorOf (const QWidget *child);
|
||||
static QList<QETDiagramEditor *> diagramEditors();
|
||||
static QETDiagramEditor* diagramEditor(QETProject *project);
|
||||
static QList<QETElementEditor *> elementEditors();
|
||||
static QList<QETElementEditor *> elementEditors(QETProject *);
|
||||
static QList<QETTitleBlockTemplateEditor *> titleBlockTemplateEditors();
|
||||
|
||||
@@ -447,8 +447,7 @@ void QETDiagramEditor::setUpActions()
|
||||
{
|
||||
if (auto project = this->currentProject())
|
||||
{
|
||||
auto tsew {new TerminalStripEditorWindow{project, this}};
|
||||
tsew->show();
|
||||
TerminalStripEditorWindow::instance(project, this)->show();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user