From 80601a415ab3c30a85cbc2f37461b13b61e9b612 Mon Sep 17 00:00:00 2001 From: joshua Date: Tue, 17 Aug 2021 20:49:48 +0200 Subject: [PATCH] Double click on Xref cell show the terminal in the diagram --- .../TerminalStrip/ui/terminalstripeditor.cpp | 24 +++++++++++++++++ .../TerminalStrip/ui/terminalstripmodel.cpp | 26 +++++++++++++++++++ sources/TerminalStrip/ui/terminalstripmodel.h | 2 ++ 3 files changed, 52 insertions(+) diff --git a/sources/TerminalStrip/ui/terminalstripeditor.cpp b/sources/TerminalStrip/ui/terminalstripeditor.cpp index 909eafc04..a1a67f2ad 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.cpp +++ b/sources/TerminalStrip/ui/terminalstripeditor.cpp @@ -29,6 +29,7 @@ #include "terminalstriptreewidget.h" #include "../../qeticons.h" #include "terminalstripmodel.h" +#include "../diagram.h" #include @@ -48,6 +49,29 @@ TerminalStripEditor::TerminalStripEditor(QETProject *project, QWidget *parent) : buildTree(); ui->m_terminal_strip_tw->expandRecursively(ui->m_terminal_strip_tw->rootIndex()); setUpUndoConnections(); + + //Go the diagram of double clicked terminal + connect(ui->m_table_widget, &QAbstractItemView::doubleClicked, [this](auto index) + { + Element *elmt = nullptr; + if (this->m_model->isXrefCell(index, &elmt)) + { + auto diagram = elmt->diagram(); + if (diagram) + { + diagram->showMe(); + if (diagram->views().size()) + { + auto fit_view = elmt->sceneBoundingRect(); + fit_view.adjust(-200,-200,200,200); + diagram->views().first()->fitInView(fit_view, Qt::KeepAspectRatioByExpanding); + } + } + } + }); + connect(ui->m_table_widget, &QAbstractItemView::entered, [this](auto index) { + qDebug() <<"entered"; + }); } /** diff --git a/sources/TerminalStrip/ui/terminalstripmodel.cpp b/sources/TerminalStrip/ui/terminalstripmodel.cpp index 89f6a3f04..a1a6bea99 100644 --- a/sources/TerminalStrip/ui/terminalstripmodel.cpp +++ b/sources/TerminalStrip/ui/terminalstripmodel.cpp @@ -239,6 +239,32 @@ QHash TerminalStripModel::editedTerminalsData() const return returned_hash; } +/** + * @brief TerminalStripModel::isXrefCell + * @param index + * @param elmt : Pointer of a pointer element + * @return true if the index is the Xref cell, if true the pointer \p element + * will be set to the element associated to the cell. + */ +bool TerminalStripModel::isXrefCell(const QModelIndex &index, Element **element) +{ + if (index.model() == this && index.isValid()) + { + if (index.column() == XREF_CELL) + { + if (index.row() < m_real_terminal_data.size()) + { + auto data = m_real_terminal_data.at(index.row()); + *element = m_terminal_strip->elementForRealTerminal(data.m_real_terminal); + + } + return true; + } + } + + return false; +} + void TerminalStripModel::fillRealTerminalData() { if (m_terminal_strip) { diff --git a/sources/TerminalStrip/ui/terminalstripmodel.h b/sources/TerminalStrip/ui/terminalstripmodel.h index cf96bcb8b..249859246 100644 --- a/sources/TerminalStrip/ui/terminalstripmodel.h +++ b/sources/TerminalStrip/ui/terminalstripmodel.h @@ -42,6 +42,8 @@ class TerminalStripModel : public QAbstractTableModel QHash editedTerminalsData() const; + bool isXrefCell(const QModelIndex &index, Element **element = nullptr); + private: void fillRealTerminalData(); static ElementData modifiedData(const ElementData &original_data, const RealTerminalData &edited_data);