mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
TerminalStripBridge color can be edited.
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2021 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 "changeterminalstripcolor.h"
|
||||||
|
#include "../terminalstripbridge.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ChangeTerminalStripColor::ChangeTerminalStripColor
|
||||||
|
* @param bridge
|
||||||
|
* @param color
|
||||||
|
* @param parent
|
||||||
|
*/
|
||||||
|
ChangeTerminalStripColor::ChangeTerminalStripColor(QSharedPointer<TerminalStripBridge> bridge,
|
||||||
|
const QColor &color,
|
||||||
|
QUndoCommand *parent):
|
||||||
|
QUndoCommand(parent),
|
||||||
|
m_bridge(bridge),
|
||||||
|
m_new_color(color)
|
||||||
|
{
|
||||||
|
if (m_bridge) {
|
||||||
|
m_old_color = m_bridge->color();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangeTerminalStripColor::redo()
|
||||||
|
{
|
||||||
|
if (m_bridge) {
|
||||||
|
m_bridge->setColor(m_new_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangeTerminalStripColor::undo()
|
||||||
|
{
|
||||||
|
if (m_bridge) {
|
||||||
|
m_bridge->setColor(m_old_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
45
sources/TerminalStrip/UndoCommand/changeterminalstripcolor.h
Normal file
45
sources/TerminalStrip/UndoCommand/changeterminalstripcolor.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2021 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 CHANGETERMINALSTRIPCOLOR_H
|
||||||
|
#define CHANGETERMINALSTRIPCOLOR_H
|
||||||
|
|
||||||
|
#include <QUndoCommand>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
|
class TerminalStripBridge;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The ChangeTerminalStripColor class
|
||||||
|
*/
|
||||||
|
class ChangeTerminalStripColor : public QUndoCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ChangeTerminalStripColor(QSharedPointer<TerminalStripBridge> bridge,
|
||||||
|
const QColor &color,
|
||||||
|
QUndoCommand *parent = nullptr);
|
||||||
|
|
||||||
|
void redo() override;
|
||||||
|
void undo() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QSharedPointer<TerminalStripBridge> m_bridge;
|
||||||
|
QColor m_old_color, m_new_color;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CHANGETERMINALSTRIPCOLOR_H
|
||||||
@@ -484,7 +484,8 @@ bool TerminalStrip::setBridge(const QVector<QSharedPointer<RealTerminal>> &real_
|
|||||||
auto bridge = bridgeFor(real_terminals);
|
auto bridge = bridgeFor(real_terminals);
|
||||||
if (bridge.isNull())
|
if (bridge.isNull())
|
||||||
{
|
{
|
||||||
bridge = QSharedPointer<TerminalStripBridge>(new TerminalStripBridge(this));
|
auto br_ = new TerminalStripBridge(this);
|
||||||
|
bridge = br_->sharedRef();
|
||||||
m_bridge.append(bridge);
|
m_bridge.append(bridge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class TerminalStrip : public QObject
|
|||||||
signals:
|
signals:
|
||||||
void orderChanged(); //Emitted when the order of the physical terminal is changed
|
void orderChanged(); //Emitted when the order of the physical terminal is changed
|
||||||
void bridgeChanged();
|
void bridgeChanged();
|
||||||
|
void bridgeColorChanged(QSharedPointer<TerminalStripBridge> bridge);
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TerminalStrip(QETProject *project);
|
TerminalStrip(QETProject *project);
|
||||||
|
|||||||
@@ -23,6 +23,30 @@ TerminalStripBridge::TerminalStripBridge(TerminalStrip *parent_strip) :
|
|||||||
m_strip(parent_strip)
|
m_strip(parent_strip)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripBridge::sharedRef
|
||||||
|
* @return a QSharedPointer of this
|
||||||
|
*/
|
||||||
|
QSharedPointer<TerminalStripBridge> TerminalStripBridge::sharedRef()
|
||||||
|
{
|
||||||
|
QSharedPointer<TerminalStripBridge> this_shared(this->weakRef());
|
||||||
|
if (this_shared.isNull())
|
||||||
|
{
|
||||||
|
this_shared = QSharedPointer<TerminalStripBridge>(this);
|
||||||
|
m_this_weak = this_shared.toWeakRef();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this_shared;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripBridge::weakRef
|
||||||
|
* @return a QWeakPointer of this, weak pointer can be null
|
||||||
|
*/
|
||||||
|
QWeakPointer<TerminalStripBridge> TerminalStripBridge::weakRef() {
|
||||||
|
return m_this_weak;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalStripBridge::color
|
* @brief TerminalStripBridge::color
|
||||||
* @return The color of this bridge
|
* @return The color of this bridge
|
||||||
@@ -31,6 +55,13 @@ QColor TerminalStripBridge::color() const {
|
|||||||
return m_color;
|
return m_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TerminalStripBridge::setColor(const QColor &color) {
|
||||||
|
m_color = color;
|
||||||
|
if (m_strip) {
|
||||||
|
m_strip->bridgeColorChanged(sharedRef());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalStripBridge::realTerminals
|
* @brief TerminalStripBridge::realTerminals
|
||||||
* @return the real terminals who are bridged by this bridge
|
* @return the real terminals who are bridged by this bridge
|
||||||
|
|||||||
@@ -28,13 +28,20 @@ class TerminalStrip;
|
|||||||
|
|
||||||
class TerminalStripBridge
|
class TerminalStripBridge
|
||||||
{
|
{
|
||||||
|
friend class TerminalStrip;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QVector<QColor> bridgeColor() {return QVector<QColor>{Qt::red, Qt::blue, Qt::white, Qt::darkGray, Qt::black};}
|
static QVector<QColor> bridgeColor() {return QVector<QColor>{Qt::red, Qt::blue, Qt::white, Qt::darkGray, Qt::black};}
|
||||||
|
|
||||||
TerminalStripBridge(TerminalStrip *parent_strip = nullptr);
|
TerminalStripBridge(TerminalStrip *parent_strip = nullptr);
|
||||||
|
QSharedPointer<TerminalStripBridge> sharedRef();
|
||||||
|
QWeakPointer<TerminalStripBridge> weakRef();
|
||||||
|
|
||||||
QColor color() const;
|
QColor color() const;
|
||||||
|
void setColor(const QColor &color);
|
||||||
QVector<QSharedPointer<RealTerminal>> realTerminals() const;
|
QVector<QSharedPointer<RealTerminal>> realTerminals() const;
|
||||||
|
|
||||||
|
private:
|
||||||
bool addTerminals(const QVector<QSharedPointer<RealTerminal>> &real_terminals);
|
bool addTerminals(const QVector<QSharedPointer<RealTerminal>> &real_terminals);
|
||||||
void removeTerminals(const QVector<QSharedPointer<RealTerminal>> &real_terminals);
|
void removeTerminals(const QVector<QSharedPointer<RealTerminal>> &real_terminals);
|
||||||
|
|
||||||
@@ -44,6 +51,7 @@ class TerminalStripBridge
|
|||||||
QVector<QSharedPointer<RealTerminal>> m_real_terminals;
|
QVector<QSharedPointer<RealTerminal>> m_real_terminals;
|
||||||
QColor m_color = Qt::darkGray;
|
QColor m_color = Qt::darkGray;
|
||||||
QUuid m_uuid = QUuid::createUuid();
|
QUuid m_uuid = QUuid::createUuid();
|
||||||
|
QWeakPointer<TerminalStripBridge> m_this_weak;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2021 The QElectroTech Team
|
Copyright 2006-2021 The QElectroTech Team
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
@@ -34,6 +34,7 @@
|
|||||||
#include "../UndoCommand/groupterminalscommand.h"
|
#include "../UndoCommand/groupterminalscommand.h"
|
||||||
#include "../UndoCommand/changeterminallevel.h"
|
#include "../UndoCommand/changeterminallevel.h"
|
||||||
#include "../UndoCommand/bridgeterminalscommand.h"
|
#include "../UndoCommand/bridgeterminalscommand.h"
|
||||||
|
#include "../UndoCommand/changeterminalstripcolor.h"
|
||||||
#include "../physicalterminal.h"
|
#include "../physicalterminal.h"
|
||||||
#include "../realterminal.h"
|
#include "../realterminal.h"
|
||||||
#include "../terminalstripbridge.h"
|
#include "../terminalstripbridge.h"
|
||||||
@@ -429,20 +430,21 @@ void TerminalStripEditor::selectionChanged()
|
|||||||
//Enable/disable bridge and unbridge
|
//Enable/disable bridge and unbridge
|
||||||
bool enable_bridge = false;
|
bool enable_bridge = false;
|
||||||
bool enable_unbridge = false;
|
bool enable_unbridge = false;
|
||||||
|
bool enable_bridge_color = false;
|
||||||
|
|
||||||
//One column must be selected and the column must be a level column
|
//One column must be selected and the column must be a level column
|
||||||
int level_ = TerminalStripModel::levelForColumn(isSingleColumnSelected());
|
int level_ = TerminalStripModel::levelForColumn(isSingleColumnSelected());
|
||||||
if (level_ >= 0 && m_current_strip)
|
if (level_ >= 0 && m_current_strip)
|
||||||
{
|
{
|
||||||
//Select only terminals of corresponding level cell selection
|
//Select only terminals of corresponding level cell selection
|
||||||
QVector<modelRealTerminalData> model_real_terminal_level_vector;
|
|
||||||
QVector<QSharedPointer<RealTerminal>> real_terminal_in_level_vector;
|
QVector<QSharedPointer<RealTerminal>> real_terminal_in_level_vector;
|
||||||
for (const auto &mrtd : model_real_terminal_vector)
|
for (const auto &mrtd : model_real_terminal_vector)
|
||||||
{
|
{
|
||||||
if (mrtd.level_ == level_)
|
if (mrtd.level_ == level_) {
|
||||||
{
|
|
||||||
model_real_terminal_level_vector.append(mrtd);
|
|
||||||
real_terminal_in_level_vector.append(mrtd.real_terminal.toStrongRef());
|
real_terminal_in_level_vector.append(mrtd.real_terminal.toStrongRef());
|
||||||
|
if (!enable_bridge_color && mrtd.bridged_) {
|
||||||
|
enable_bridge_color = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enable_bridge = m_current_strip->isBridgeable(real_terminal_in_level_vector);
|
enable_bridge = m_current_strip->isBridgeable(real_terminal_in_level_vector);
|
||||||
@@ -450,6 +452,7 @@ void TerminalStripEditor::selectionChanged()
|
|||||||
}
|
}
|
||||||
ui->m_bridge_terminals_pb->setEnabled(enable_bridge);
|
ui->m_bridge_terminals_pb->setEnabled(enable_bridge);
|
||||||
ui->m_unbridge_terminals_pb->setEnabled(enable_unbridge);
|
ui->m_unbridge_terminals_pb->setEnabled(enable_unbridge);
|
||||||
|
ui->m_bridge_color_cb->setEnabled(enable_bridge_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize TerminalStripEditor::setUpBridgeCellWidth()
|
QSize TerminalStripEditor::setUpBridgeCellWidth()
|
||||||
@@ -476,7 +479,7 @@ QSize TerminalStripEditor::setUpBridgeCellWidth()
|
|||||||
* If all current QModelIndex are in the same column
|
* If all current QModelIndex are in the same column
|
||||||
* return the column type
|
* return the column type
|
||||||
* @sa TerminalStripModel::Column
|
* @sa TerminalStripModel::Column
|
||||||
* @return
|
* @return the column or TerminalStripModel::Invalid if several column are selected
|
||||||
*/
|
*/
|
||||||
TerminalStripModel::Column TerminalStripEditor::isSingleColumnSelected() const
|
TerminalStripModel::Column TerminalStripEditor::isSingleColumnSelected() const
|
||||||
{
|
{
|
||||||
@@ -501,6 +504,29 @@ TerminalStripModel::Column TerminalStripEditor::isSingleColumnSelected() const
|
|||||||
return TerminalStripModel::Invalid;
|
return TerminalStripModel::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripEditor::singleColumnData
|
||||||
|
* @return a QPair with for first value the column and for second value the data
|
||||||
|
* of selected cell of the table widget, only if the selected cells are
|
||||||
|
* in the same column. If selected cells are not in the same column the first value
|
||||||
|
* of the QPair is TerminalStripModel::Invalid.
|
||||||
|
*/
|
||||||
|
QPair<TerminalStripModel::Column, QVector<modelRealTerminalData> > TerminalStripEditor::singleColumnData() const
|
||||||
|
{
|
||||||
|
if (m_current_strip)
|
||||||
|
{
|
||||||
|
auto level_ = isSingleColumnSelected();
|
||||||
|
if (level_ != TerminalStripModel::Invalid)
|
||||||
|
{
|
||||||
|
const auto index_list = ui->m_table_widget->selectionModel()->selectedIndexes();
|
||||||
|
const auto mrtd_vector = m_model->modelRealTerminalDataForIndex(index_list);
|
||||||
|
return qMakePair(level_, mrtd_vector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return qMakePair(TerminalStripModel::Invalid, QVector<modelRealTerminalData>());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalStripEditor::on_m_add_terminal_strip_pb_clicked
|
* @brief TerminalStripEditor::on_m_add_terminal_strip_pb_clicked
|
||||||
* Action when user click on add terminal strip button
|
* Action when user click on add terminal strip button
|
||||||
@@ -829,7 +855,6 @@ void TerminalStripEditor::on_m_bridge_terminals_pb_clicked()
|
|||||||
|
|
||||||
const auto index_list = ui->m_table_widget->selectionModel()->selectedIndexes();
|
const auto index_list = ui->m_table_widget->selectionModel()->selectedIndexes();
|
||||||
const auto mrtd_vector = m_model->modelRealTerminalDataForIndex(index_list);
|
const auto mrtd_vector = m_model->modelRealTerminalDataForIndex(index_list);
|
||||||
|
|
||||||
QVector <QSharedPointer<RealTerminal>> match_vector;
|
QVector <QSharedPointer<RealTerminal>> match_vector;
|
||||||
for (const auto &mrtd : mrtd_vector)
|
for (const auto &mrtd : mrtd_vector)
|
||||||
{
|
{
|
||||||
@@ -879,6 +904,22 @@ void TerminalStripEditor::on_m_unbridge_terminals_pb_clicked()
|
|||||||
|
|
||||||
void TerminalStripEditor::on_m_bridge_color_cb_activated(const QColor &col)
|
void TerminalStripEditor::on_m_bridge_color_cb_activated(const QColor &col)
|
||||||
{
|
{
|
||||||
|
const auto data_vector = singleColumnData();
|
||||||
|
const auto column_ = data_vector.first;
|
||||||
|
if (column_ == TerminalStripModel::Level0 ||
|
||||||
|
column_ == TerminalStripModel::Level1 ||
|
||||||
|
column_ == TerminalStripModel::Level2 ||
|
||||||
|
column_ == TerminalStripModel::Level3)
|
||||||
|
{
|
||||||
|
const auto level_ = TerminalStripModel::levelForColumn(column_);
|
||||||
|
for (const auto &mrtd : data_vector.second)
|
||||||
|
{
|
||||||
|
if (mrtd.level_ == level_ && mrtd.bridged_) {
|
||||||
|
auto bridge_ = mrtd.real_terminal.toStrongRef()->bridge();
|
||||||
|
m_project->undoStack()->push(new ChangeTerminalStripColor(bridge_, col));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class TerminalStripEditor : public QDialog
|
|||||||
void selectionChanged();
|
void selectionChanged();
|
||||||
QSize setUpBridgeCellWidth();
|
QSize setUpBridgeCellWidth();
|
||||||
TerminalStripModel::Column isSingleColumnSelected() const;
|
TerminalStripModel::Column isSingleColumnSelected() const;
|
||||||
|
QPair<TerminalStripModel::Column, QVector<modelRealTerminalData>> singleColumnData() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_m_add_terminal_strip_pb_clicked();
|
void on_m_add_terminal_strip_pb_clicked();
|
||||||
|
|||||||
@@ -109,6 +109,11 @@ TerminalStripModel::TerminalStripModel(TerminalStrip *terminal_strip, QObject *p
|
|||||||
m_terminal_strip(terminal_strip)
|
m_terminal_strip(terminal_strip)
|
||||||
{
|
{
|
||||||
fillPhysicalTerminalData();
|
fillPhysicalTerminalData();
|
||||||
|
|
||||||
|
connect(terminal_strip, &TerminalStrip::bridgeColorChanged, this, [=] {
|
||||||
|
emit dataChanged(index(0, LEVEL_0_CELL),
|
||||||
|
index(rowCount(), LEVEL_3_CELL));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
int TerminalStripModel::rowCount(const QModelIndex &parent) const
|
int TerminalStripModel::rowCount(const QModelIndex &parent) const
|
||||||
|
|||||||
Reference in New Issue
Block a user