mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Revamp PhysicalTerminal class
This commit is contained in:
@@ -17,33 +17,35 @@
|
||||
*/
|
||||
#include "sortterminalstripcommand.h"
|
||||
#include "../terminalstrip.h"
|
||||
#include "../../utils/qetutils.h"
|
||||
|
||||
SortTerminalStripCommand::SortTerminalStripCommand(TerminalStrip *strip, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
m_strip(strip)
|
||||
{
|
||||
setText(QObject::tr("Trier le bornier %1").arg(m_strip->name()));
|
||||
m_old_order = m_new_order = m_strip->physicalTerminalData();
|
||||
m_old_order = QETUtils::weakVectorToShared(m_strip->physicalTerminal());
|
||||
m_new_order = QETUtils::weakVectorToShared(m_strip->physicalTerminal());
|
||||
sort();
|
||||
}
|
||||
|
||||
void SortTerminalStripCommand::undo()
|
||||
{
|
||||
if (m_strip) {
|
||||
m_strip->setOrderTo(m_old_order);
|
||||
m_strip->setOrderTo(QETUtils::sharedVectorToWeak(m_old_order));
|
||||
}
|
||||
}
|
||||
|
||||
void SortTerminalStripCommand::redo()
|
||||
{
|
||||
if (m_strip) {
|
||||
m_strip->setOrderTo(m_new_order);
|
||||
m_strip->setOrderTo(QETUtils::sharedVectorToWeak(m_new_order));
|
||||
}
|
||||
}
|
||||
|
||||
void SortTerminalStripCommand::sort()
|
||||
{
|
||||
std::sort(m_new_order.begin(), m_new_order.end(), [](PhysicalTerminalData arg1, PhysicalTerminalData arg2)
|
||||
std::sort(m_new_order.begin(), m_new_order.end(), [](QSharedPointer<PhysicalTerminal> arg1, QSharedPointer<PhysicalTerminal> arg2)
|
||||
{
|
||||
const QRegularExpression rx(QStringLiteral("^\\d+"));
|
||||
|
||||
@@ -52,9 +54,9 @@ void SortTerminalStripCommand::sort()
|
||||
int int1 =-1;
|
||||
int int2 =-1;
|
||||
|
||||
if (arg1.realTerminalCount())
|
||||
if (arg1->realTerminalCount())
|
||||
{
|
||||
str1 = arg1.realTerminals().constLast().toStrongRef()->label();
|
||||
str1 = arg1->realTerminals().constLast().toStrongRef()->label();
|
||||
|
||||
auto match = rx.match(str1);
|
||||
if (match.hasMatch()) {
|
||||
@@ -62,9 +64,9 @@ void SortTerminalStripCommand::sort()
|
||||
}
|
||||
}
|
||||
|
||||
if (arg2.realTerminalCount())
|
||||
if (arg2->realTerminalCount())
|
||||
{
|
||||
str2 = arg2.realTerminals().constLast().toStrongRef()->label();
|
||||
str2 = arg2->realTerminals().constLast().toStrongRef()->label();
|
||||
|
||||
auto match = rx.match(str2);
|
||||
if (match.hasMatch()) {
|
||||
|
||||
Reference in New Issue
Block a user