mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-12 07:04:12 +02:00
Terminal strip: add a label filter to the free terminals table
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
#include "../terminalstrip.h"
|
||||
#include "../UndoCommand/addterminaltostripcommand.h"
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
/**
|
||||
* @brief FreeTerminalEditor::FreeTerminalEditor
|
||||
* @param project
|
||||
@@ -39,8 +41,23 @@ FreeTerminalEditor::FreeTerminalEditor(QETProject *project, QWidget *parent) :
|
||||
ui->m_table_view->setItemDelegate(new FreeTerminalModelDelegate(ui->m_table_view));
|
||||
|
||||
m_model = new FreeTerminalModel(m_project, this);
|
||||
ui->m_table_view->setModel(m_model);
|
||||
ui->m_table_view->setCurrentIndex(m_model->index(0,0));
|
||||
|
||||
//The view works on a filtered proxy of the model. The filter is a plain,
|
||||
//case insensitive "contains" on the label, so typing Z1 shows Z1:1, Z1:2...
|
||||
//Not dynamic : an edited label must not vanish from the table while it is typed.
|
||||
m_proxy_model = new QSortFilterProxyModel(this);
|
||||
m_proxy_model->setSourceModel(m_model);
|
||||
m_proxy_model->setFilterKeyColumn(FreeTerminalModel::Label);
|
||||
m_proxy_model->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
m_proxy_model->setDynamicSortFilter(false);
|
||||
ui->m_table_view->setModel(m_proxy_model);
|
||||
ui->m_table_view->setCurrentIndex(m_proxy_model->index(0,0));
|
||||
|
||||
connect(ui->m_filter_le, &QLineEdit::textChanged, this, [this](const QString &text)
|
||||
{
|
||||
m_proxy_model->setFilterFixedString(text);
|
||||
selectionChanged();
|
||||
});
|
||||
//Selected rows can be dragged onto a strip of the terminal strip tree
|
||||
ui->m_table_view->setDragEnabled(true);
|
||||
ui->m_table_view->setDragDropMode(QAbstractItemView::DragOnly);
|
||||
@@ -55,8 +72,9 @@ FreeTerminalEditor::FreeTerminalEditor(QETProject *project, QWidget *parent) :
|
||||
connect(ui->m_table_view->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
this, &FreeTerminalEditor::selectionChanged);
|
||||
|
||||
connect(ui->m_table_view, &QAbstractItemView::doubleClicked, this, [this](const QModelIndex &index)
|
||||
connect(ui->m_table_view, &QAbstractItemView::doubleClicked, this, [this](const QModelIndex &proxy_index)
|
||||
{
|
||||
const auto index = m_proxy_model->mapToSource(proxy_index);
|
||||
if (m_model->columnTypeForIndex(index) == FreeTerminalModel::XRef)
|
||||
{
|
||||
auto mrtd = m_model->dataAtRow(index.row());
|
||||
@@ -176,7 +194,7 @@ void FreeTerminalEditor::on_m_type_cb_activated(int index)
|
||||
|
||||
for (auto model_index : index_list)
|
||||
{
|
||||
auto type_index = m_model->index(model_index.row(), FreeTerminalModel::Type, model_index.parent());
|
||||
auto type_index = m_model->index(m_proxy_model->mapToSource(model_index).row(), FreeTerminalModel::Type);
|
||||
if (type_index.isValid())
|
||||
{
|
||||
ElementData::TerminalType override_type;
|
||||
@@ -219,7 +237,7 @@ void FreeTerminalEditor::on_m_function_cb_activated(int index)
|
||||
|
||||
for (auto model_index : index_list)
|
||||
{
|
||||
auto function_index = m_model->index(model_index.row(), FreeTerminalModel::Function, model_index.parent());
|
||||
auto function_index = m_model->index(m_proxy_model->mapToSource(model_index).row(), FreeTerminalModel::Function);
|
||||
if (function_index.isValid())
|
||||
{
|
||||
ElementData::TerminalFunction override_function;
|
||||
@@ -248,7 +266,7 @@ void FreeTerminalEditor::on_m_led_cb_activated(int index)
|
||||
|
||||
for (auto model_index : index_list)
|
||||
{
|
||||
auto led_index = m_model->index(model_index.row(), FreeTerminalModel::Led, model_index.parent());
|
||||
auto led_index = m_model->index(m_proxy_model->mapToSource(model_index).row(), FreeTerminalModel::Led);
|
||||
|
||||
if (led_index.isValid()) {
|
||||
m_model->setData(led_index,
|
||||
@@ -262,7 +280,10 @@ void FreeTerminalEditor::on_m_led_cb_activated(int index)
|
||||
void FreeTerminalEditor::on_m_move_pb_clicked()
|
||||
{
|
||||
//Get the selected real terminal
|
||||
const auto index_list = ui->m_table_view->selectionModel()->selectedIndexes();
|
||||
QModelIndexList index_list;
|
||||
for (const auto &proxy_index : ui->m_table_view->selectionModel()->selectedIndexes()) {
|
||||
index_list.append(m_proxy_model->mapToSource(proxy_index));
|
||||
}
|
||||
const auto real_t_vector = m_model->realTerminalForIndex(index_list);
|
||||
if (real_t_vector.isEmpty()) {
|
||||
return;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
class RealTerminal;
|
||||
class FreeTerminalModel;
|
||||
class QTableView;
|
||||
class QSortFilterProxyModel;
|
||||
|
||||
namespace Ui {
|
||||
class FreeTerminalEditor;
|
||||
@@ -57,5 +58,6 @@ class FreeTerminalEditor : public QWidget
|
||||
Ui::FreeTerminalEditor *ui;
|
||||
QPointer <QETProject> m_project;
|
||||
FreeTerminalModel *m_model {nullptr};
|
||||
QSortFilterProxyModel *m_proxy_model {nullptr};
|
||||
};
|
||||
#endif // FREETERMINALEDITOR_H
|
||||
|
||||
@@ -14,14 +14,24 @@
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="1">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLineEdit" name="m_filter_le">
|
||||
<property name="placeholderText">
|
||||
<string>Filter by label (e.g. Z1)</string>
|
||||
</property>
|
||||
<property name="clearButtonEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="m_move_label">
|
||||
<property name="text">
|
||||
<string>Move to :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<item row="1" column="2">
|
||||
<widget class="QComboBox" name="m_move_in_cb">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
@@ -34,7 +44,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<item row="6" column="2">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@@ -47,35 +57,35 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="6">
|
||||
<item row="1" column="0" rowspan="6">
|
||||
<widget class="QTableView" name="m_table_view">
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Type :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Function :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>LED :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<item row="1" column="3">
|
||||
<widget class="QPushButton" name="m_move_pb">
|
||||
<property name="toolTip">
|
||||
<string>Apply displacement</string>
|
||||
@@ -88,14 +98,14 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="3">
|
||||
<item row="2" column="1" colspan="3">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2" colspan="2">
|
||||
<item row="3" column="2" colspan="2">
|
||||
<widget class="QComboBox" name="m_type_cb">
|
||||
<item>
|
||||
<property name="text">
|
||||
@@ -149,7 +159,7 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2" colspan="2">
|
||||
<item row="4" column="2" colspan="2">
|
||||
<widget class="QComboBox" name="m_function_cb">
|
||||
<item>
|
||||
<property name="text">
|
||||
@@ -168,7 +178,7 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2" colspan="2">
|
||||
<item row="5" column="2" colspan="2">
|
||||
<widget class="QComboBox" name="m_led_cb">
|
||||
<item>
|
||||
<property name="text">
|
||||
|
||||
Reference in New Issue
Block a user