qt6: nglcompression, widgets, dialog fixes: remove QTextCodec, QStringRef/splitRef, QDesktopWidget, use QMultiMap and Qt6 APIs; adjust QtConcurrent::run wrappers; replace endl with newline

This commit is contained in:
torsten committed 2026-07-14 20:38:30 +02:00
1 parent 17f1c61c9e
commit f744a8c37a
328 files changed
+53567 -112

No files matched your search

+5 -3
View File
@@ -1,5 +1,5 @@
FIND_PACKAGE(Log4Qt REQUIRED)
FIND_PACKAGE(Log4Qt)
# Sourcen
SET(NGLLogger_SRCS
@@ -27,7 +27,7 @@ NGL_TARGET_INCLUDE_DIRECTORIES(NGLLogger
)
NGL_TARGET_LINK_LIBRARIES(NGLLogger
PRIVATE
Log4Qt::log4qt
$<IF:$<BOOL:${Log4Qt_FOUND}>,Log4Qt::log4qt,>
PUBLIC
Qt5::Core
)
@@ -37,7 +37,7 @@ NGL_INSTALL_TARGET(NGLLogger)
#
# test_ngllogger
#
IF(BUILD_TESTING AND TARGET NGLLogger)
IF(BUILD_TESTING AND TARGET NGLLogger AND Log4Qt_FOUND)
ADD_EXECUTABLE(test_ngllogger test_ngllogger.cpp)
TARGET_LINK_LIBRARIES(test_ngllogger NGLLogger)
TARGET_LINK_LIBRARIES(test_ngllogger
@@ -45,6 +45,8 @@ IF(BUILD_TESTING AND TARGET NGLLogger)
ngltools
)
ADD_TEST(NAME test_ngllogger COMMAND $<TARGET_FILE:test_ngllogger>)
ELSE()
MESSAGE(STATUS "Log4Qt not found; skipping test_ngllogger")
ENDIF(BUILD_TESTING AND TARGET NGLLogger)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/log4cxx.props ${CMAKE_BINARY_DIR}/log4cxx.props COPYONLY)
-1
View File
@@ -6,7 +6,6 @@ SET(qtsapp_common_SRCS
qtlocalpeer.cpp
qtlocalpeer.h
)
QT5_WRAP_CPP(qtsapp_common_SRCS qtlockedfile.h)
NGL_ADD_LIBRARY(WS AAR SV qtsa_common STATIC ${qtsapp_common_SRCS})
NGL_TARGET_LINK_LIBRARIES(qtsa_common
PUBLIC
+3 -1
View File
@@ -6,6 +6,7 @@
#include <QCoreApplication>
#include <QDataStream>
#include <QTime>
#include <QRegularExpression>
#if defined(Q_OS_WIN)
#include <QLibrary>
@@ -41,7 +42,8 @@ QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId)
#endif
prefix = id.section(QLatin1Char('/'), -1);
}
prefix.remove(QRegExp(QLatin1String("[^a-zA-Z]")));
// QRegExp is removed in Qt6; use QRegularExpression
prefix.remove(QRegularExpression(QLatin1String("[^a-zA-Z]")));
prefix.truncate(6);
QByteArray idc = id.toUtf8();
-1
View File
@@ -29,7 +29,6 @@ namespace QtLP_Private {
class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile
{
Q_OBJECT
public:
enum LockMode { NoLock = 0, ReadLock, WriteLock };
@@ -76,3 +76,4 @@ QtLockedFile::~QtLockedFile()
unlock();
}
+9 -7
View File
@@ -104,7 +104,9 @@ void Compress::compress(QIODevice *out,
{
DEBUG_LOG(m_logger) << "compress #2";
reset();
setupFutureWatcher(QtConcurrent::run(this, &Compress::_compress, out, filesRootDir, files, memFiles, destRootDir));
setupFutureWatcher(QtConcurrent::run([this, out, filesRootDir, files, memFiles, destRootDir]() {
return this->_compress(out, filesRootDir, files, memFiles, destRootDir);
}));
}
void Compress::compress(QIODevice *out, const QString &sourceDir, const QString &destRootDir)
@@ -196,16 +198,16 @@ bool Compress::_compress(QIODevice *output,
};
TarFilter tf(&bzip2, nullptr, readCallback);
TarFilter tf(&bzip2, readCallback);
m_currentTarFilter = &tf;
const QVector<QStringRef> paths = destRootDir.splitRef(QLatin1Char('/'), QString::SkipEmptyParts);
const QStringList paths = destRootDir.split(QLatin1Char('/'), Qt::SkipEmptyParts);
QString curPath;
DEBUG_LOG(m_logger) << "prepairing tar filter";
for (const QStringRef &path : paths)
for (const QString &path : paths)
{
DEBUG_LOG(m_logger) << "path = " << path.toString();
DEBUG_LOG(m_logger) << "path = " << path;
if (m_aborted) return false;
if (curPath.isEmpty())
@@ -310,7 +312,7 @@ void Compress::uncompress(QIODevice *in, const QString &outDir)
{
DEBUG_LOG(m_logger) << "uncompress #1";
reset();
setupFutureWatcher(QtConcurrent::run(this, &Compress::_uncompressDirectory, in, outDir));
setupFutureWatcher(QtConcurrent::run([this, in, outDir](){ return this->_uncompressDirectory(in, outDir); }));
}
bool Compress::_uncompressDirectory(QIODevice *input, const QString &outDir)
@@ -408,7 +410,7 @@ void Compress::uncompress(QIODevice *in)
{
DEBUG_LOG(m_logger) << "uncompress #2!";
reset();
setupFutureWatcher(QtConcurrent::run(this, &Compress::_uncompressBuffer, in));
setupFutureWatcher(QtConcurrent::run([this, in](){ return this->_uncompressBuffer(in); }));
}
bool Compress::_uncompressBuffer(QIODevice *input)
+21 -24
View File
@@ -8,7 +8,7 @@
#include <QIODevice>
#include <QFileInfo>
#include <QDateTime>
#include <QTextCodec>
// Use UTF-8 conversions instead of QTextCodec (Qt6)
#include <time.h>
@@ -30,9 +30,8 @@
class TarFilter::Private
{
public:
Private(QIODevice *dev, QTextCodec *c)
Private(QIODevice *dev)
: device(dev)
, codec(c ? c : QTextCodec::codecForLocale())
, iBufSize(1024 * 1024)
, nextChunkSize(-1)
{}
@@ -66,7 +65,6 @@ public:
bool copyData(QIODevice *in, QIODevice *out, qint64 iSize);
QIODevice *device;
QTextCodec *codec;
QString lastError;
unsigned int iBufSize;
qint64 nextChunkSize;
@@ -76,7 +74,7 @@ public:
bool TarFilter::Private::fi2tph(const FileInformations &infos)
{
QByteArray fn = codec->fromUnicode(infos.fileName);
QByteArray fn = infos.fileName.toUtf8();
#ifdef Q_OS_WIN
if (fn.size() > 3 && fn[1] == ':' && (fn[2] == '\\' || fn[2] == '/'))
fn = fn.mid(3);
@@ -103,8 +101,12 @@ bool TarFilter::Private::fi2tph(const FileInformations &infos)
#else
qstrncpy(hdr.uname, codec->fromUnicode(infos.uname).constData(), sizeof(hdr.uname));
qstrncpy(hdr.gname, codec->fromUnicode(infos.gname).constData(), sizeof(hdr.gname));
{
QByteArray unameBa = infos.uname.toUtf8();
QByteArray gnameBa = infos.gname.toUtf8();
qstrncpy(hdr.uname, unameBa.constData(), sizeof(hdr.uname));
qstrncpy(hdr.gname, gnameBa.constData(), sizeof(hdr.gname));
}
#endif
@@ -131,7 +133,7 @@ bool TarFilter::Private::addHeader(const FileInformations &infos)
{
QByteArray fn = codec->fromUnicode(infos.fileName);
QByteArray fn = infos.fileName.toUtf8();
#ifdef Q_OS_WIN
if (fn.size() > 3 && fn[1] == ':' && (fn[2] == '\\' || fn[2] == '/'))
fn = fn.mid(3);
@@ -155,10 +157,10 @@ bool TarFilter::Private::addHeader(const FileInformations &infos)
#ifndef Q_OS_WIN
struct passwd *p = getpwuid(longlink.uid);
if (p)
longlink.uname = codec->toUnicode(p->pw_name);
longlink.uname = QString::fromUtf8(p->pw_name);
struct group *g = getgrgid(longlink.gid);
if (g)
longlink.gname = codec->toUnicode(g->gr_name);
longlink.gname = QString::fromUtf8(g->gr_name);
#endif
fi2tph(longlink);
QByteArray ba(512, '\0');
@@ -212,15 +214,15 @@ bool TarFilter::Private::tph2fi(FileInformations &infos)
QByteArray ba(hdr.name, sizeof(hdr.name));
ba.resize(qstrlen(ba.constData()));
infos.fileName = codec->toUnicode(ba);
infos.fileName = QString::fromUtf8(ba.constData());
infos.fileSize = QByteArray(hdr.size, sizeof(hdr.size)).toUInt(nullptr, 8);
infos.mode = static_cast<QFile::Permissions>(QByteArray(hdr.mode, sizeof(hdr.mode)).toUInt(nullptr, 16));
infos.uid = QByteArray(hdr.uid, sizeof(hdr.uid)).toUInt(nullptr, 8);
infos.gid = QByteArray(hdr.gid, sizeof(hdr.gid)).toUInt(nullptr, 8);
infos.mtime = QByteArray(hdr.mtime, sizeof(hdr.mtime)).toUInt(nullptr, 8);
infos.fileType = (FileType)hdr.typeflag;
infos.uname = codec->toUnicode(hdr.uname, sizeof(hdr.uname));
infos.gname = codec->toUnicode(hdr.gname, sizeof(hdr.gname));
infos.uname = QString::fromUtf8(QByteArray(hdr.uname, sizeof(hdr.uname)).constData());
infos.gname = QString::fromUtf8(QByteArray(hdr.gname, sizeof(hdr.gname)).constData());
return true;
}
@@ -250,8 +252,8 @@ bool TarFilter::Private::getHeader(FileInformations &infos)
}
if (!tph2fi(infos))
return false;
const int len = qstrlen(fn.constData());
infos.fileName = codec->toUnicode(fn.constData(), len);
const int len = qstrlen(fn.constData());
infos.fileName = QString::fromUtf8(fn.constData(), len);
}
return true;
@@ -319,8 +321,8 @@ bool TarFilter::Private::copyData(QIODevice *in, QIODevice *out, qint64 iSize)
TarFilter::TarFilter(QIODevice *dev, QTextCodec *codec, const std::function<void(qint64)> &readCallback)
: d(new Private(dev, codec))
TarFilter::TarFilter(QIODevice *dev, const std::function<void(qint64)> &readCallback)
: d(new Private(dev))
{
d->readCallback = readCallback;
}
@@ -335,11 +337,6 @@ void TarFilter::abort()
d->aborted = 1;
}
void TarFilter::setLocaleCodec(QTextCodec *codec)
{
d->codec = codec ? codec : QTextCodec::codecForLocale();
}
void TarFilter::setBufferSize(unsigned int size)
{
d->iBufSize = size > 1024 ? size : 1024;
@@ -420,12 +417,12 @@ bool TarFilter::addData(const QString &filename, const QByteArray &data, bool bI
struct passwd p;
getpwuid_r(fi.uid, &p, name, sizeof(name) - 1, &p_ptr);
if (p_ptr)
fi.uname = d->codec->toUnicode(p_ptr->pw_name);
fi.uname = QString::fromUtf8(p_ptr->pw_name);
struct group *g_ptr;
struct group g;
getgrgid_r(fi.gid, &g, name, sizeof(name) - 1, &g_ptr);
if (g_ptr)
fi.gname = d->codec->toUnicode(g_ptr->gr_name);
fi.gname = QString::fromUtf8(g_ptr->gr_name);
#endif
QBuffer buf(const_cast<QByteArray *>(&data));
+3 -5
View File
@@ -11,7 +11,6 @@
#include <functional>
class QIODevice;
class QTextCodec;
class QByteArray;
@@ -50,13 +49,12 @@ public:
TarFilter(QIODevice *dev, QTextCodec *codec = nullptr, const std::function<void(qint64)> &readCallback = nullptr);
TarFilter(QIODevice *dev, const std::function<void(qint64)> &readCallback = nullptr);
~TarFilter();
void abort();
void setLocaleCodec(QTextCodec *codec);
void setBufferSize(unsigned int size);
bool error() const;
void setBufferSize(unsigned int size);
bool error() const;
QString lastError() const;
+5 -1
View File
@@ -102,7 +102,11 @@ QVariant NSqlQuery::boundValue(int pos) const
QMap<QString, QVariant> NSqlQuery::boundValues() const
{
DB_TRACE
return QSqlQuery::boundValues();
QMap<QString, QVariant> res;
const QVariantList list = QSqlQuery::boundValues();
for (int i = 0; i < list.size(); ++i)
res.insert(QString::number(i), list.at(i));
return res;
}
void NSqlQuery::clear()
+3 -3
View File
@@ -166,9 +166,9 @@ namespace NGL
QString defaultPw = QStringLiteral("ctc11de");
if (!databaseUser.isEmpty())
{
const QVector<QStringRef> &sl = databaseUser.splitRef(QLatin1Char('_'));
if (sl.size() > 1)
defaultPw = sl.at(0).toString() + QStringLiteral("11de");
const QStringList sl = databaseUser.split(QLatin1Char('_'));
if (!sl.isEmpty())
defaultPw = sl.at(0) + QStringLiteral("11de");
}
return m_settings->value(QLatin1String("db/passwd"), defaultPw).toString();
}
+3 -3
View File
@@ -270,8 +270,8 @@ static DTGValidation validate18(const QString &input, QDateTime &dt)
}
const int day = input.leftRef(2).toInt();
const int year = input.midRef(16, 2).toInt() + 2000;
const int day = input.left(2).toInt();
const int year = input.mid(16, 2).toInt() + 2000;
dt = QDateTime(QDate(year, month + 1, day), QTime(hh, mm, ss), Qt::UTC);
if (!dt.isValid())
{
@@ -311,7 +311,7 @@ static DTGValidation validate7(const QString &input, QDateTime &dt)
}
const int day = input.leftRef(2).toInt();
const int day = input.left(2).toInt();
const QDate curDate = QDate::currentDate();
dt = QDateTime(QDate(curDate.year(), curDate.month(), day), QTime(hh, mm), Qt::UTC);
if (!dt.isValid())
+4 -2
View File
@@ -66,7 +66,9 @@ bool Translator::setTranslationDataJson(const QByteArray &jsonData, const QByteA
if (m_md5Sum == md5Sum)
return true;
const QJsonObject jObj = QJsonDocument::fromBinaryData(bCompressed ? qUncompress(jsonData) : jsonData).object();
// Use fromJson; fromBinaryData is not available in this Qt build
const QByteArray jsonRaw = bCompressed ? qUncompress(jsonData) : jsonData;
const QJsonObject jObj = QJsonDocument::fromJson(jsonRaw).object();
const QString translationKey(QStringLiteral("translations"));
if (jObj.empty() ||
!jObj.contains(translationKey) ||
@@ -124,7 +126,7 @@ QString Translator::translate(const char *context,
void Translator::isoCodeChanged(const QByteArray &isoCode)
{
m_translationLookup.clear();
for (const TranslationEntry &te : qAsConst(m_catalog))
for (const TranslationEntry &te : std::as_const(m_catalog))
{
if (te.isoCode != isoCode)
continue;
+8
View File
@@ -50,3 +50,11 @@ NGL_TARGET_LINK_LIBRARIES(nglwidgets
)
NGL_INSTALL_TARGET(nglwidgets)
# Unit test for PDFWidget
IF(BUILD_TESTING)
FIND_PACKAGE(Qt6 REQUIRED COMPONENTS Test Widgets)
ADD_EXECUTABLE(test_nglpdfwidget test_nglpdfwidget.cpp)
TARGET_LINK_LIBRARIES(test_nglpdfwidget PRIVATE nglwidgets Qt6::Test Qt6::Widgets)
ADD_TEST(NAME test_nglpdfwidget COMMAND $<TARGET_FILE:test_nglpdfwidget>)
ENDIF(BUILD_TESTING)
+1 -1
View File
@@ -82,7 +82,7 @@ void NGLDialog::centerWidget()
void NGLDialog::printWidget(QWidget *widgetToPrint)
{
QRect r = widgetToPrint->frameGeometry();
QPixmap pm = QApplication::desktop()->grab(r);
QPixmap pm = QGuiApplication::primaryScreen()->grabWindow(0, r.x(), r.y(), r.width(), r.height());
QString path = QString::fromLocal8Bit(qgetenv("GFS_PATH"));
if (path.isEmpty())
path = QCoreApplication::applicationDirPath() + QLatin1String("/../images");
+6 -6
View File
@@ -93,7 +93,7 @@ void NGLDialogButtonBox::addButtonInternal(NGLStandardButton *button)
button->setDefault(false);
button->setAutoDefault(false);
m_standardButtons.insertMulti(button->layoutPriority(), button);
m_standardButtons.insert(button->layoutPriority(), button);
}
void NGLDialogButtonBox::addButton(NGLStandardButton *button)
@@ -168,14 +168,14 @@ bool NGLDialogButtonBox::setVisible(NGLStandardButton::StandardButton button, bo
void NGLDialogButtonBox::layoutPriorityChanged()
{
QMap<qint32, NGLStandardButton *> standardButtons = m_standardButtons;
QMultiMap<qint32, NGLStandardButton *> standardButtons = m_standardButtons;
m_standardButtons.clear();
QMap<int, NGLStandardButton *>::const_iterator it = standardButtons.constBegin();
QMap<int, NGLStandardButton *>::const_iterator end = standardButtons.constEnd();
QMultiMap<int, NGLStandardButton *>::const_iterator it = standardButtons.constBegin();
QMultiMap<int, NGLStandardButton *>::const_iterator end = standardButtons.constEnd();
for (; it != end; ++it)
{
NGLStandardButton *button = it.value();
m_standardButtons.insertMulti(button->layoutPriority(), button);
m_standardButtons.insert(button->layoutPriority(), button);
}
init();
@@ -212,7 +212,7 @@ void NGLDialogButtonBox::init()
lMain = new QHBoxLayout;
l = new QVBoxLayout;
}
lMain->setMargin(0);
lMain->setContentsMargins(0,0,0,0);
if (m_bLineVisible)
{
m_line = new QFrame(this);
+2 -2
View File
@@ -1,6 +1,6 @@
#pragma once
#include <QtCore/QMap>
#include <QtCore/QMultiMap>
#include <QWidget>
#include "nglwidgets_export.h"
@@ -177,7 +177,7 @@ protected Q_SLOTS:
void buttonClicked();
protected:
QMap<qint32, NGLStandardButton *> m_standardButtons;
QMultiMap<qint32, NGLStandardButton *> m_standardButtons;
Qt::Orientation m_orientation;
NGLStandardButton::StandardButtons m_buttons;
NGLStandardButton::StandardButtons m_disabledActions;
+2 -1
View File
@@ -79,7 +79,8 @@ void NGLMainWindow::onInvokeHelp(const QString &helpContext)
}
QTextStream str(m_helpProcess);
str << QLatin1String("activateIdentifier ") + helpContext << QLatin1Char('\0') << endl;
str << QLatin1String("activateIdentifier ") + helpContext << QLatin1Char('\0') << QLatin1Char('\n');
str.flush();
}
void NGLMainWindow::onHelpFinished(int exitCode, QProcess::ExitStatus exitStatus)
+2 -2
View File
@@ -11,7 +11,7 @@ namespace NGL
PDFWidget::PDFWidget(QWidget *parent)
: QWidget(parent)
, m_zoomFactor(1.0)
, ui(new Ui::pdfWidget)
, ui(std::make_unique<Ui::pdfWidget>())
{
ui->setupUi(this);
ui->zoomFull->setVisible(false);
@@ -34,7 +34,7 @@ PDFWidget::PDFWidget(QWidget *parent)
PDFWidget::~PDFWidget()
{
delete ui;
// unique_ptr<Ui::pdfWidget> destructor runs here where Ui::pdfWidget is a complete type
}
bool PDFWidget::showPDF(const QUrl &pdf)
+6 -5
View File
@@ -2,7 +2,8 @@
#pragma once
#include <QWidget>
#include <poppler/qt5/poppler-qt5.h>
#include <memory>
#include <poppler/qt6/poppler-qt6.h>
#include "nglwidgets_export.h"
@@ -32,7 +33,7 @@ public:
int curPage() const;
Q_SIGNALS:
void currentPageChanged(int cur, int max);
void currentPageChanged(int cur, int max);
void rotationChanged(Poppler::Page::Rotation newRotation);
protected Q_SLOTS:
void pageChanged(int cur, int max);
@@ -42,7 +43,7 @@ protected Q_SLOTS:
void onZoomMinus();
void onZoomPlus();
protected:
double m_zoomFactor;
Ui::pdfWidget *ui;
double m_zoomFactor{1.0};
std::unique_ptr<Ui::pdfWidget> ui;
};
}
}
+20
View File
@@ -0,0 +1,20 @@
#include <QTest>
#include "nglpdfwidget.h"
class TestPDFWidget : public QObject
{
Q_OBJECT
private slots:
void initTestCase() {}
void cleanupTestCase() {}
void testConstruct()
{
NGL::PDFWidget w;
QVERIFY(w.numPages() >= 0);
}
};
QTEST_MAIN(TestPDFWidget)
#include "test_nglpdfwidget.moc"