Continues migration with DDS, Common

This commit is contained in:
torsten committed 2026-07-17 12:41:42 +02:00
1 parent 9b15cee841
commit fa48db111e
668 files changed
+111841 -2

No files matched your search

@@ -0,0 +1,28 @@
#
# $Id$
# $HeadURL$
# $Author$
# Created by Mike Wille, SLSE, 2016-05-12
#
SET(srcs
connect_dialog.h
connect_dialog.cpp
connect_dialog_nt.h
connect_dialog_nt.cpp
)
NGL_WRAP_UI(srcs
connect_dialog.ui
)
NGL_ADD_LIBRARY2(WS LtsUtilsGuiConnectDialog SHARED ${srcs})
NGL_TARGET_INCLUDE_DIRECTORIES(LtsUtilsGuiConnectDialog
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../
${CMAKE_CURRENT_BINARY_DIR}/../
)
NGL_TARGET_LINK_LIBRARIES(LtsUtilsGuiConnectDialog
Qt5::Widgets
LtsWidgets
)
@@ -0,0 +1,73 @@
#include "connect_dialog.h"
#include "ui_connect_dialog.h"
#include <stdlib.h>
namespace LtsUtils
{
int ConnectingDialog::s_waitForHistoricalDataWaitTime = 10000;
void ConnectingDialog::reset()
{
m_ui->label->setText(QStringLiteral("<font color='orange'>%1</font>").arg(tr("Connecting to %1 on %2 ...").arg(m_serviceName, m_exerciseName)));
}
void ConnectingDialog::setup()
{
m_ui = new Ui::ConnectingDialog;
m_ui->setupUi(this);
reset();
setMinimumSize(sizeHint());
connect(m_ui->pbRetry, &QPushButton::clicked,
this, [this]()
{
m_ui->pbRetry->setEnabled(false);
m_ui->pbIgnore->setEnabled(false);
reset();
emit signalStopLoop();
});
connect(m_ui->pbIgnore, &QPushButton::clicked,
this, [this]()
{
m_ui->pbIgnore->setEnabled(false);
m_ui->pbRetry->setEnabled(false);
m_ui->pbIgnore->setText(tr("continuing.."));
deleteLater();
return;
});
}
ConnectingDialog::~ConnectingDialog()
{
delete m_ui;
}
void ConnectingDialog::failed()
{
m_ui->label->setText(QStringLiteral("<font color='red'>%1</font>").arg(tr("Could not connect to %1 on %2 !").arg(m_serviceName, m_exerciseName)));
m_ui->pbRetry->setEnabled(true);
m_ui->pbIgnore->setEnabled(true);
raise();
}
}
@@ -0,0 +1,82 @@
#pragma once
#include <ConnectDialog/ltsutilsguiconnectdialog_export.h>
#include <LtsWidgets/lts_frameless_dialog.h>
#include <QWidget>
#include <QTimer>
#include <functional>
namespace Ui
{
class ConnectingDialog;
}
namespace LtsUtils
{
class LTSUTILSGUICONNECTDIALOG_EXPORT ConnectingDialog : public LtsWidgets::LtsFramelessDialog
{
Q_OBJECT
public:
static int s_waitForHistoricalDataWaitTime;
template <typename DtcType, typename WaitForHistoricalDataFunction>
explicit ConnectingDialog(DtcType dtc,
WaitForHistoricalDataFunction waitForHistoricalDataFunction,
const QString &serviceName,
const QString &exerciseName,
QWidget *parent = nullptr)
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
, m_serviceName(serviceName)
, m_exerciseName(exerciseName)
, m_ui(nullptr)
{
setWindowTitle(tr("Connecting .."));
setup();
show();
while (true)
{
if ((dtc.get()->*waitForHistoricalDataFunction)(s_waitForHistoricalDataWaitTime))
{
deleteLater();
return;
}
if (s_waitForHistoricalDataWaitTime >= 999999)
{
deleteLater();
return;
}
else
{
failed();
}
}
}
~ConnectingDialog();
void failed();
private:
QString m_serviceName;
QString m_exerciseName;
Ui::ConnectingDialog *m_ui;
void reset();
void setup();
signals:
void signalStopLoop();
};
}
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConnectingDialog</class>
<widget class="QWidget" name="ConnectingDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>260</width>
<height>200</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>260</width>
<height>200</height>
</size>
</property>
<property name="windowTitle">
<string>Login</string>
</property>
<layout class="QVBoxLayout" name="mainLayout" stretch="0,0">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pbRetry">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Retry</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbIgnore">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Ignore</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,157 @@
#include "connect_dialog.h"
#include "connect_dialog_nt.h"
#include "ui_connect_dialog.h"
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
#include <QRandomGenerator>
#endif
namespace LtsUtils
{
ConnectingDialogNT::ConnectingDialogNT(const std::function<bool(int)> &checkFn,
const QString &serviceName,
const QString &exerciseName,
QWidget *parent)
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
, m_serviceName(serviceName)
, m_exerciseName(exerciseName)
, m_checkFn(checkFn)
, m_go(false)
, m_autoRetryTimer(new QTimer(this))
, m_ui(new Ui::ConnectingDialog )
{
m_ui->setupUi(this);
m_autoRetryTimer->setInterval(1000);
connect(m_autoRetryTimer, &QTimer::timeout,
this, [this]()
{
if (m_autoRetryTick < 1)
{
slotRetry();
return;
}
m_ui->pbRetry->setText(QStringLiteral("%1 [%2]").arg(tr("Retry")).arg(m_autoRetryTick));
m_autoRetryTick--;
});
reset();
setMinimumSize(sizeHint());
connect(m_ui->pbRetry, &QPushButton::clicked,
this, &ConnectingDialogNT::slotRetry);
connect(m_ui->pbIgnore, &QPushButton::clicked,
this, [this]()
{
m_ui->pbIgnore->setEnabled(false);
m_ui->pbRetry->setEnabled(false);
m_ui->pbIgnore->setText(tr("continuing.."));
emit signalFailed();
deleteLater();
return;
});
show();
connect(this, &ConnectingDialogNT::signalGo,
this, &ConnectingDialogNT::slotGo, Qt::QueuedConnection);
m_go = true;
m_ui->pbRetry->setEnabled(false);
}
int ConnectingDialogNT::random(int min, int max)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
return QRandomGenerator::global()->bounded(min, max);
#else
return (qrand() % (((max + 1) - min) + min));
#endif
}
bool ConnectingDialogNT::event(QEvent *event)
{
bool result = LtsWidgets::LtsFramelessDialog::event(event);
if (event->type() == QEvent::Paint && m_go)
{
m_go = false;
QTimer::singleShot(0, this, &ConnectingDialogNT::signalGo);
}
return result;
}
void ConnectingDialogNT::slotRetry()
{
m_autoRetryTimer->stop();
m_ui->pbRetry->setText(tr("Retry"));
m_ui->pbRetry->setEnabled(false);
m_ui->pbIgnore->setEnabled(false);
reset();
QTimer::singleShot(1, this, &ConnectingDialogNT::slotGo);
}
void ConnectingDialogNT::slotGo()
{
if (m_checkFn(ConnectingDialog::s_waitForHistoricalDataWaitTime))
{
emit signalSuccess();
deleteLater();
return;
}
failed();
}
void ConnectingDialogNT::reset()
{
m_ui->label->setText(QStringLiteral("<font color='orange'>%1</font>").arg(tr("Connecting to %1 on %2 ...").arg(m_serviceName, m_exerciseName)));
}
ConnectingDialogNT::~ConnectingDialogNT()
{
delete m_ui;
}
void ConnectingDialogNT::failed()
{
m_ui->label->setText(QStringLiteral("<font color='red'>%1</font>").arg(tr("Could not connect to %1 on %2 !").arg(m_serviceName, m_exerciseName)));
m_ui->pbRetry->setEnabled(true);
m_ui->pbIgnore->setEnabled(true);
m_autoRetryTick = random(5, 20);
m_autoRetryTimer->start();
raise();
}
}
@@ -0,0 +1,63 @@
#pragma once
#include <ConnectDialog/ltsutilsguiconnectdialog_export.h>
#include <LtsWidgets/lts_frameless_dialog.h>
#include <functional>
class QTimer;
namespace Ui
{
class ConnectingDialog;
}
namespace LtsUtils
{
class LTSUTILSGUICONNECTDIALOG_EXPORT ConnectingDialogNT : public LtsWidgets::LtsFramelessDialog
{
Q_OBJECT
public:
explicit ConnectingDialogNT(const std::function<bool(int)> &checkFn,
const QString &serviceName,
const QString &exerciseName,
QWidget *parent);
~ConnectingDialogNT();
void failed();
private slots:
void slotGo();
void slotRetry();
signals:
void signalGo();
void signalFailed();
void signalSuccess();
private:
QString m_serviceName;
QString m_exerciseName;
std::function<bool(int)> m_checkFn;
bool m_go;
QTimer *m_autoRetryTimer;
int m_autoRetryTick { 0 };
Ui::ConnectingDialog *m_ui;
int random(int min, int max);
bool event(QEvent *event) override;
void reset();
};
}