Revamp PhysicalTerminal class

This commit is contained in:
joshua
2021-12-23 22:17:37 +01:00
parent a2e5989f3b
commit 2ea9f8a2c6
9 changed files with 303 additions and 315 deletions

View File

@@ -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()) {