LtsWidgets: Qt6 API fixes complete

- QComboBox::activated signal: QString→int parameter (lts_text_editor)
- qAsConst→std::as_const (5 files)
- localPos()→position() (lts_height_plot_widget)
- setMargin→setContentsMargins (tests/window.cpp)
- CMAKE_AUTOUIC OFF + include in header for MOC
- enterEvent(QEnterEvent*) signature fixes
- QRegExp→QRegularExpression replacements

All LtsWidgets module files now Qt6-compatible.
This commit is contained in:
torsten committed 2026-08-21 11:08:24 +02:00
1 parent ffa25fb394
commit 418443c841
25 files changed
+58 -47

No files matched your search

@@ -146,8 +146,8 @@ NGL_WRAP_UI(ltswidgets_SRCS
)
# ui_requirement.cpp/h sind normale C++ Dateien, keine UI-Dateien
# SKIP_AUTOUIC verhindert dass CMake nach requirement.ui sucht
set_source_files_properties(ui_requirement.cpp PROPERTIES SKIP_AUTOUIC ON)
# CMAKE_AUTOUIC komplett deaktivieren da ui_requirement.h wie eine UI-Datei aussieht
set(CMAKE_AUTOUIC OFF)
NGL_ADD_BIG_RESOURCES(ltswidgets_SRCS resources/lts_resources.qrc)
NGL_ADD_LIBRARY(WS TOOLSWS TOOLSSV LtsWidgets SHARED ${ltswidgets_SRCS})
@@ -8,6 +8,8 @@
*/
#include "lts_abstract_sequence_widget.h"
#include <QRegularExpression>
#include <QToolButton>
namespace LtsWidgets
@@ -119,7 +121,7 @@ void LtsAbstractSequenceWidget::deleteMemberWidget(QObject *member)
QString childName = child->objectName();
QString newId = QString::number(i + 1);
child->setObjectName(childName.replace(QRegExp(QLatin1String(".([0-9]*)")), newId));
child->setObjectName(childName.replace(QRegularExpression(QLatin1String("\\.([0-9]*)")), newId));
}
}
}
@@ -224,7 +224,7 @@ QString LtsAngleEdit::toString(LtsAngleEdit::AngleUnitType t)
void LtsAngleEdit::onCBoxAngleUnitChanged()
{
AngleUnitType newUnit = static_cast<AngleUnitType>(m_ui->cBoxAngleUnit->currentData().toInt());
for(auto dbox : qAsConst(m_sBoxMap))
for(auto dbox : std::as_const(m_sBoxMap))
{
const double value = getAngleConverted(dbox->value(), newUnit, m_currAngleUnit);
auto mapVal = m_dboxLimitMap.value(newUnit);
@@ -12,6 +12,7 @@
#include <QPaintEvent>
#include <QPainter>
#include <QDebug>
#include <QFile>
#ifdef Q_OS_WIN
#include <QtPlatformHeaders/qwindowswindowfunctions.h>
@@ -187,8 +187,9 @@ LtsBaseLayoutWidget::LtsBaseLayoutWidget(QWidget *parent, bool splitMenu)
m_bg->addButton(m_ui->pbAfterAction, (int) ExercisePart::eAfterAction);
m_bg->addButton(m_ui->pbSpecial, (int) ExercisePart::eSpecial);
connect(m_bg, QOverload<int>::of(&QButtonGroup::buttonClicked), m_ui->stackedWidget, [this](int id)
connect(m_bg, QOverload<QAbstractButton*>::of(&QButtonGroup::buttonClicked), m_ui->stackedWidget, [this](QAbstractButton* btn)
{
int id = m_bg->id(btn);
m_ui->stackedWidget->setCurrentWidget(getToolBox((ExercisePart) id));
});
m_ui->pbSpecial->click();
@@ -634,7 +635,7 @@ void LtsBaseLayoutWidget::slotOperatorMenuClicked()
operatorMenu->setTerminalButton(m_showTerminalButton);
bool hasOperatorSettings = false;
for (const PluginData &pd : qAsConst(m_mapButtons))
for (const PluginData &pd : std::as_const(m_mapButtons))
{
if (pd.identifier == QStringLiteral("_OpmShowOperatorSettings"))
{
@@ -1804,7 +1805,7 @@ bool LtsBaseLayoutWidget::messageIdentifierExists(const QString &identifier) con
return true;
}
for (const Message &m : qAsConst(m_messageQueue))
for (const Message &m : std::as_const(m_messageQueue))
{
if (m.identifier == identifier)
{
@@ -14,6 +14,7 @@
#include <QDataStream>
#include <QIcon>
#include <QIODevice>
#include <QRegularExpression>
#include <QSortFilterProxyModel>
#include <QVector>
@@ -80,7 +80,7 @@ public:
void setupUi(QWidget *parent)
{
gridLayout = new QGridLayout(parent);
gridLayout->setMargin(0);
gridLayout->setContentsMargins(0, 0, 0, 0);
int iStart = 3; // 3 invisible widgets before
@@ -1420,7 +1420,7 @@ void LtsDateTimeEdit::onCheckBoxChanged()
}
bEnable = checkBox()->isChecked();
for (auto w : qAsConst(widgets))
for (auto w : std::as_const(widgets))
{
if (w)
w->setEnabled(bEnable);
@@ -80,7 +80,7 @@ public:
void setupUi(QWidget *parent)
{
gridLayout = new QGridLayout(parent);
gridLayout->setMargin(0);
gridLayout->setContentsMargins(0, 0, 0, 0);
int iStart = 3; // 3 invisible widgets before
@@ -13,6 +13,7 @@
#include "lts_dialog_button_box.h"
#include "lts_base_layout_widget.h"
#include "lts_date_time_edit.h"
#include "ui_requirement.h"
#include <QHBoxLayout>
#include <QProgressBar>
@@ -164,7 +165,6 @@ LtsDialog::LtsDialog(QWidget *parent, ButtonCombination buttonCombination, bool
if (l)
{
l->setContentsMargins(0,0,0,0);
l->setMargin(0);
}
else
{
@@ -30,7 +30,8 @@
#include <QDebug>
// Forward declaration - ui_requirement.h is not a UI file but regular C++ code
namespace LtsWidgets { class UiRequirementList; }
// Include is in cpp file to avoid AutoUIC issues
#include "ui_requirement.h"
namespace LtsWidgets
@@ -153,7 +153,7 @@ void LtsDragIcon::initButton()
QVBoxLayout *box = new QVBoxLayout(this);
box->setMargin(0);
box->setContentsMargins(0, 0, 0, 0);
box->setSpacing(0);
box->addWidget(m_toolButton);
@@ -471,7 +471,7 @@ QIcon LtsDragIcon::modifyIcon(const QIcon &icon)
QPainter painter(&iconImage);
painter.save();
painter.setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform);
painter.setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
painter.setBrush(QColor("red"));
painter.setPen(QPen(QColor("red"), 3));
@@ -25,7 +25,7 @@ LtsGridLayout::LtsGridLayout(LtsWidgets::ButtonSize buttonSize, QWidget *parent,
setSizeConstraint(SizeConstraint::SetNoConstraint);
//setHorizontalSpacing(1);
setVerticalSpacing(1);
setMargin(0);
setContentsMargins(0, 0, 0, 0);
}
void LtsGridLayout::add_widget(QWidget *widget)
@@ -64,10 +64,10 @@ void LtsGridLayout::setMaxColumn(int max)
//resetInternalSize
m_colSize = 0;
for (QWidget *wid : qAsConst(m_widgetList))
for (QWidget *wid : std::as_const(m_widgetList))
removeWidget(wid);
for (QWidget *wid : qAsConst(m_widgetList))
for (QWidget *wid : std::as_const(m_widgetList))
addWidgetInternal(wid);
}
@@ -356,8 +356,7 @@ void LtsHeightPlotWidget::Private::repaint()
QImage img(m_curSize, QImage::Format_ARGB32);
img.fill(Qt::transparent);
QPainter p(&img);
const QPainter::RenderHints hints = QPainter::HighQualityAntialiasing |
QPainter::SmoothPixmapTransform |
const QPainter::RenderHints hints = QPainter::SmoothPixmapTransform |
QPainter::TextAntialiasing |
QPainter::Antialiasing;
p.setRenderHints(hints);
@@ -416,7 +415,7 @@ void LtsHeightPlotWidget::Private::repaint()
const QPointF p1(-20, y);
const QString str = QString::number(i);
QRectF r = fm.boundingRect(str);
r.setWidth(fm.width(str)); // important, see docu!
r.setWidth(fm.horizontalAdvance(str)); // important, see docu!
r.moveTo(p1.x() - r.width() / 2., p1.y() - r.height() / 2.);
p.drawText(r, str, Qt::AlignHCenter | Qt::AlignVCenter);
}
@@ -447,7 +446,7 @@ void LtsHeightPlotWidget::Private::repaint()
const QPointF p1(point.x(), point.y() + 15);
const QString str = QString::number(i);
QRectF r = fm.boundingRect(str);
r.setWidth(fm.width(str)); // important, see docu!
r.setWidth(fm.horizontalAdvance(str)); // important, see docu!
r.moveTo(p1.x() - r.width() / 2., p1.y() - r.height() / 2.);
p.drawText(r, str, Qt::AlignHCenter | Qt::AlignVCenter);
}
@@ -526,7 +525,7 @@ void LtsHeightPlotWidget::setMarks(const QVector<QPointF> &data)
void LtsHeightPlotWidget::setBackgroundBrush(const QBrush &brush)
{
QPalette pal = palette();
pal.setBrush(QPalette::Background, brush);
pal.setBrush(QPalette::Window, brush);
setPalette(pal);
}
@@ -594,7 +593,7 @@ void LtsHeightPlotWidget::mouseMoveEvent(QMouseEvent *e)
if (!d->m_heightList.count())
return;
const QPointF pos = d->m_transInverted.map(e->localPos());
const QPointF pos = d->m_transInverted.map(e->position());
emit mousePositionChanged(d->getDataPos(pos.x()), d->getDataHeight(pos.x()), pos.y());
d->m_mousePos = pos;
update();
@@ -40,7 +40,7 @@ void LtsImageEditor::setPixmap(const QPixmap &pixmap)
}
void LtsImageEditor::enterEvent(QEvent *)
void LtsImageEditor::enterEvent(QEnterEvent *)
{
//qWarning() << "enter";
m_isHovered = true;
@@ -52,7 +52,7 @@ public:
protected:
void paintEvent(QPaintEvent *event);
void enterEvent(QEvent *);
void enterEvent(QEnterEvent *);
void leaveEvent(QEvent *);
bool event(QEvent *event);
@@ -81,7 +81,7 @@ LtsMessageDialogNew::LtsMessageDialogNew(QWidget *parent, const QString &message
mainLayout->addWidget(messageLabel);
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->setMargin(0);
buttonLayout->setContentsMargins(0, 0, 0, 0);
// TODO: FIXME: can this be called after the selection was made and the shadow just dies ?
//connect(m_dialog, &LtsFramelessDialog::rejected, this, &LtsMessageDialogHelper::slotCancel); // respect that non-modal dialogs can be closed by clicking outside of it
@@ -43,7 +43,7 @@ Button LtsMessageDialogHelper::showMessage(QWidget *parent,
mainLayout->addWidget(messageLabel);
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->setMargin(0);
buttonLayout->setContentsMargins(0, 0, 0, 0);
// TODO: FIXME: can this be called after the selection was made and the shadow just dies ?
connect(m_dialog, &LtsFramelessDialog::rejected, this, &LtsMessageDialogHelper::slotCancel); // respect that non-modal dialogs can be closed by clicking outside of it
@@ -75,7 +75,7 @@ void LtsMultiRangeSpinBox::fixup(QString &str) const
QValidator::State LtsMultiRangeSpinBox::validateAll(QString &input, int &pos)
{
for(QPair<int,int> range : qAsConst(m_rangesList))
for(QPair<int,int> range : std::as_const(m_rangesList))
{
QIntValidator validator(range.first, range.second);
QValidator::State valState = validator.validate(input, pos);
@@ -127,7 +127,7 @@ void LtsMultiRangeSpinBox::setRanges(const QVector<QPair<int, int>> &ranges)
QStringList rangeStrings;
rangeStrings.reserve(m_rangesList.size());
for (const QPair<int,int> &range : qAsConst(m_rangesList))
for (const QPair<int,int> &range : std::as_const(m_rangesList))
rangeStrings << tr("%1-%2%3").arg(range.first).arg(range.second).arg(suffix());
setToolTip(tr("Ranges:\n%1").arg(rangeStrings.join(QStringLiteral(",\n"))));
}
@@ -43,7 +43,7 @@ void LtsProfileButton::setPixmap(const QPixmap &pixmap)
}
void LtsProfileButton::enterEvent(QEvent *event)
void LtsProfileButton::enterEvent(QEnterEvent *event)
{
//qWarning() << "enter";
m_isHovered = true;
@@ -51,7 +51,7 @@ public:
protected:
void paintEvent(QPaintEvent *event);
void enterEvent(QEvent *event);
void enterEvent(QEnterEvent *event);
void leaveEvent(QEvent *event);
bool event(QEvent *event);
@@ -29,6 +29,7 @@
#include <math.h>
#include <QTimer>
#include <QLabel>
#include <QRandomGenerator>
namespace LtsWidgets
{
@@ -378,7 +379,7 @@ void LtsTabWidget::addWidget(const QString &fullName, QWidget *widget, bool setC
QString randomString;
for (int i = 0; i < randomStringLength; i++)
{
int index = qrand() % possibleCharacters.length();
int index = QRandomGenerator::global()->bounded(possibleCharacters.length());
QChar nextChar = possibleCharacters.at(index);
randomString.append(nextChar);
}
@@ -892,14 +893,14 @@ void CloseButton::mouseReleaseEvent(QMouseEvent *e) // only accept a click direc
QRectF c = cross();
QRect adjusted = QRect(QPoint(floor(c.x()), floor(c.y())), QPoint(ceil(c.right()), ceil(c.bottom() +1 /* hack */))); // be more tolerant
if (!adjusted.contains(e->localPos().toPoint()))
if (!adjusted.contains(e->position().toPoint()))
{
//qWarning() << "NO! release - event:" << e->localPos() << "cross:" << cross();
//qWarning() << "NO! release - event:" << e->position() << "cross:" << cross();
e->ignore();
return;
}
//qWarning() << "YES! release - event:" << e->localPos() << "cross:" << cross();
//qWarning() << "YES! release - event:" << e->position() << "cross:" << cross();
e->accept();
emit clicked();
}
@@ -83,7 +83,7 @@ LtsTextEditor::LtsTextEditor(QWidget *parent)
slotBackgroundColorChanged(m_backgroundColor);
connect(m_ui->cbFonts, QOverload<const QString &>::of(&QComboBox::activated),
connect(m_ui->cbFonts, QOverload<int>::of(&QComboBox::activated),
this, &LtsTextEditor::slotTextFamily);
const QList<int> standardSizes = QFontDatabase::standardSizes();
@@ -91,7 +91,7 @@ LtsTextEditor::LtsTextEditor(QWidget *parent)
m_ui->cbFontSize->addItem(QString::number(size));
m_ui->cbFontSize->setCurrentIndex(standardSizes.indexOf(QApplication::font().pointSize()));
connect(m_ui->cbFontSize, QOverload<const QString &>::of(&QComboBox::activated),
connect(m_ui->cbFontSize, QOverload<int>::of(&QComboBox::activated),
this, &LtsTextEditor::slotTextSize);
connect(m_ui->cbFontSize->lineEdit(), &QLineEdit::editingFinished,
@@ -187,8 +187,9 @@ void LtsTextEditor::slotTextItalic()
}
void LtsTextEditor::slotTextFamily(const QString &f)
void LtsTextEditor::slotTextFamily(int index)
{
Q_UNUSED(index);
QTextCharFormat fmt;
if (m_ui->textEdit->document()->isEmpty())
{
@@ -200,14 +201,17 @@ void LtsTextEditor::slotTextFamily(const QString &f)
fmt.setFontPointSize(pointSize);
fmt.setForeground(m_foregroundColor);
}
const QString f = m_ui->cbFonts->currentText();
fmt.setFontFamily(f);
fmt.setFontFamilies({f});
slotMergeFormatOnWordOrSelection(fmt);
}
void LtsTextEditor::slotTextSize(const QString &p)
void LtsTextEditor::slotTextSize(int index)
{
Q_UNUSED(index);
const QString p = m_ui->cbFontSize->currentText();
qreal pointSize = p.toFloat();
if (p.toFloat() > 0)
@@ -46,9 +46,9 @@ private slots:
void slotClipboardDataChanged();
void slotTextColor();
void slotBackgroundColor();
void slotTextSize(const QString &p);
void slotTextSize(int index);
void slotTextSizeEditingFinished();
void slotTextFamily(const QString &f);
void slotTextFamily(int index);
void slotTextItalic();
void slotTextUnderline();
void slotTextBold();
@@ -18,6 +18,7 @@
#include <QMenu>
#include <QShortcut>
#include <QPointer>
#include <utility>
namespace LtsWidgets
@@ -191,7 +192,7 @@ void LtsToolBarArea::dropEvent(QDropEvent *event)
LtsDragIcon *source = qobject_cast<LtsDragIcon *>(event->source());
// does not work when not dragged on a LtsDragIcon ... should be ok for now
LtsDragIcon *after = nullptr;
QWidget *w = childAt(event->pos());
QWidget *w = childAt(event->position().toPoint());
while (w)
{
after = qobject_cast<LtsDragIcon *>(w);
@@ -212,7 +213,7 @@ QMenu *LtsToolBarArea::functionKeyMenu(QWidget *parent)
{
ShortCut &shorty = val.value();
act = menu->addAction(QStringLiteral("%1%2").arg(shorty.keyName(), !shorty.name.isEmpty() ? QStringLiteral(" - %1").arg(shorty.name) : QString()));
act->setData(shorty.shortcut->key()[0]);
act->setData(shorty.shortcut->key()[0].toCombined());
connect(act, &QAction::triggered, this, &LtsToolBarArea::functionKeyMenuTriggered);
}
menu->addSeparator();
@@ -264,7 +265,7 @@ bool LtsToolBarArea::setFunctionKey(int fkey, const QString &action)
// Icon available?
LtsDragIcon *icon = nullptr;
for (LtsDragIcon *ic : qAsConst(m_buttonMap))
for (LtsDragIcon *ic : std::as_const(m_buttonMap))
{
if (ic->identifier() == action)
{
@@ -280,7 +281,7 @@ bool LtsToolBarArea::setFunctionKey(int fkey, const QString &action)
ShortCut &shorty = m_functionKeys[fkey];
// Remove key symbol from any icon
for (LtsDragIcon *ic : qAsConst(m_buttonMap))
for (LtsDragIcon *ic : std::as_const(m_buttonMap))
if (ic->identifier() == shorty.identifier)
ic->removeModification();
@@ -327,7 +328,7 @@ void LtsToolBarArea::removeMenuAction(LtsDragIcon *icon)
if (itShortcut.identifier == icon->identifier())
itShortcut.clear();
}
for (LtsDragIcon *ic : qAsConst(m_foreignButtonMap))
for (LtsDragIcon *ic : std::as_const(m_foreignButtonMap))
{
if(ic->identifier() == icon->identifier())
{
@@ -17,7 +17,7 @@ Window::Window(QWidget *parent)
QHBoxLayout *lay = new QHBoxLayout;
lay->setMargin(0);
lay->setContentsMargins(0, 0, 0, 0);
//lay->setSizeConstraint(QLayout::SetMinimumSize);