Apply clang-format to Lts/Common and DTC/enum headers
- Formatted all CodeGen module files (9 files) - Formatted LtsAppDescriptor module files - Formatted LtsAppManager/AppChooser files - Applied clang-format to all DTC and enum headers across modules - Removed coordTransTests from CommonUnitTestsPlaceholder (moved to tests/) Cosmetic changes only, no functional modifications. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
848 files changed
+89305
-100020
No files matched your search
Executable → Regular
+26
-40
@@ -1,73 +1,59 @@
|
||||
|
||||
|
||||
|
||||
#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)));
|
||||
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);
|
||||
|
||||
m_ui = new Ui::ConnectingDialog;
|
||||
m_ui->setupUi(this);
|
||||
reset();
|
||||
emit signalStopLoop();
|
||||
});
|
||||
setMinimumSize(sizeHint());
|
||||
connect(m_ui->pbRetry, &QPushButton::clicked, this, [this]() {
|
||||
m_ui->pbRetry->setEnabled(false);
|
||||
m_ui->pbIgnore->setEnabled(false);
|
||||
|
||||
connect(m_ui->pbIgnore, &QPushButton::clicked,
|
||||
this, [this]()
|
||||
{
|
||||
m_ui->pbIgnore->setEnabled(false);
|
||||
m_ui->pbRetry->setEnabled(false);
|
||||
m_ui->pbIgnore->setText(tr("continuing.."));
|
||||
reset();
|
||||
emit signalStopLoop();
|
||||
});
|
||||
|
||||
deleteLater();
|
||||
return;
|
||||
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;
|
||||
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->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_ui->pbRetry->setEnabled(true);
|
||||
m_ui->pbIgnore->setEnabled(true);
|
||||
|
||||
raise();
|
||||
raise();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsUtils
|
||||
Executable → Regular
+43
-53
@@ -1,18 +1,14 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltsutilsguiconnectdialog_export.h"
|
||||
|
||||
#include <LtsWidgets/lts_frameless_dialog.h>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
|
||||
#include <QWidget>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class ConnectingDialog;
|
||||
@@ -23,61 +19,55 @@ namespace LtsUtils
|
||||
|
||||
class LTSUTILSGUICONNECTDIALOG_EXPORT ConnectingDialog : public LtsWidgets::LtsFramelessDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static int s_waitForHistoricalDataWaitTime;
|
||||
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)
|
||||
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)
|
||||
{
|
||||
if ((dtc.get()->*waitForHistoricalDataFunction)(s_waitForHistoricalDataWaitTime))
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
setWindowTitle(tr("Connecting .."));
|
||||
setup();
|
||||
show();
|
||||
|
||||
if (s_waitForHistoricalDataWaitTime >= 999999)
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
failed();
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
if ((dtc.get()->*waitForHistoricalDataFunction)(s_waitForHistoricalDataWaitTime))
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
if (s_waitForHistoricalDataWaitTime >= 999999)
|
||||
{
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
failed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~ConnectingDialog();
|
||||
~ConnectingDialog();
|
||||
|
||||
void failed();
|
||||
void failed();
|
||||
|
||||
private:
|
||||
QString m_serviceName;
|
||||
QString m_exerciseName;
|
||||
Ui::ConnectingDialog *m_ui;
|
||||
private:
|
||||
QString m_serviceName;
|
||||
QString m_exerciseName;
|
||||
Ui::ConnectingDialog* m_ui;
|
||||
|
||||
void reset();
|
||||
void setup();
|
||||
|
||||
signals:
|
||||
void signalStopLoop();
|
||||
void reset();
|
||||
void setup();
|
||||
|
||||
signals:
|
||||
void signalStopLoop();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsUtils
|
||||
Executable → Regular
+70
-98
@@ -1,157 +1,129 @@
|
||||
|
||||
|
||||
#include "connect_dialog_nt.h"
|
||||
|
||||
#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 )
|
||||
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_ui->setupUi(this);
|
||||
|
||||
m_autoRetryTimer->setInterval(1000);
|
||||
connect(m_autoRetryTimer, &QTimer::timeout,
|
||||
this, [this]()
|
||||
{
|
||||
if (m_autoRetryTick < 1)
|
||||
{
|
||||
slotRetry();
|
||||
return;
|
||||
}
|
||||
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--;
|
||||
});
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
return QRandomGenerator::global()->bounded(min, max);
|
||||
#else
|
||||
return (qrand() % (((max + 1) - min) + min));
|
||||
return (qrand() % (((max + 1) - min) + min));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ConnectingDialogNT::event(QEvent *event)
|
||||
bool ConnectingDialogNT::event(QEvent* event)
|
||||
{
|
||||
bool result = LtsWidgets::LtsFramelessDialog::event(event);
|
||||
bool result = LtsWidgets::LtsFramelessDialog::event(event);
|
||||
|
||||
if (event->type() == QEvent::Paint && m_go)
|
||||
{
|
||||
m_go = false;
|
||||
QTimer::singleShot(0, this, &ConnectingDialogNT::signalGo);
|
||||
}
|
||||
if (event->type() == QEvent::Paint && m_go)
|
||||
{
|
||||
m_go = false;
|
||||
QTimer::singleShot(0, this, &ConnectingDialogNT::signalGo);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void ConnectingDialogNT::slotRetry()
|
||||
{
|
||||
m_autoRetryTimer->stop();
|
||||
m_autoRetryTimer->stop();
|
||||
|
||||
m_ui->pbRetry->setText(tr("Retry"));
|
||||
m_ui->pbRetry->setEnabled(false);
|
||||
m_ui->pbIgnore->setEnabled(false);
|
||||
m_ui->pbRetry->setText(tr("Retry"));
|
||||
m_ui->pbRetry->setEnabled(false);
|
||||
m_ui->pbIgnore->setEnabled(false);
|
||||
|
||||
reset();
|
||||
QTimer::singleShot(1, this, &ConnectingDialogNT::slotGo);
|
||||
reset();
|
||||
QTimer::singleShot(1, this, &ConnectingDialogNT::slotGo);
|
||||
}
|
||||
|
||||
|
||||
void ConnectingDialogNT::slotGo()
|
||||
{
|
||||
|
||||
if (m_checkFn(ConnectingDialog::s_waitForHistoricalDataWaitTime))
|
||||
{
|
||||
emit signalSuccess();
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
failed();
|
||||
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)));
|
||||
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;
|
||||
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->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_ui->pbRetry->setEnabled(true);
|
||||
m_ui->pbIgnore->setEnabled(true);
|
||||
|
||||
m_autoRetryTick = random(5, 20);
|
||||
m_autoRetryTimer->start();
|
||||
m_autoRetryTick = random(5, 20);
|
||||
m_autoRetryTimer->start();
|
||||
|
||||
raise();
|
||||
raise();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsUtils
|
||||
Executable → Regular
+27
-35
@@ -1,15 +1,12 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "ltsutilsguiconnectdialog_export.h"
|
||||
|
||||
#include <LtsWidgets/lts_frameless_dialog.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <functional>
|
||||
|
||||
|
||||
class QTimer;
|
||||
|
||||
namespace Ui
|
||||
@@ -22,43 +19,38 @@ namespace LtsUtils
|
||||
|
||||
class LTSUTILSGUICONNECTDIALOG_EXPORT ConnectingDialogNT : public LtsWidgets::LtsFramelessDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
explicit ConnectingDialogNT(const std::function<bool(int)>& checkFn, const QString& serviceName,
|
||||
const QString& exerciseName, QWidget* parent);
|
||||
~ConnectingDialogNT();
|
||||
|
||||
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();
|
||||
|
||||
void failed();
|
||||
signals:
|
||||
void signalGo();
|
||||
void signalFailed();
|
||||
void signalSuccess();
|
||||
|
||||
private slots:
|
||||
void slotGo();
|
||||
void slotRetry();
|
||||
private:
|
||||
QString m_serviceName;
|
||||
QString m_exerciseName;
|
||||
std::function<bool(int)> m_checkFn;
|
||||
bool m_go;
|
||||
|
||||
signals:
|
||||
void signalGo();
|
||||
void signalFailed();
|
||||
void signalSuccess();
|
||||
QTimer* m_autoRetryTimer;
|
||||
int m_autoRetryTick{0};
|
||||
|
||||
private:
|
||||
QString m_serviceName;
|
||||
QString m_exerciseName;
|
||||
std::function<bool(int)> m_checkFn;
|
||||
bool m_go;
|
||||
Ui::ConnectingDialog* m_ui;
|
||||
|
||||
QTimer *m_autoRetryTimer;
|
||||
int m_autoRetryTick { 0 };
|
||||
|
||||
Ui::ConnectingDialog *m_ui;
|
||||
|
||||
int random(int min, int max);
|
||||
bool event(QEvent *event) override;
|
||||
void reset();
|
||||
int random(int min, int max);
|
||||
bool event(QEvent* event) override;
|
||||
void reset();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsUtils
|
||||
Executable → Regular
+73
-78
@@ -1,9 +1,7 @@
|
||||
|
||||
|
||||
|
||||
#include <LtsUtilsCore/dds_vector.h>
|
||||
#include <LtsUtils/LtsUtilsGui/LtsUtilsGuiDds/dds_vector_to_pixmap.h>
|
||||
|
||||
#include <LtsUtilsCore/dds_vector.h>
|
||||
#include <QBuffer>
|
||||
#include <QFile>
|
||||
#include <QIcon>
|
||||
@@ -12,123 +10,120 @@
|
||||
#include <QPixmap>
|
||||
#include <QSvgRenderer>
|
||||
|
||||
|
||||
namespace LtsUtils
|
||||
{
|
||||
|
||||
QIcon iconFromSvg(const QByteArray &svgData, QSize iconSize)
|
||||
QIcon iconFromSvg(const QByteArray& svgData, QSize iconSize)
|
||||
{
|
||||
QSvgRenderer renderer(svgData);
|
||||
QPixmap p(iconSize);
|
||||
p.fill(Qt::transparent);
|
||||
QPainter painter(&p);
|
||||
renderer.render(&painter);
|
||||
painter.end();
|
||||
QSvgRenderer renderer(svgData);
|
||||
QPixmap p(iconSize);
|
||||
p.fill(Qt::transparent);
|
||||
QPainter painter(&p);
|
||||
renderer.render(&painter);
|
||||
painter.end();
|
||||
|
||||
return {p};
|
||||
return {p};
|
||||
}
|
||||
|
||||
QIcon iconFromSvg(const QString &svgFilename, QSize iconSize)
|
||||
QIcon iconFromSvg(const QString& svgFilename, QSize iconSize)
|
||||
{
|
||||
QFile f(svgFilename);
|
||||
if (!f.open(QIODevice::ReadOnly))
|
||||
return {};
|
||||
return iconFromSvg(f.readAll(), iconSize);
|
||||
QFile f(svgFilename);
|
||||
if (!f.open(QIODevice::ReadOnly))
|
||||
return {};
|
||||
return iconFromSvg(f.readAll(), iconSize);
|
||||
}
|
||||
|
||||
QPixmap pixmapFromIcon(const QIcon &icon, QSize iconSize)
|
||||
QPixmap pixmapFromIcon(const QIcon& icon, QSize iconSize)
|
||||
{
|
||||
return icon.pixmap(iconSize).scaled(100, 100, Qt::AspectRatioMode::IgnoreAspectRatio);
|
||||
return icon.pixmap(iconSize).scaled(100, 100, Qt::AspectRatioMode::IgnoreAspectRatio);
|
||||
}
|
||||
|
||||
QPixmap pixmapFromSvg(const QString &svgFilename, QSize iconSize)
|
||||
QPixmap pixmapFromSvg(const QString& svgFilename, QSize iconSize)
|
||||
{
|
||||
return pixmapFromIcon(iconFromSvg(svgFilename, iconSize), iconSize);
|
||||
return pixmapFromIcon(iconFromSvg(svgFilename, iconSize), iconSize);
|
||||
}
|
||||
|
||||
QPixmap getPixmap(const std::vector<uint8_t> &data)
|
||||
QPixmap getPixmap(const std::vector<uint8_t>& data)
|
||||
{
|
||||
if (data.size() == 0)
|
||||
return QPixmap();
|
||||
|
||||
return getPixmap(QByteArray(reinterpret_cast<const char*>(&data.at(0)), data.size()));
|
||||
if (data.size() == 0)
|
||||
return QPixmap();
|
||||
|
||||
return getPixmap(QByteArray(reinterpret_cast<const char*>(&data.at(0)), data.size()));
|
||||
}
|
||||
|
||||
QPixmap getPixmap(const QByteArray &data)
|
||||
QPixmap getPixmap(const QByteArray& data)
|
||||
{
|
||||
return QPixmap::fromImage(QImage::fromData(data));
|
||||
return QPixmap::fromImage(QImage::fromData(data));
|
||||
}
|
||||
|
||||
QImage getImage(const std::vector<uint8_t> &data)
|
||||
QImage getImage(const std::vector<uint8_t>& data)
|
||||
{
|
||||
if (data.size() == 0)
|
||||
return QImage();
|
||||
|
||||
return getImage(QByteArray(reinterpret_cast<const char*>(&data.at(0)), data.size()));
|
||||
if (data.size() == 0)
|
||||
return QImage();
|
||||
|
||||
return getImage(QByteArray(reinterpret_cast<const char*>(&data.at(0)), data.size()));
|
||||
}
|
||||
|
||||
QImage getImage(const QByteArray &data)
|
||||
QImage getImage(const QByteArray& data)
|
||||
{
|
||||
return QImage::fromData(data);
|
||||
return QImage::fromData(data);
|
||||
}
|
||||
|
||||
static inline void setIf(bool *boolPtr, bool val)
|
||||
static inline void setIf(bool* boolPtr, bool val)
|
||||
{
|
||||
if (boolPtr)
|
||||
*boolPtr = val;
|
||||
if (boolPtr)
|
||||
*boolPtr = val;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> fromPixmap(const QPixmap &pixmap, bool *bIsPng)
|
||||
std::vector<uint8_t> fromPixmap(const QPixmap& pixmap, bool* bIsPng)
|
||||
{
|
||||
QBuffer buf;
|
||||
buf.open(QIODevice::WriteOnly);
|
||||
pixmap.save(&buf, "PNG");
|
||||
buf.close();
|
||||
QByteArray ba = buf.buffer();
|
||||
QBuffer buf;
|
||||
buf.open(QIODevice::WriteOnly);
|
||||
pixmap.save(&buf, "PNG");
|
||||
buf.close();
|
||||
QByteArray ba = buf.buffer();
|
||||
|
||||
setIf(bIsPng, true);
|
||||
|
||||
if (ba.size() > 10240 && !pixmap.hasAlpha() && !pixmap.hasAlphaChannel())
|
||||
{
|
||||
QBuffer buf2;
|
||||
buf2.open(QIODevice::WriteOnly);
|
||||
pixmap.save(&buf2, "JPG");
|
||||
buf2.close();
|
||||
if (buf2.buffer().size() < buf.buffer().size())
|
||||
setIf(bIsPng, true);
|
||||
|
||||
if (ba.size() > 10240 && !pixmap.hasAlpha() && !pixmap.hasAlphaChannel())
|
||||
{
|
||||
setIf(bIsPng, false);
|
||||
ba = buf2.buffer();
|
||||
QBuffer buf2;
|
||||
buf2.open(QIODevice::WriteOnly);
|
||||
pixmap.save(&buf2, "JPG");
|
||||
buf2.close();
|
||||
if (buf2.buffer().size() < buf.buffer().size())
|
||||
{
|
||||
setIf(bIsPng, false);
|
||||
ba = buf2.buffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return convert<std::vector<uint8_t>>(ba);
|
||||
return convert<std::vector<uint8_t>>(ba);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> fromImage(const QImage &image, bool *bIsPng)
|
||||
std::vector<uint8_t> fromImage(const QImage& image, bool* bIsPng)
|
||||
{
|
||||
QBuffer buf;
|
||||
buf.open(QIODevice::WriteOnly);
|
||||
image.save(&buf, "PNG");
|
||||
buf.close();
|
||||
QByteArray ba = buf.buffer();
|
||||
QBuffer buf;
|
||||
buf.open(QIODevice::WriteOnly);
|
||||
image.save(&buf, "PNG");
|
||||
buf.close();
|
||||
QByteArray ba = buf.buffer();
|
||||
|
||||
|
||||
setIf(bIsPng, true);
|
||||
if ((ba.size() > 10240 && !image.hasAlphaChannel()) ||
|
||||
ba.size() > 1024 * 1024)
|
||||
{
|
||||
QBuffer buf2;
|
||||
buf2.open(QIODevice::WriteOnly);
|
||||
image.save(&buf2, "JPG");
|
||||
buf2.close();
|
||||
if (buf2.buffer().size() < buf.buffer().size())
|
||||
setIf(bIsPng, true);
|
||||
if ((ba.size() > 10240 && !image.hasAlphaChannel()) || ba.size() > 1024 * 1024)
|
||||
{
|
||||
setIf(bIsPng, false);
|
||||
ba = buf2.buffer();
|
||||
QBuffer buf2;
|
||||
buf2.open(QIODevice::WriteOnly);
|
||||
image.save(&buf2, "JPG");
|
||||
buf2.close();
|
||||
if (buf2.buffer().size() < buf.buffer().size())
|
||||
{
|
||||
setIf(bIsPng, false);
|
||||
ba = buf2.buffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return convert<std::vector<uint8_t>>(ba);
|
||||
return convert<std::vector<uint8_t>>(ba);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsUtils
|
||||
qt6-after/qt6-migrated-legatus/Lts/Common/LtsUtils/LtsUtilsGui/LtsUtilsGuiDds/dds_vector_to_pixmap.h
Executable → Regular
+11
-13
@@ -1,13 +1,11 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ltsutilsguidds_export.h"
|
||||
|
||||
#include <QSize>
|
||||
#include <QString>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
@@ -19,15 +17,15 @@ class QIcon;
|
||||
namespace LtsUtils
|
||||
{
|
||||
|
||||
LTSUTILSCORE_EXPORT QPixmap getPixmap(const std::vector<uint8_t> &data);
|
||||
LTSUTILSCORE_EXPORT QPixmap getPixmap(const QByteArray &data);
|
||||
LTSUTILSCORE_EXPORT QImage getImage(const std::vector<uint8_t> &data);
|
||||
LTSUTILSCORE_EXPORT QImage getImage(const QByteArray &data);
|
||||
LTSUTILSCORE_EXPORT QIcon iconFromSvg(const QByteArray &svgData, QSize iconSize = QSize(100, 100));
|
||||
LTSUTILSCORE_EXPORT QIcon iconFromSvg(const QString &svgFilename, QSize iconSize = QSize(100, 100));
|
||||
LTSUTILSCORE_EXPORT QPixmap pixmapFromIcon(const QIcon &icon, QSize iconSize = QSize(100, 100));
|
||||
LTSUTILSCORE_EXPORT QPixmap pixmapFromSvg(const QString &svgFilename, QSize iconSize = QSize(100, 100));
|
||||
LTSUTILSCORE_EXPORT std::vector<uint8_t> fromPixmap(const QPixmap &pixmap, bool *bIsPng = nullptr);
|
||||
LTSUTILSCORE_EXPORT std::vector<uint8_t> fromImage(const QImage &image, bool *bIsPng = nullptr);
|
||||
LTSUTILSCORE_EXPORT QPixmap getPixmap(const std::vector<uint8_t>& data);
|
||||
LTSUTILSCORE_EXPORT QPixmap getPixmap(const QByteArray& data);
|
||||
LTSUTILSCORE_EXPORT QImage getImage(const std::vector<uint8_t>& data);
|
||||
LTSUTILSCORE_EXPORT QImage getImage(const QByteArray& data);
|
||||
LTSUTILSCORE_EXPORT QIcon iconFromSvg(const QByteArray& svgData, QSize iconSize = QSize(100, 100));
|
||||
LTSUTILSCORE_EXPORT QIcon iconFromSvg(const QString& svgFilename, QSize iconSize = QSize(100, 100));
|
||||
LTSUTILSCORE_EXPORT QPixmap pixmapFromIcon(const QIcon& icon, QSize iconSize = QSize(100, 100));
|
||||
LTSUTILSCORE_EXPORT QPixmap pixmapFromSvg(const QString& svgFilename, QSize iconSize = QSize(100, 100));
|
||||
LTSUTILSCORE_EXPORT std::vector<uint8_t> fromPixmap(const QPixmap& pixmap, bool* bIsPng = nullptr);
|
||||
LTSUTILSCORE_EXPORT std::vector<uint8_t> fromImage(const QImage& image, bool* bIsPng = nullptr);
|
||||
|
||||
}
|
||||
} // namespace LtsUtils
|
||||
Executable → Regular
+150
-180
@@ -1,6 +1,5 @@
|
||||
|
||||
|
||||
|
||||
#include "request_helper.h"
|
||||
|
||||
#ifdef REQUEST_HELPER_WITH_GUI
|
||||
@@ -9,268 +8,239 @@
|
||||
#include <QWidget>
|
||||
#endif
|
||||
|
||||
|
||||
#include <QEventLoop>
|
||||
#include <QTimer>
|
||||
#include <memory>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QTimer>
|
||||
#include <memory>
|
||||
|
||||
#define DEBUG
|
||||
|
||||
|
||||
namespace LtsUtils
|
||||
{
|
||||
bool RequestHelper::s_debug = false;
|
||||
|
||||
RequestHelper::RequestHelper(QObject *parent, bool quiet,
|
||||
|
||||
const std::function<void (void)> &success,
|
||||
const std::function<void (void)> &failure)
|
||||
: QObject(parent)
|
||||
, m_failed(false)
|
||||
, m_repliedId(-1)
|
||||
, m_quiet(quiet)
|
||||
, m_blockingCall(true)
|
||||
, m_successFn(success)
|
||||
, m_failureFn(failure)
|
||||
{
|
||||
connect(this, &RequestHelper::signalSuccess, this, m_successFn, Qt::QueuedConnection);
|
||||
connect(this, &RequestHelper::signalFailed, this, m_failureFn, Qt::QueuedConnection);
|
||||
RequestHelper::RequestHelper(QObject* parent, bool quiet,
|
||||
|
||||
if (s_debug)
|
||||
{
|
||||
QTimer *t = new QTimer(this);
|
||||
t->setInterval(2000);
|
||||
t->setSingleShot(true);
|
||||
connect(this, &RequestHelper::signalNextRequest, t, static_cast<void (QTimer::*)(void)>(&QTimer::start));
|
||||
connect(t, &QTimer::timeout, this, &RequestHelper::slotNextRequest, Qt::QueuedConnection);
|
||||
}
|
||||
else
|
||||
{
|
||||
connect(this, &RequestHelper::signalNextRequest,
|
||||
this, &RequestHelper::slotNextRequest,
|
||||
Qt::QueuedConnection
|
||||
|
||||
);
|
||||
}
|
||||
const std::function<void(void)>& success, const std::function<void(void)>& failure)
|
||||
: QObject(parent), m_failed(false), m_repliedId(-1), m_quiet(quiet), m_blockingCall(true), m_successFn(success),
|
||||
m_failureFn(failure)
|
||||
{
|
||||
connect(this, &RequestHelper::signalSuccess, this, m_successFn, Qt::QueuedConnection);
|
||||
connect(this, &RequestHelper::signalFailed, this, m_failureFn, Qt::QueuedConnection);
|
||||
|
||||
if (s_debug)
|
||||
{
|
||||
QTimer* t = new QTimer(this);
|
||||
t->setInterval(2000);
|
||||
t->setSingleShot(true);
|
||||
connect(this, &RequestHelper::signalNextRequest, t, static_cast<void (QTimer::*)(void)>(&QTimer::start));
|
||||
connect(t, &QTimer::timeout, this, &RequestHelper::slotNextRequest, Qt::QueuedConnection);
|
||||
}
|
||||
else
|
||||
{
|
||||
connect(this, &RequestHelper::signalNextRequest, this, &RequestHelper::slotNextRequest, Qt::QueuedConnection
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RequestHelper::addRequest(const std::function<int64_t()> &requestFunction,
|
||||
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler)
|
||||
void RequestHelper::addRequest(const std::function<int64_t()>& requestFunction,
|
||||
const std::function<void(const Core::FunctionReply& baseReply)>& baseReplyHandler)
|
||||
{
|
||||
m_requestFunctions.append(RequestFunctionContainer(requestFunction, baseReplyHandler));
|
||||
m_requestFunctions.append(RequestFunctionContainer(requestFunction, baseReplyHandler));
|
||||
}
|
||||
|
||||
bool RequestHelper::requestReply(const Core::FunctionReply &baseReply)
|
||||
bool RequestHelper::requestReply(const Core::FunctionReply& baseReply)
|
||||
{
|
||||
const Core::FunctionReplyObject fro(baseReply.id(),
|
||||
baseReply.errorString(),
|
||||
baseReply.errorParams());
|
||||
return _requestReply(fro, &baseReply);
|
||||
const Core::FunctionReplyObject fro(baseReply.id(), baseReply.errorString(), baseReply.errorParams());
|
||||
return _requestReply(fro, &baseReply);
|
||||
}
|
||||
|
||||
bool RequestHelper::requestReply(const Core::FunctionReplyObject &replyObject)
|
||||
bool RequestHelper::requestReply(const Core::FunctionReplyObject& replyObject)
|
||||
{
|
||||
return _requestReply(replyObject, nullptr);
|
||||
return _requestReply(replyObject, nullptr);
|
||||
}
|
||||
|
||||
|
||||
bool RequestHelper::_requestReply(const Core::FunctionReplyObject &fro, const Core::FunctionReply *baseReply)
|
||||
bool RequestHelper::_requestReply(const Core::FunctionReplyObject& fro, const Core::FunctionReply* baseReply)
|
||||
{
|
||||
m_errorString = fro.translated();
|
||||
m_errorString = fro.translated();
|
||||
|
||||
#ifdef REQUEST_HELPER_WITH_GUI
|
||||
if (fro.error())
|
||||
{
|
||||
|
||||
if (!m_quiet)
|
||||
if (fro.error())
|
||||
{
|
||||
if (m_blockingCall)
|
||||
{
|
||||
LtsWidgets::LtsMessageDialog::showMessage(qobject_cast<QWidget *>(parent()),
|
||||
m_errorString,
|
||||
tr("Request failed"));
|
||||
}
|
||||
else
|
||||
{
|
||||
new LtsWidgets::LtsMessageDialogNew(qobject_cast<QWidget *>(parent()),
|
||||
m_errorString,
|
||||
tr("Request failed"));
|
||||
}
|
||||
|
||||
if (!m_quiet)
|
||||
{
|
||||
if (m_blockingCall)
|
||||
{
|
||||
LtsWidgets::LtsMessageDialog::showMessage(qobject_cast<QWidget*>(parent()), m_errorString,
|
||||
tr("Request failed"));
|
||||
}
|
||||
else
|
||||
{
|
||||
new LtsWidgets::LtsMessageDialogNew(qobject_cast<QWidget*>(parent()), m_errorString,
|
||||
tr("Request failed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
m_repliedId = fro.id();
|
||||
m_repliedId = fro.id();
|
||||
|
||||
if (m_singleRequestCustomFunctionReply != nullptr)
|
||||
{
|
||||
if (baseReply)
|
||||
m_singleRequestCustomFunctionReply(*baseReply);
|
||||
else
|
||||
m_singleRequestCustomFunctionReply(Core::FunctionReply(fro.id(), fro.str(), fro.args(), fro.additionalInfo()));
|
||||
}
|
||||
if (m_singleRequestCustomFunctionReply != nullptr)
|
||||
{
|
||||
if (baseReply)
|
||||
m_singleRequestCustomFunctionReply(*baseReply);
|
||||
else
|
||||
m_singleRequestCustomFunctionReply(
|
||||
Core::FunctionReply(fro.id(), fro.str(), fro.args(), fro.additionalInfo()));
|
||||
}
|
||||
|
||||
if (fro.error())
|
||||
{
|
||||
failure();
|
||||
return false;
|
||||
}
|
||||
if (fro.error())
|
||||
{
|
||||
failure();
|
||||
return false;
|
||||
}
|
||||
|
||||
emit signalNextRequest();
|
||||
return true;
|
||||
emit signalNextRequest();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RequestHelper::startSingleRequest(const std::function<int64_t()> &requestFunction,
|
||||
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler)
|
||||
bool RequestHelper::startSingleRequest(
|
||||
const std::function<int64_t()>& requestFunction,
|
||||
const std::function<void(const Core::FunctionReply& baseReply)>& baseReplyHandler)
|
||||
{
|
||||
addRequest(requestFunction, baseReplyHandler);
|
||||
return startRequests();
|
||||
addRequest(requestFunction, baseReplyHandler);
|
||||
return startRequests();
|
||||
}
|
||||
|
||||
|
||||
void RequestHelper::failure()
|
||||
{
|
||||
m_failed = true;
|
||||
emit signalFailed();
|
||||
done();
|
||||
m_failed = true;
|
||||
emit signalFailed();
|
||||
done();
|
||||
}
|
||||
|
||||
|
||||
void RequestHelper::done()
|
||||
{
|
||||
#ifdef REQUEST_HELPER_WITH_GUI
|
||||
if (!m_quiet)
|
||||
LtsWidgets::LtsGlobalWaitDialog::getInstance()->done();
|
||||
if (!m_quiet)
|
||||
LtsWidgets::LtsGlobalWaitDialog::getInstance()->done();
|
||||
#endif
|
||||
|
||||
m_requestFunctions.clear();
|
||||
m_singleRequestCustomFunctionReply = nullptr;
|
||||
m_requestFunctions.clear();
|
||||
m_singleRequestCustomFunctionReply = nullptr;
|
||||
|
||||
if (m_blockingCall)
|
||||
emit signalQuitLoop();
|
||||
if (m_blockingCall)
|
||||
emit signalQuitLoop();
|
||||
|
||||
m_blockingCall = true;
|
||||
m_blockingCall = true;
|
||||
|
||||
if (!m_blockingCall)
|
||||
deleteLater();
|
||||
if (!m_blockingCall)
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void RequestHelper::slotNextRequest()
|
||||
{
|
||||
if (m_requestFunctions.isEmpty())
|
||||
{
|
||||
if (!m_blockingCall)
|
||||
emit signalSuccess();
|
||||
|
||||
done();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const RequestFunctionContainer rfc = m_requestFunctions.takeFirst();
|
||||
m_singleRequestCustomFunctionReply = rfc.second;
|
||||
|
||||
int64_t result = rfc.first();
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
#ifdef REQUEST_HELPER_WITH_GUI
|
||||
if (!m_quiet)
|
||||
if (m_requestFunctions.isEmpty())
|
||||
{
|
||||
if (m_blockingCall)
|
||||
{
|
||||
LtsWidgets::LtsMessageDialog::showMessage(qobject_cast<QWidget *>(parent()),
|
||||
tr("Request failed"));
|
||||
}
|
||||
else
|
||||
{
|
||||
connect(new LtsWidgets::LtsMessageDialogNew(qobject_cast<QWidget *>(parent()),
|
||||
tr("Request failed")), &LtsWidgets::LtsMessageDialogNew::destroyed,
|
||||
this, [this]()
|
||||
{
|
||||
failure();
|
||||
});
|
||||
if (!m_blockingCall)
|
||||
emit signalSuccess();
|
||||
|
||||
done();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const RequestFunctionContainer rfc = m_requestFunctions.takeFirst();
|
||||
m_singleRequestCustomFunctionReply = rfc.second;
|
||||
|
||||
int64_t result = rfc.first();
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
#ifdef REQUEST_HELPER_WITH_GUI
|
||||
if (!m_quiet)
|
||||
{
|
||||
if (m_blockingCall)
|
||||
{
|
||||
LtsWidgets::LtsMessageDialog::showMessage(qobject_cast<QWidget*>(parent()), tr("Request failed"));
|
||||
}
|
||||
else
|
||||
{
|
||||
connect(new LtsWidgets::LtsMessageDialogNew(qobject_cast<QWidget*>(parent()), tr("Request failed")),
|
||||
&LtsWidgets::LtsMessageDialogNew::destroyed, this, [this]() { failure(); });
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
failure();
|
||||
}
|
||||
failure();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RequestHelper::startSingleBackgroundRequest(const std::function<int64_t()> &requestFunction,
|
||||
const std::function<void (const Core::FunctionReply &)> &baseReplyHandler)
|
||||
void RequestHelper::startSingleBackgroundRequest(
|
||||
const std::function<int64_t()>& requestFunction,
|
||||
const std::function<void(const Core::FunctionReply&)>& baseReplyHandler)
|
||||
{
|
||||
m_blockingCall = false;
|
||||
startSingleRequest(requestFunction, baseReplyHandler);
|
||||
m_blockingCall = false;
|
||||
startSingleRequest(requestFunction, baseReplyHandler);
|
||||
}
|
||||
|
||||
|
||||
void RequestHelper::startBackgroundRequests()
|
||||
{
|
||||
m_blockingCall = false;
|
||||
startRequests();
|
||||
m_blockingCall = false;
|
||||
startRequests();
|
||||
}
|
||||
|
||||
|
||||
void RequestHelper::setCustomWaitMessage(const QString &customWaitMessage)
|
||||
void RequestHelper::setCustomWaitMessage(const QString& customWaitMessage)
|
||||
{
|
||||
m_customWaitMessage = (customWaitMessage + QStringLiteral(" ..."));
|
||||
m_customWaitMessage = (customWaitMessage + QStringLiteral(" ..."));
|
||||
}
|
||||
|
||||
|
||||
bool RequestHelper::startRequests()
|
||||
{
|
||||
if (m_requestFunctions.isEmpty())
|
||||
{
|
||||
if (m_requestFunctions.isEmpty())
|
||||
{
|
||||
#ifdef LTS_DEBUG
|
||||
qWarning("RequestHelper: started request helper without requests!");
|
||||
qWarning("RequestHelper: started request helper without requests!");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
m_failed = false;
|
||||
m_failed = false;
|
||||
|
||||
#ifdef REQUEST_HELPER_WITH_GUI
|
||||
if (!m_quiet)
|
||||
LtsWidgets::LtsGlobalWaitDialog::getInstance()->wait(m_customWaitMessage);
|
||||
m_customWaitMessage.clear();
|
||||
if (!m_quiet)
|
||||
LtsWidgets::LtsGlobalWaitDialog::getInstance()->wait(m_customWaitMessage);
|
||||
m_customWaitMessage.clear();
|
||||
#endif
|
||||
|
||||
m_errorString.clear();
|
||||
m_repliedId = -1;
|
||||
m_errorString.clear();
|
||||
m_repliedId = -1;
|
||||
|
||||
if (s_debug)
|
||||
{
|
||||
QTimer *t = new QTimer(this);
|
||||
t->setInterval(2000);
|
||||
connect(t, &QTimer::timeout, this, &RequestHelper::slotNextRequest, Qt::QueuedConnection);
|
||||
connect(t, &QTimer::timeout, t, &QTimer::deleteLater);
|
||||
t->start();
|
||||
}
|
||||
else
|
||||
{
|
||||
slotNextRequest();
|
||||
|
||||
if (m_blockingCall)
|
||||
if (s_debug)
|
||||
{
|
||||
QEventLoop loop;
|
||||
connect(this, &RequestHelper::signalQuitLoop,
|
||||
&loop, &QEventLoop::quit,
|
||||
Qt::QueuedConnection);
|
||||
loop.exec();
|
||||
QTimer* t = new QTimer(this);
|
||||
t->setInterval(2000);
|
||||
connect(t, &QTimer::timeout, this, &RequestHelper::slotNextRequest, Qt::QueuedConnection);
|
||||
connect(t, &QTimer::timeout, t, &QTimer::deleteLater);
|
||||
t->start();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
slotNextRequest();
|
||||
|
||||
if (m_blockingCall)
|
||||
{
|
||||
QEventLoop loop;
|
||||
connect(this, &RequestHelper::signalQuitLoop, &loop, &QEventLoop::quit, Qt::QueuedConnection);
|
||||
loop.exec();
|
||||
}
|
||||
}
|
||||
|
||||
return (!m_failed);
|
||||
return (!m_failed);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsUtils
|
||||
Executable → Regular
+74
-73
@@ -1,6 +1,5 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef REQUEST_HELPER_WITH_GUI
|
||||
@@ -12,112 +11,114 @@
|
||||
#endif
|
||||
|
||||
#include <Core/core_types.h>
|
||||
#include <DDS/Core/core.hpp>
|
||||
|
||||
#include <DDS/Core/core.hpp>
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <QPair>
|
||||
#include <QVector>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace LtsUtils
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
dds::core::optional<T> toOptional(T inVal)
|
||||
template <typename T> dds::core::optional<T> toOptional(T inVal)
|
||||
{
|
||||
return inVal != T() ? dds::core::optional<T>(inVal) : dds::core::optional<T>();
|
||||
return inVal != T() ? dds::core::optional<T>(inVal) : dds::core::optional<T>();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
dds::core::optional<T> optional()
|
||||
template <typename T> dds::core::optional<T> optional()
|
||||
{
|
||||
return dds::core::optional<T>();
|
||||
return dds::core::optional<T>();
|
||||
}
|
||||
|
||||
|
||||
class LTSUTILSGUIDDS_INTERNAL_EXPORT RequestHelper : public QObject
|
||||
class LTSUTILSGUIDDS_INTERNAL_EXPORT RequestHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static bool s_debug;
|
||||
public:
|
||||
static bool s_debug;
|
||||
|
||||
explicit RequestHelper(QObject *parent = nullptr, bool quiet = false,
|
||||
|
||||
const std::function<void (void)> &success = [](){},
|
||||
const std::function<void (void)> &failure = [](){});
|
||||
~RequestHelper() = default;
|
||||
explicit RequestHelper(
|
||||
QObject* parent = nullptr, bool quiet = false,
|
||||
|
||||
bool quiet() const { return m_quiet; }
|
||||
void setQuiet(bool quiet) { m_quiet = quiet; }
|
||||
void addRequest(const std::function<int64_t()> &requestFunction,
|
||||
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler = nullptr);
|
||||
bool startRequests();
|
||||
const std::function<void(void)>& success = []() {}, const std::function<void(void)>& failure = []() {});
|
||||
~RequestHelper() = default;
|
||||
|
||||
|
||||
bool startSingleRequest(const std::function<int64_t(void)> &requestFunction,
|
||||
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler = nullptr
|
||||
);
|
||||
bool quiet() const
|
||||
{
|
||||
return m_quiet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void setQuiet(bool quiet)
|
||||
{
|
||||
m_quiet = quiet;
|
||||
}
|
||||
|
||||
void startSingleBackgroundRequest(const std::function<int64_t()> &requestFunction,
|
||||
const std::function<void(const Core::FunctionReply &baseReply)> &baseReplyHandler = nullptr);
|
||||
|
||||
void addRequest(const std::function<int64_t()>& requestFunction,
|
||||
const std::function<void(const Core::FunctionReply& baseReply)>& baseReplyHandler = nullptr);
|
||||
bool startRequests();
|
||||
|
||||
void startBackgroundRequests();
|
||||
bool
|
||||
startSingleRequest(const std::function<int64_t(void)>& requestFunction,
|
||||
const std::function<void(const Core::FunctionReply& baseReply)>& baseReplyHandler = nullptr);
|
||||
|
||||
bool requestReply(const Core::FunctionReply &baseReply);
|
||||
bool requestReply(const Core::FunctionReplyObject &replyObject);
|
||||
void startSingleBackgroundRequest(
|
||||
const std::function<int64_t()>& requestFunction,
|
||||
const std::function<void(const Core::FunctionReply& baseReply)>& baseReplyHandler = nullptr);
|
||||
|
||||
|
||||
void startBackgroundRequests();
|
||||
|
||||
bool hasRequests() const { return !m_requestFunctions.isEmpty(); }
|
||||
bool requestReply(const Core::FunctionReply& baseReply);
|
||||
bool requestReply(const Core::FunctionReplyObject& replyObject);
|
||||
|
||||
bool hasRequests() const
|
||||
{
|
||||
return !m_requestFunctions.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
int getRepliedId() const
|
||||
{
|
||||
return m_repliedId;
|
||||
}
|
||||
|
||||
int getRepliedId() const { return m_repliedId; }
|
||||
QString getErrorString() const
|
||||
{
|
||||
return m_errorString;
|
||||
}
|
||||
|
||||
|
||||
void setCustomWaitMessage(const QString& customWaitMessage);
|
||||
|
||||
QString getErrorString() const { return m_errorString; }
|
||||
bool failed() const
|
||||
{
|
||||
return m_failed;
|
||||
}
|
||||
|
||||
|
||||
void failure();
|
||||
|
||||
void setCustomWaitMessage(const QString &customWaitMessage);
|
||||
private:
|
||||
using RequestFunctionContainer = QPair<std::function<int64_t()>, std::function<void(const Core::FunctionReply&)>>;
|
||||
|
||||
bool failed() const { return m_failed; }
|
||||
void failure();
|
||||
QVector<RequestFunctionContainer> m_requestFunctions;
|
||||
bool m_failed;
|
||||
int m_repliedId;
|
||||
std::function<void(const Core::FunctionReply&)> m_singleRequestCustomFunctionReply;
|
||||
bool m_quiet;
|
||||
bool m_blockingCall;
|
||||
std::function<void(void)> m_successFn;
|
||||
std::function<void(void)> m_failureFn;
|
||||
QString m_errorString;
|
||||
QString m_customWaitMessage;
|
||||
|
||||
private:
|
||||
using RequestFunctionContainer = QPair<std::function<int64_t()>, std::function<void(const Core::FunctionReply &)>>;
|
||||
void done();
|
||||
bool _requestReply(const Core::FunctionReplyObject& fro, const Core::FunctionReply* baseReply);
|
||||
|
||||
QVector<RequestFunctionContainer> m_requestFunctions;
|
||||
bool m_failed;
|
||||
int m_repliedId;
|
||||
std::function<void(const Core::FunctionReply &)> m_singleRequestCustomFunctionReply;
|
||||
bool m_quiet;
|
||||
bool m_blockingCall;
|
||||
std::function<void (void)> m_successFn;
|
||||
std::function<void (void)> m_failureFn;
|
||||
QString m_errorString;
|
||||
QString m_customWaitMessage;
|
||||
|
||||
void done();
|
||||
bool _requestReply(const Core::FunctionReplyObject &fro, const Core::FunctionReply *baseReply);
|
||||
|
||||
signals:
|
||||
void signalNextRequest();
|
||||
void signalQuitLoop();
|
||||
void signalSuccess();
|
||||
void signalFailed();
|
||||
|
||||
private slots:
|
||||
void slotNextRequest();
|
||||
signals:
|
||||
void signalNextRequest();
|
||||
void signalQuitLoop();
|
||||
void signalSuccess();
|
||||
void signalFailed();
|
||||
|
||||
private slots:
|
||||
void slotNextRequest();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace LtsUtils
|
||||
Executable → Regular
+69
-83
@@ -1,114 +1,100 @@
|
||||
|
||||
|
||||
|
||||
#include "style_manager.h"
|
||||
|
||||
#include <LtsPluginManager/lts_plugin_loader.h>
|
||||
#include <PluginInterfaces/style_plugin_interface.h>
|
||||
|
||||
#include <QPluginLoader>
|
||||
#include <QDebug>
|
||||
|
||||
#include <QPluginLoader>
|
||||
|
||||
namespace LtsUtils
|
||||
{
|
||||
|
||||
struct StyleManagerHandler
|
||||
{
|
||||
StyleManager styleManager;
|
||||
StyleManager styleManager;
|
||||
};
|
||||
Q_GLOBAL_STATIC(StyleManagerHandler, s_styleManagerHandler)
|
||||
|
||||
|
||||
StyleManager *StyleManager::getInstance()
|
||||
StyleManager* StyleManager::getInstance()
|
||||
{
|
||||
return &s_styleManagerHandler->styleManager;
|
||||
return &s_styleManagerHandler->styleManager;
|
||||
}
|
||||
|
||||
bool StyleManager::loadStyle(const QString &stylePluginName, bool highDpi)
|
||||
bool StyleManager::loadStyle(const QString& stylePluginName, bool highDpi)
|
||||
{
|
||||
if (m_currentStylePluginLoader != nullptr)
|
||||
{
|
||||
|
||||
if (m_currentStylePluginLoader != nullptr)
|
||||
{
|
||||
|
||||
QObject *pluginInstance = m_currentStylePluginLoader->instance();
|
||||
StylePlugin::Plugin *sp = qobject_cast<StylePlugin::Plugin *>(pluginInstance);
|
||||
QObject* pluginInstance = m_currentStylePluginLoader->instance();
|
||||
StylePlugin::Plugin* sp = qobject_cast<StylePlugin::Plugin*>(pluginInstance);
|
||||
|
||||
if (sp == nullptr)
|
||||
{
|
||||
qWarning() << "StyleManager::loadStyle: could not unload style plugin - wrong type ("
|
||||
<< pluginInstance->metaObject()->className() << ") - new style not loaded";
|
||||
return false;
|
||||
}
|
||||
|
||||
sp->unloadStyle();
|
||||
|
||||
m_currentStylePluginLoader = nullptr;
|
||||
}
|
||||
|
||||
LtsPluginManager::LtsPluginLoader* pluginLoader = LtsPluginManager::LtsPluginLoader::getInstance();
|
||||
|
||||
QPluginLoader* stylePluginLoader = nullptr;
|
||||
int pluginsLoaded = 0;
|
||||
|
||||
std::function<bool(const LtsPluginManager::PluginInstance& pi)> loadPluginFn =
|
||||
[&stylePluginLoader, &pluginsLoaded](const LtsPluginManager::PluginInstance& pi) {
|
||||
stylePluginLoader = pi.pluginLoader;
|
||||
pluginsLoaded++;
|
||||
return true;
|
||||
};
|
||||
|
||||
if (!pluginLoader->loadPlugins(LtsPluginManager::PluginType::STYLE, loadPluginFn, QStringList() << stylePluginName))
|
||||
{
|
||||
qWarning() << "StyleManager::loadStyle: Error loading Style Plugin - using default Qt style";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pluginsLoaded == 0)
|
||||
{
|
||||
qWarning() << "StyleManager::loadStyle: Could not find Style Plugin" << stylePluginName
|
||||
<< "- using default Qt style";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pluginsLoaded > 1)
|
||||
{
|
||||
qWarning() << "StyleManager::loadStyle: Style Plugin" << stylePluginName
|
||||
<< " is ambiguous - using default Qt style";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (stylePluginLoader == nullptr)
|
||||
{
|
||||
qWarning() << "StyleManager::loadStyle: No Style Plugin loader available - using default Qt style";
|
||||
return false;
|
||||
}
|
||||
|
||||
StylePlugin::Plugin* sp = qobject_cast<StylePlugin::Plugin*>(stylePluginLoader->instance());
|
||||
|
||||
if (sp == nullptr)
|
||||
{
|
||||
qWarning() << "StyleManager::loadStyle: could not unload style plugin - wrong type ("
|
||||
<< pluginInstance->metaObject()->className() << ") - new style not loaded";
|
||||
return false;
|
||||
qWarning() << "StyleManager::loadStyle: could not load style plugin - wrong type ("
|
||||
<< stylePluginLoader->instance()->metaObject()->className() << ") - new style not loaded";
|
||||
return false;
|
||||
}
|
||||
|
||||
sp->unloadStyle();
|
||||
sp->loadStyle(highDpi);
|
||||
|
||||
|
||||
m_currentStylePluginLoader = stylePluginLoader;
|
||||
m_stylePluginName = stylePluginName;
|
||||
emit signalStyleChanged(stylePluginName);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
m_currentStylePluginLoader = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
LtsPluginManager::LtsPluginLoader *pluginLoader = LtsPluginManager::LtsPluginLoader::getInstance();
|
||||
|
||||
QPluginLoader *stylePluginLoader = nullptr;
|
||||
int pluginsLoaded = 0;
|
||||
|
||||
std::function<bool(const LtsPluginManager::PluginInstance &pi)> loadPluginFn = [&stylePluginLoader, &pluginsLoaded]
|
||||
(const LtsPluginManager::PluginInstance &pi)
|
||||
{
|
||||
stylePluginLoader = pi.pluginLoader;
|
||||
pluginsLoaded++;
|
||||
return true;
|
||||
};
|
||||
|
||||
if (!pluginLoader->loadPlugins(LtsPluginManager::PluginType::STYLE, loadPluginFn, QStringList() << stylePluginName))
|
||||
{
|
||||
qWarning() << "StyleManager::loadStyle: Error loading Style Plugin - using default Qt style";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pluginsLoaded == 0)
|
||||
{
|
||||
qWarning() << "StyleManager::loadStyle: Could not find Style Plugin" << stylePluginName << "- using default Qt style";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pluginsLoaded > 1)
|
||||
{
|
||||
qWarning() << "StyleManager::loadStyle: Style Plugin" << stylePluginName << " is ambiguous - using default Qt style";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (stylePluginLoader == nullptr)
|
||||
{
|
||||
qWarning() << "StyleManager::loadStyle: No Style Plugin loader available - using default Qt style";
|
||||
return false;
|
||||
}
|
||||
|
||||
StylePlugin::Plugin *sp = qobject_cast<StylePlugin::Plugin *>(stylePluginLoader->instance());
|
||||
|
||||
if (sp == nullptr)
|
||||
{
|
||||
qWarning() << "StyleManager::loadStyle: could not load style plugin - wrong type ("
|
||||
<< stylePluginLoader->instance()->metaObject()->className() << ") - new style not loaded";
|
||||
return false;
|
||||
}
|
||||
|
||||
sp->loadStyle(highDpi);
|
||||
|
||||
m_currentStylePluginLoader = stylePluginLoader;
|
||||
m_stylePluginName = stylePluginName;
|
||||
emit signalStyleChanged(stylePluginName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LtsUtils
|
||||
Executable → Regular
+19
-17
@@ -1,36 +1,38 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ltsutilsguistylemanager_export.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class QPluginLoader;
|
||||
|
||||
|
||||
namespace LtsUtils
|
||||
{
|
||||
class LTSUTILSGUISTYLEMANAGER_EXPORT StyleManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
using QObject::QObject;
|
||||
~StyleManager() = default;
|
||||
public:
|
||||
static StyleManager *getInstance();
|
||||
Q_OBJECT
|
||||
using QObject::QObject;
|
||||
~StyleManager() = default;
|
||||
|
||||
bool loadStyle(const QString &stylePluginName, bool highDpi = false);
|
||||
const QString ¤tStyleName() const { return m_stylePluginName; }
|
||||
public:
|
||||
static StyleManager* getInstance();
|
||||
|
||||
private:
|
||||
friend struct StyleManagerHandler;
|
||||
bool loadStyle(const QString& stylePluginName, bool highDpi = false);
|
||||
|
||||
QPluginLoader *m_currentStylePluginLoader = nullptr;
|
||||
QString m_stylePluginName;
|
||||
const QString& currentStyleName() const
|
||||
{
|
||||
return m_stylePluginName;
|
||||
}
|
||||
|
||||
signals:
|
||||
void signalStyleChanged(const QString &stylePluginName);
|
||||
private:
|
||||
friend struct StyleManagerHandler;
|
||||
|
||||
QPluginLoader* m_currentStylePluginLoader = nullptr;
|
||||
QString m_stylePluginName;
|
||||
|
||||
signals:
|
||||
void signalStyleChanged(const QString& stylePluginName);
|
||||
};
|
||||
}
|
||||
} // namespace LtsUtils
|
||||
Reference in new issue
Block a user