Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Application/THP/thpwidgets/thp_html_widget.cpp
T
Berrux Kana 3f7beb3c7e Qt6 migration: build fixes for Groups 10/11 + missing plugin modules
Continue the Qt5->Qt6 migration so the LTS Projects (Group 10) and LTS
Application (Group 11) compile, link, and ctest runs.

Qt5->Qt6 API migration (resolves removed/deprecated Qt6 APIs) across Lts
Tools and Apps, e.g. QAction->QActionGroup, QAbstractSocket::errorOccurred,
Qt::SkipEmptyParts, QRandomGenerator, QInputDevice::DeviceType,
QRegularExpression, QLatin1Literal->QStringLiteral, and the SampleModel
m_description->description rename.

CMake build fixes:
- CMakeLists.txt: add Lts/Common to CMAKE_AUTOMOC_INCLUDE_DIRECTORIES so moc
  resolves Q_INTERFACES(ProjectPlugin::Plugin) for the migrated Projects.
- cmake/NGLMacros.cmake: NGL_COMPILE_RESOURCES - replace return() (which aborts
  the calling CMakeLists.txt) with an if/else/endif.
- OpApp/THP: guard the ArcGISQt5Hack link with $<IF:$<TARGET_EXISTS:...>> (the
  target is absent when the SituationMap viewer is stubbed); matches
  CentralEffectSimulation.
- LtsSession: prefer the in-tree svcCoreClient target over a FIND_LIBRARY in
  /usr/local/lib.
- CnrProxyTester/DotMatrixDisplay: set AUTOUIC_SEARCH_PATHS for the ui/ subdir.
- TopicDiscover: link NGLLogger.

Export-header visibility stubs (expand the empty *_EXPORT macro to
__attribute__((visibility("default"))); the build sets -fvisibility=hidden and
these stubs shadow the CMake-generated header):
- include/LtsProjectionWorkstation/ltsprojectionworkstation_export.h (fixes
  undefined reference to LtsProjectionWorkstation::getInstance /
  setProjectionOperatorPreset)
- include/LtsSession/ltssession_export.h, include/LtsUtilsGuiDds/ltsutilsguidds_export.h (same pattern)

New plugin modules (copied from legacy) so LtsAppDescriptorChecker finds the
gui:3 IIDs referenced by the Projects' apps.json:
- TakeHomePackageManager/OldTHP              gui:3:tpm.man, gui:3:tpm.usb
- PresentationManagement/.../ScriptEditor   gui:3:pre.script.edit
- Timeline/Gui/EventTimelineClassic         gui:3:tln.view

new_docker_build.sh: correct group targets to the actual CMake target names,
guard LtsReportDisplay on BUILD_CODIFICATION, and skip modules unavailable in
the prebuilt image (AsmWorkstationCertifier/botan2, TrajectoryWidget,
VideoImport, thp_viewer/VLC).
2026-10-05 10:49:34 +02:00

141 lines
3.4 KiB
C++
Executable File

/**
* @RDE_HEADER@
* Handle HTML output for thp
* $Id$
* $HeadURL$
* $Author$
*/
#include "thp_html_widget.h"
#include "ui_thp_html_widget.h"
#include <QUrl>
#include <QWebEnginePage>
#include <NGLLogger/NGLLoggerBootstrap.h>
namespace THP
{
class MyQWebEnginePage : public QWebEnginePage
{
Q_OBJECT
public:
explicit MyQWebEnginePage(NGL::INGLLogger &logger, QObject *parent = nullptr)
: QWebEnginePage(parent)
, m_logger(logger)
{}
MyQWebEnginePage(NGL::INGLLogger &logger, QWebEngineProfile *profile, QObject *parent = nullptr)
: QWebEnginePage(profile, parent)
, m_logger(logger)
{}
bool needsToBeOpenedExternally(const QUrl &url)
{
const QString lpath = url.toString();
// Qt6: QStringRef/QString::splitRef and QString::midRef were removed; use QStringView
const QStringView ext = QStringView{lpath}.split(QLatin1Char('.')).last();
const QStringView ext2Chars = ext.left(2);
if (ext == QLatin1String("html") &&
QStringView{lpath}.mid(lpath.lastIndexOf(QLatin1Char('/')) + 1).startsWith(QLatin1String("combined_")))
return true;
// PDF
if (ext == QLatin1String("pdf"))
return true;
// A/V playlist
if (ext == QLatin1String("pls"))
return true;
// Situation
if (ext == QLatin1String("json"))
return true;
// Word/Excel/PowerPoint
if (ext2Chars == QLatin1String("do") ||
ext2Chars == QLatin1String("xl") ||
ext2Chars == QLatin1String("pp"))
return true;
return false;
}
bool acceptNavigationRequest(const QUrl &url,
QWebEnginePage::NavigationType type,
bool isMainFrame) override
{
Q_UNUSED(isMainFrame)
if (type == QWebEnginePage::NavigationTypeLinkClicked)
{
if (needsToBeOpenedExternally(url))
{
emit linkClicked(url);
DEBUG_LOG(m_logger) << "acceptNavigationRequest denied for " << url.toString();
return false;
}
}
DEBUG_LOG(m_logger) << "acceptNavigationRequest allowed for " << url.toString();
return true;
}
Q_SIGNALS:
void linkClicked(const QUrl &url);
private:
NGL::INGLLogger &m_logger;
};
HtmlWidget::HtmlWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::HtmlWidget)
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("THP.HtmlWidget"))
{
ui->setupUi(this);
auto webEnginePage = new MyQWebEnginePage(m_logger, this);
ui->html->setPage(webEnginePage);
connect(webEnginePage, &MyQWebEnginePage::linkClicked, this, &HtmlWidget::linkClicked);
connect(ui->html, &QWebEngineView::loadFinished, this, &HtmlWidget::loadFinished);
connect(ui->html, &QWebEngineView::urlChanged, this, &HtmlWidget::urlChanged);
connect(ui->html, &QWebEngineView::titleChanged, this, &HtmlWidget::titleChanged);
}
HtmlWidget::~HtmlWidget()
{
delete ui;
}
void HtmlWidget::back()
{
ui->html->back();
}
QString HtmlWidget::title() const
{
return ui->html->title();
}
QUrl HtmlWidget::url() const
{
return ui->html->url();
}
bool HtmlWidget::showHTML(const QUrl &url)
{
if (!url.isValid())
{
WARNING_LOG(m_logger) << "Invalid url: " << url.toString();
return false;
}
ui->html->load(url);
return true;
}
void HtmlWidget::setZoomFactor(double newZoomFactor)
{
ui->html->setZoomFactor(newZoomFactor);
}
void HtmlWidget::print(QPrinter *printer) const
{
ui->html->page()->print(printer, [](bool) {});
}
} // namespace THP
#include "thp_html_widget.moc"