Skip to content

Commit

Permalink
qtpropertybrowser: Port to Qt 6
Browse files Browse the repository at this point in the history
* QRegExp -> QRegularExpression
* QLocale::decimalPoint now returns QString
* QStyleOption::init -> initFrom
* QLayout::setMargin -> setContentsMargins
* QFont::resolve -> resolveMask (hidden API...)
  • Loading branch information
bjorn committed Oct 12, 2020
1 parent 4469ecd commit 45bd6df
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 52 deletions.
26 changes: 13 additions & 13 deletions src/qtpropertybrowser/src/qteditorfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ class QtLineEditFactoryPrivate : public EditorFactoryPrivate<QLineEdit>
public:

void slotPropertyChanged(QtProperty *property, const QString &value);
void slotRegExpChanged(QtProperty *property, const QRegExp &regExp);
void slotRegExpChanged(QtProperty *property, const QRegularExpression &regExp);
void slotSetValue(const QString &value);
void slotEchoModeChanged(QtProperty *, int);
void slotReadOnlyChanged(QtProperty *, bool);
Expand All @@ -1011,7 +1011,7 @@ void QtLineEditFactoryPrivate::slotPropertyChanged(QtProperty *property,
}

void QtLineEditFactoryPrivate::slotRegExpChanged(QtProperty *property,
const QRegExp &regExp)
const QRegularExpression &regExp)
{
if (!m_createdEditors.contains(property))
return;
Expand All @@ -1027,7 +1027,7 @@ void QtLineEditFactoryPrivate::slotRegExpChanged(QtProperty *property,
const QValidator *oldValidator = editor->validator();
QValidator *newValidator = 0;
if (regExp.isValid()) {
newValidator = new QRegExpValidator(regExp, editor);
newValidator = new QRegularExpressionValidator(regExp, editor);
}
editor->setValidator(newValidator);
if (oldValidator)
Expand Down Expand Up @@ -1127,8 +1127,8 @@ void QtLineEditFactory::connectPropertyManager(QtStringPropertyManager *manager)
{
connect(manager, SIGNAL(valueChanged(QtProperty *, const QString &)),
this, SLOT(slotPropertyChanged(QtProperty *, const QString &)));
connect(manager, SIGNAL(regExpChanged(QtProperty *, const QRegExp &)),
this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &)));
connect(manager, SIGNAL(regExpChanged(QtProperty *, const QRegularExpression &)),
this, SLOT(slotRegExpChanged(QtProperty *, const QRegularExpression &)));
connect(manager, SIGNAL(echoModeChanged(QtProperty*, int)),
this, SLOT(slotEchoModeChanged(QtProperty *, int)));
connect(manager, SIGNAL(readOnlyChanged(QtProperty*, bool)),
Expand All @@ -1147,9 +1147,9 @@ QWidget *QtLineEditFactory::createEditor(QtStringPropertyManager *manager,
QLineEdit *editor = d_ptr->createEditor(property, parent);
editor->setEchoMode((EchoMode)manager->echoMode(property));
editor->setReadOnly(manager->isReadOnly(property));
QRegExp regExp = manager->regExp(property);
QRegularExpression regExp = manager->regExp(property);
if (regExp.isValid()) {
QValidator *validator = new QRegExpValidator(regExp, editor);
QValidator *validator = new QRegularExpressionValidator(regExp, editor);
editor->setValidator(validator);
}
editor->setText(manager->value(property));
Expand All @@ -1170,8 +1170,8 @@ void QtLineEditFactory::disconnectPropertyManager(QtStringPropertyManager *manag
{
disconnect(manager, SIGNAL(valueChanged(QtProperty *, const QString &)),
this, SLOT(slotPropertyChanged(QtProperty *, const QString &)));
disconnect(manager, SIGNAL(regExpChanged(QtProperty *, const QRegExp &)),
this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &)));
disconnect(manager, SIGNAL(regExpChanged(QtProperty *, const QRegularExpression &)),
this, SLOT(slotRegExpChanged(QtProperty *, const QRegularExpression &)));
disconnect(manager, SIGNAL(echoModeChanged(QtProperty*,int)),
this, SLOT(slotEchoModeChanged(QtProperty *, int)));
disconnect(manager, SIGNAL(readOnlyChanged(QtProperty*, bool)),
Expand Down Expand Up @@ -1682,7 +1682,7 @@ QtCharEdit::QtCharEdit(QWidget *parent)
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(m_lineEdit);
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
m_lineEdit->installEventFilter(this);
m_lineEdit->setReadOnly(true);
m_lineEdit->setFocusProxy(this);
Expand Down Expand Up @@ -1806,7 +1806,7 @@ void QtCharEdit::keyReleaseEvent(QKeyEvent *e)
void QtCharEdit::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
Expand Down Expand Up @@ -2378,7 +2378,7 @@ bool QtColorEditWidget::eventFilter(QObject *obj, QEvent *ev)
void QtColorEditWidget::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
Expand Down Expand Up @@ -2617,7 +2617,7 @@ bool QtFontEditWidget::eventFilter(QObject *obj, QEvent *ev)
void QtFontEditWidget::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/qtpropertybrowser/src/qteditorfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class QT_QTPROPERTYBROWSER_EXPORT QtLineEditFactory : public QtAbstractEditorFac
Q_DECLARE_PRIVATE(QtLineEditFactory)
Q_DISABLE_COPY(QtLineEditFactory)
Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, const QString &))
Q_PRIVATE_SLOT(d_func(), void slotRegExpChanged(QtProperty *, const QRegExp &))
Q_PRIVATE_SLOT(d_func(), void slotRegExpChanged(QtProperty *, const QRegularExpression &))
Q_PRIVATE_SLOT(d_func(), void slotEchoModeChanged(QtProperty *, int))
Q_PRIVATE_SLOT(d_func(), void slotReadOnlyChanged(QtProperty *, bool))
Q_PRIVATE_SLOT(d_func(), void slotSetValue(const QString &))
Expand Down
30 changes: 11 additions & 19 deletions src/qtpropertybrowser/src/qtpropertybrowserutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void QtBoolEdit::mousePressEvent(QMouseEvent *event)
void QtBoolEdit::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
Expand All @@ -308,7 +308,7 @@ QtKeySequenceEdit::QtKeySequenceEdit(QWidget *parent)
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(m_lineEdit);
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
m_lineEdit->installEventFilter(this);
m_lineEdit->setReadOnly(true);
m_lineEdit->setFocusProxy(this);
Expand Down Expand Up @@ -442,7 +442,7 @@ void QtKeySequenceEdit::keyReleaseEvent(QKeyEvent *e)
void QtKeySequenceEdit::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
Expand All @@ -468,26 +468,18 @@ bool QtKeySequenceEdit::event(QEvent *e)
*/
QString removeRedundantTrialingZeros(const QString &text)
{
const QChar decimalPoint = QLocale::system().decimalPoint();
const QString decimalPoint = QLocale::system().decimalPoint();
const auto decimalPointIndex = text.lastIndexOf(decimalPoint);
if (decimalPointIndex < 0) // return if there is no decimal point
return text;

int i = text.length() - 1;
const auto afterDecimalPoint = decimalPointIndex + decimalPoint.length();
int redundantZeros = 0;

while (i > 0) {
if (text.at(i) == QLatin1Char('0')) {
++redundantZeros;
} else {
if (text.at(i) == decimalPoint)
--redundantZeros;
break;
}
--i;
}

if (redundantZeros > 0)
return text.left(text.length() - redundantZeros);
for (int i = text.length() - 1; i > afterDecimalPoint && text.at(i) == QLatin1Char('0'); --i)
++redundantZeros;

return text;
return text.left(text.length() - redundantZeros);
}


Expand Down
22 changes: 14 additions & 8 deletions src/qtpropertybrowser/src/qtpropertymanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,12 +1310,14 @@ class QtStringPropertyManagerPrivate

struct Data
{
Data() : regExp(QString(QLatin1Char('*')), Qt::CaseSensitive, QRegExp::Wildcard),
echoMode(QLineEdit::Normal), readOnly(false)
Data() :
regExp(QStringLiteral(".*"), QRegularExpression::CaseInsensitiveOption),
echoMode(QLineEdit::Normal),
readOnly(false)
{
}
QString val;
QRegExp regExp;
QRegularExpression regExp;
int echoMode;
bool readOnly;
};
Expand Down Expand Up @@ -1355,7 +1357,7 @@ class QtStringPropertyManagerPrivate
*/

/*!
\fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegExp &regExp)
\fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegularExpression &regExp)
This signal is emitted whenever a property created by this manager
changes its currenlty set regular expression, passing a pointer to
Expand Down Expand Up @@ -1404,9 +1406,9 @@ QString QtStringPropertyManager::value(const QtProperty *property) const
\sa setRegExp()
*/
QRegExp QtStringPropertyManager::regExp(const QtProperty *property) const
QRegularExpression QtStringPropertyManager::regExp(const QtProperty *property) const
{
return getData<QRegExp>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::regExp, property, QRegExp());
return getData<QRegularExpression>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::regExp, property, QRegularExpression());
}

/*!
Expand Down Expand Up @@ -1477,7 +1479,7 @@ void QtStringPropertyManager::setValue(QtProperty *property, const QString &val)
if (data.val == val)
return;

if (data.regExp.isValid() && !data.regExp.exactMatch(val))
if (data.regExp.isValid() && !data.regExp.match(val).hasMatch())
return;

data.val = val;
Expand All @@ -1493,7 +1495,7 @@ void QtStringPropertyManager::setValue(QtProperty *property, const QString &val)
\sa regExp(), setValue(), regExpChanged()
*/
void QtStringPropertyManager::setRegExp(QtProperty *property, const QRegExp &regExp)
void QtStringPropertyManager::setRegExp(QtProperty *property, const QRegularExpression &regExp)
{
const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
Expand Down Expand Up @@ -6067,7 +6069,11 @@ void QtFontPropertyManager::setValue(QtProperty *property, const QFont &val)
return;

const QFont oldVal = it.value();
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
if (oldVal == val && oldVal.resolve() == val.resolve())
#else
if (oldVal == val && oldVal.resolveMask() == val.resolveMask())
#endif
return;

it.value() = val;
Expand Down
7 changes: 4 additions & 3 deletions src/qtpropertybrowser/src/qtpropertymanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include "qtpropertybrowser.h"
#include <QLineEdit>
#include <QRegularExpression>

#if QT_VERSION >= 0x040400
QT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -184,19 +185,19 @@ class QT_QTPROPERTYBROWSER_EXPORT QtStringPropertyManager : public QtAbstractPro
~QtStringPropertyManager();

QString value(const QtProperty *property) const;
QRegExp regExp(const QtProperty *property) const;
QRegularExpression regExp(const QtProperty *property) const;
EchoMode echoMode(const QtProperty *property) const;
bool isReadOnly(const QtProperty *property) const;

public Q_SLOTS:
void setValue(QtProperty *property, const QString &val);
void setRegExp(QtProperty *property, const QRegExp &regExp);
void setRegExp(QtProperty *property, const QRegularExpression &regExp);
void setEchoMode(QtProperty *property, EchoMode echoMode);
void setReadOnly(QtProperty *property, bool readOnly);

Q_SIGNALS:
void valueChanged(QtProperty *property, const QString &val);
void regExpChanged(QtProperty *property, const QRegExp &regExp);
void regExpChanged(QtProperty *property, const QRegularExpression &regExp);
void echoModeChanged(QtProperty *property, const int);
void readOnlyChanged(QtProperty *property, bool);

Expand Down
2 changes: 1 addition & 1 deletion src/qtpropertybrowser/src/qttreepropertybrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ static QIcon drawIndicatorIcon(const QPalette &palette, QStyle *style)
void QtTreePropertyBrowserPrivate::init(QWidget *parent)
{
QHBoxLayout *layout = new QHBoxLayout(parent);
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
m_treeWidget = new QtPropertyEditorView(parent);
m_treeWidget->setEditorPrivate(this);
m_treeWidget->setIconSize(QSize(18, 18));
Expand Down
12 changes: 6 additions & 6 deletions src/qtpropertybrowser/src/qtvariantproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class QtVariantPropertyManagerPrivate
void slotDecimalsChanged(QtProperty *property, int prec);
void slotValueChanged(QtProperty *property, bool val);
void slotValueChanged(QtProperty *property, const QString &val);
void slotRegExpChanged(QtProperty *property, const QRegExp &regExp);
void slotRegExpChanged(QtProperty *property, const QRegularExpression &regExp);
void slotEchoModeChanged(QtProperty *property, int);
void slotValueChanged(QtProperty *property, const QDate &val);
void slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max);
Expand Down Expand Up @@ -540,7 +540,7 @@ void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, con
valueChanged(property, QVariant(val));
}

void QtVariantPropertyManagerPrivate::slotRegExpChanged(QtProperty *property, const QRegExp &regExp)
void QtVariantPropertyManagerPrivate::slotRegExpChanged(QtProperty *property, const QRegularExpression &regExp)
{
if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
emit q_ptr->attributeChanged(varProp, m_regExpAttribute, QVariant(regExp));
Expand Down Expand Up @@ -1011,16 +1011,16 @@ QtVariantPropertyManager::QtVariantPropertyManager(QObject *parent)
d_ptr->m_typeToPropertyManager[QVariant::String] = stringPropertyManager;
d_ptr->m_typeToValueType[QVariant::String] = QVariant::String;
d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_regExpAttribute] =
QVariant::RegExp;
QVariant::RegularExpression;
d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_echoModeAttribute] =
QVariant::Int;
d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_readOnlyAttribute] =
QVariant::Bool;

connect(stringPropertyManager, SIGNAL(valueChanged(QtProperty *, const QString &)),
this, SLOT(slotValueChanged(QtProperty *, const QString &)));
connect(stringPropertyManager, SIGNAL(regExpChanged(QtProperty *, const QRegExp &)),
this, SLOT(slotRegExpChanged(QtProperty *, const QRegExp &)));
connect(stringPropertyManager, SIGNAL(regExpChanged(QtProperty *, const QRegularExpression &)),
this, SLOT(slotRegExpChanged(QtProperty *, const QRegularExpression &)));
connect(stringPropertyManager, SIGNAL(echoModeChanged(QtProperty*,int)),
this, SLOT(slotEchoModeChanged(QtProperty*, int)));
connect(stringPropertyManager, SIGNAL(readOnlyChanged(QtProperty*, bool)),
Expand Down Expand Up @@ -1770,7 +1770,7 @@ void QtVariantPropertyManager::setAttribute(QtProperty *property,
return;
} else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
if (attribute == d_ptr->m_regExpAttribute)
stringManager->setRegExp(internProp, value.value<QRegExp>());
stringManager->setRegExp(internProp, value.value<QRegularExpression>());
if (attribute == d_ptr->m_echoModeAttribute)
stringManager->setEchoMode(internProp, (EchoMode)value.value<int>());
if (attribute == d_ptr->m_readOnlyAttribute)
Expand Down
2 changes: 1 addition & 1 deletion src/qtpropertybrowser/src/qtvariantproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Q_SLOTS:
Q_PRIVATE_SLOT(d_func(), void slotDecimalsChanged(QtProperty *, int))
Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, bool))
Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QString &))
Q_PRIVATE_SLOT(d_func(), void slotRegExpChanged(QtProperty *, const QRegExp &))
Q_PRIVATE_SLOT(d_func(), void slotRegExpChanged(QtProperty *, const QRegularExpression &))
Q_PRIVATE_SLOT(d_func(), void slotEchoModeChanged(QtProperty *, int))
Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QDate &))
Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QDate &, const QDate &))
Expand Down

0 comments on commit 45bd6df

Please sign in to comment.