Remove isXrefCell method...

and use instead columnTypeForIndex method
This commit is contained in:
joshua
2021-12-02 18:54:45 +01:00
parent ce8bd7fae3
commit 6e68e6047a
3 changed files with 29 additions and 36 deletions

View File

@@ -71,9 +71,12 @@ TerminalStripEditor::TerminalStripEditor(QETProject *project, QWidget *parent) :
//Go the diagram of double clicked terminal
connect(ui->m_table_widget, &QAbstractItemView::doubleClicked, this, [=](const QModelIndex &index)
{
Element *elmt = nullptr;
if (this->m_model->isXrefCell(index, &elmt))
if (m_model->columnTypeForIndex(index) == TerminalStripModel::XRef)
{
auto rtd = m_model->realTerminalDataForIndex(index);
if (rtd.element_)
{
auto elmt = rtd.element_;
auto diagram = elmt->diagram();
if (diagram)
{
@@ -86,6 +89,7 @@ TerminalStripEditor::TerminalStripEditor(QETProject *project, QWidget *parent) :
}
}
}
}
});
}

View File

@@ -327,31 +327,6 @@ QVector<QPair<RealTerminalData, RealTerminalData>> TerminalStripModel::modifiedR
return returned_vector;
}
/**
* @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()
&& index.column() == XREF_CELL)
{
if (index.row() < rowCount())
{
if (auto data = dataAtRow(index.row()) ; data.element_) {
*element = data.element_.data();
}
}
return true;
}
return false;
}
/**
* @brief TerminalStripModel::levelCellCount
* Check for each index of @a index_list if the cell represented by the index
@@ -448,6 +423,20 @@ QVector<RealTerminalData> TerminalStripModel::realTerminalDataForIndex(QModelInd
return vector_;
}
/**
* @brief TerminalStripModel::realTerminalDataForIndex
* @param index
* @return RealTerminalData at index @a index or null RealTerminalData if invalid
*/
RealTerminalData TerminalStripModel::realTerminalDataForIndex(const QModelIndex &index) const
{
if (index.isValid()) {
return realDataAtIndex(index.row());
} else {
return RealTerminalData();
}
}
void TerminalStripModel::fillPhysicalTerminalData()
{
//Get all physical terminal

View File

@@ -1,4 +1,4 @@
/*
/*
Copyright 2006-2021 The QElectroTech Team
This file is part of QElectroTech.
@@ -64,10 +64,10 @@ class TerminalStripModel : public QAbstractTableModel
virtual Qt::ItemFlags flags (const QModelIndex &index) const override;
QVector<QPair<RealTerminalData, RealTerminalData>> modifiedRealTerminalData() const;
bool isXrefCell(const QModelIndex &index, Element **element = nullptr);
QVector<int> levelCellCount(const QModelIndexList &index_list) const;
QVector<PhysicalTerminalData> physicalTerminalDataForIndex(QModelIndexList index_list) const;
QVector<RealTerminalData> realTerminalDataForIndex(QModelIndexList index_list) const;
RealTerminalData realTerminalDataForIndex(const QModelIndex &index) const;
private:
void fillPhysicalTerminalData();