Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Common/LtsWidgets/lts_progress_dialog_helper.cpp
T
torstenandCopilot 7a6be7474e Qt6 migration: Fix BUILD_RTI=OFF build errors in TrainingAreaBase
- training_area_telegrams.cpp: Fixed QJsonObject initializer syntax (Qt6 requires {{}} not ({}))
- training_area_telegrams.cpp: Fixed fromJson() methods to access m_* members directly
- training_area_telegrams.cpp: Fixed brace mismatches in multiple toJson() methods
- training_area_telegrams.h: Changed Header struct to public members for consistency
- tx_mixin.cpp: Fixed getEquipmentNumber() template for direct member access
- lts_coordinate.cpp: Added missing #include <iomanip>
- MIGRATION_STATUS.md: Added migration progress tracking document

C++17 constraint enforced due to RTI Connext DDS 7.7.0 incompatibility with C++20+

Build status: BUILD_RTI=OFF successful (0 errors, warnings only)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-23 20:49:23 +02:00

155 lines
3.5 KiB
C++

/**
* @RDE_HEADER@
* Helper Class, which manages a progress Dialog with two states.
* $Id$
* $HeadURL$
* $Author$
*
* Created by Mike Wille, SLSE, 2016-06-20
*/
#include "lts_progress_dialog_helper.h"
#include "lts_frameless_dialog.h"
#include <QtCore/QCoreApplication>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QProgressBar>
#include <QtWidgets/QPushButton>
#include <QtCore/QTimer>
namespace LtsWidgets
{
LtsProgressDialogHelper::LtsProgressDialogHelper(QWidget *parent)
: QObject(parent)
, m_waitDlg(nullptr) // save mem
, m_parentWidget(parent)
, m_textLabel(nullptr)
{}
LtsProgressDialogHelper::~LtsProgressDialogHelper()
{
delete m_waitDlg;
}
void LtsProgressDialogHelper::setCustomText(const QString &customText)
{
if (m_waitDlg == nullptr || m_textLabel == nullptr)
return;
if (customText.isEmpty())
m_textLabel->setText(tr("Waiting for server reply..."));
else
m_textLabel->setText(customText);
}
void LtsProgressDialogHelper::setParentWidget(QWidget *newParent)
{
m_parentWidget = newParent;
if (m_waitDlg)
{
m_waitDlg->setParent(newParent);
QTimer::singleShot(0, m_waitDlg.data(), &LtsFramelessDialog::onUpdateGeometry);
}
}
void LtsProgressDialogHelper::slotShowWaitForReplyWindow()
{
if (m_waitDlg)
m_waitDlg->deleteLater(); //delete m_waitDlg; // when there is already an instance
m_waitDlg = new LtsFramelessDialog(m_parentWidget, Behaviour::Modal);
QHBoxLayout *l = new QHBoxLayout(m_waitDlg);
QProgressBar *pb = new QProgressBar(m_waitDlg);
pb->setMaximum(0);
pb->setValue(-1);
l->addWidget(pb);
m_textLabel = new QLabel(m_waitDlg);
setCustomText();
l->addWidget(m_textLabel);
m_waitDlg->setLayout(l);
m_waitDlg->show();
m_waitDlg->raise(); // TODO: needed when StyOnTop is active ?
//QCoreApplication::processEvents(); // do not look glitched if dds hangs
}
void LtsProgressDialogHelper::slotStopWaitForReplyWindow(const ReplyResult &replyResult, const QString &replyString)
{
if (m_waitDlg == nullptr)
{
// TODO: debug/warning that there is no wait dlg..
return;
}
//qDeleteAll(m_waitDlg->children()); // delete the layout and it's children
m_waitDlg->deleteLater(); // the easiest way
m_waitDlg = nullptr;
// .. a new layout, telling the reply result
QString resultText = tr("Unknown result (%1)!").arg((int)replyResult);
switch (replyResult)
{
case ReplyResult::Close:
{
return; // say nothing, just close
}
case ReplyResult::Success:
{
resultText = tr("Operation was successful");
break;
}
case ReplyResult::Failure:
{
resultText = tr("Operation has failed!\nReason: '%1'").arg(replyString);
break;
}
case ReplyResult::TimeOut:
{
resultText = tr("Operation has timed out and could not be processed! Please try again later");
break;
}
}
m_waitDlg = new LtsFramelessDialog(m_parentWidget, Behaviour::Modal);
QVBoxLayout *newLayout = new QVBoxLayout(m_waitDlg);
newLayout->addWidget(new QLabel(resultText, m_waitDlg));
QPushButton *btn = new QPushButton(tr("OK"),m_waitDlg);
connect(btn, &QPushButton::clicked,
this, &LtsProgressDialogHelper::accept); // TODO: or close?
newLayout->addWidget(btn);
m_waitDlg->setLayout(newLayout);
m_waitDlg->show();
//QCoreApplication::processEvents(); // do not look glitched if dds hangs
}
void LtsProgressDialogHelper::accept()
{
m_waitDlg->accept();
m_waitDlg->deleteLater();
m_waitDlg = nullptr;
emit accepted();
}
} // namespace LtsWidgets