refactor: Fix Qt deprecation warnings

This commit is contained in:
Lars Toenning
2025-08-29 23:11:21 +02:00
parent 7e79fa0b96
commit a0101ef943
34 changed files with 148 additions and 159 deletions

View File

@@ -128,8 +128,6 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES ".*Clang")
add_compile_options("$<$<COMPILE_LANGUAGE:CXX,OBJCXX>:-Woverloaded-virtual;-Wzero-as-null-pointer-constant;-Wno-return-std-move>")
endif()
add_compile_definitions(QT_NO_DEPRECATED_WARNINGS)
if(SWIFT_USE_CRASHPAD)
add_compile_definitions(SWIFT_USE_CRASHPAD)
endif()

View File

@@ -120,8 +120,8 @@ namespace swift::core::vatsim
Q_UNUSED(changed);
// data read finished
emit this->statusFileRead(statusFileData.count());
emit this->dataRead(CEntityFlags::VatsimStatusFile, CEntityFlags::ReadFinished, statusFileData.count());
emit this->statusFileRead(statusFileData.size());
emit this->dataRead(CEntityFlags::VatsimStatusFile, CEntityFlags::ReadFinished, statusFileData.size());
}
else
{

View File

@@ -664,10 +664,10 @@ namespace swift::gui::components
QPoint globalPos = this->mapToGlobal(point);
QScopedPointer<QMenu> contextMenu(new QMenu(this));
contextMenu->addAction("Max.data area", this, &CDbMappingComponent::resizeForSelect,
QKeySequence(static_cast<Qt::Key>(Qt::CTRL) + Qt::Key_M, Qt::Key_D));
contextMenu->addAction("Max.mapping area", this, &CDbMappingComponent::resizeForMapping,
QKeySequence(static_cast<Qt::Key>(Qt::CTRL) + Qt::Key_M, Qt::Key_M));
contextMenu->addAction("Max.data area", QKeySequence(static_cast<Qt::Key>(Qt::CTRL) + Qt::Key_M, Qt::Key_D),
this, &CDbMappingComponent::resizeForSelect);
contextMenu->addAction("Max.mapping area", QKeySequence(static_cast<Qt::Key>(Qt::CTRL) + Qt::Key_M, Qt::Key_M),
this, &CDbMappingComponent::resizeForMapping);
QAction *selectedItem = contextMenu.data()->exec(globalPos);
Q_UNUSED(selectedItem)
}

View File

@@ -54,11 +54,11 @@ namespace swift::gui::components
ui->le_TxtMsgTo->setValidator(new CUpperCaseValidator(ui->le_TxtMsgFrom));
ui->le_AtisCallsign->setValidator(new CUpperCaseValidator(ui->le_AtisCallsign));
connect(ui->cb_DebugContextAudio, &QCheckBox::stateChanged, this, &CInternalsComponent::enableDebug);
connect(ui->cb_DebugContextApplication, &QCheckBox::stateChanged, this, &CInternalsComponent::enableDebug);
connect(ui->cb_DebugContextNetwork, &QCheckBox::stateChanged, this, &CInternalsComponent::enableDebug);
connect(ui->cb_DebugContextOwnAircraft, &QCheckBox::stateChanged, this, &CInternalsComponent::enableDebug);
connect(ui->cb_DebugContextSimulator, &QCheckBox::stateChanged, this, &CInternalsComponent::enableDebug);
connect(ui->cb_DebugContextAudio, &QCheckBox::checkStateChanged, this, &CInternalsComponent::enableDebug);
connect(ui->cb_DebugContextApplication, &QCheckBox::checkStateChanged, this, &CInternalsComponent::enableDebug);
connect(ui->cb_DebugContextNetwork, &QCheckBox::checkStateChanged, this, &CInternalsComponent::enableDebug);
connect(ui->cb_DebugContextOwnAircraft, &QCheckBox::checkStateChanged, this, &CInternalsComponent::enableDebug);
connect(ui->cb_DebugContextSimulator, &QCheckBox::checkStateChanged, this, &CInternalsComponent::enableDebug);
connect(ui->pb_SendTextMessageDirectly, &QPushButton::released, this, &CInternalsComponent::sendTextMessage,
Qt::QueuedConnection);
@@ -74,7 +74,7 @@ namespace swift::gui::components
connect(ui->pb_NetworkUpdateAndReset, &QPushButton::released, this, &CInternalsComponent::networkStatistics);
connect(ui->pb_NetworkUpdate, &QPushButton::released, this, &CInternalsComponent::networkStatistics);
connect(ui->cb_NetworkStatistics, &QCheckBox::stateChanged, this,
connect(ui->cb_NetworkStatistics, &QCheckBox::checkStateChanged, this,
&CInternalsComponent::onNetworkStatisticsToggled);
if (sGui && sGui->isSupportingCrashpad())
@@ -104,7 +104,7 @@ namespace swift::gui::components
QWidget::showEvent(event);
}
void CInternalsComponent::enableDebug(int state)
void CInternalsComponent::enableDebug(Qt::CheckState checkState)
{
Q_ASSERT(sGui->getIContextApplication());
Q_ASSERT(sGui->getIContextAudio());
@@ -112,7 +112,6 @@ namespace swift::gui::components
Q_ASSERT(sGui->getIContextOwnAircraft());
Q_ASSERT(sGui->getIContextSimulator());
const Qt::CheckState checkState = static_cast<Qt::CheckState>(state);
const bool debug = (checkState == Qt::Checked);
const QObject *sender = QObject::sender();

View File

@@ -39,7 +39,7 @@ namespace swift::gui::components
private:
//! Enable / disable debugging
void enableDebug(int state);
void enableDebug(Qt::CheckState checkState);
//! Send the text message
void sendTextMessage();

View File

@@ -113,7 +113,7 @@ namespace swift::gui::components
this->setForceSmall(true);
// Aircraft previews
connect(ui->cb_AircraftIconDisplayed, &QCheckBox::stateChanged, this,
connect(ui->cb_AircraftIconDisplayed, &QCheckBox::checkStateChanged, this,
&CMappingComponent::onModelPreviewChanged);
// model string completer
@@ -416,7 +416,7 @@ namespace swift::gui::components
this->showOverlayHTMLMessage(msg, 3s);
}
void CMappingComponent::onModelPreviewChanged(int state)
void CMappingComponent::onModelPreviewChanged(Qt::CheckState state)
{
Q_UNUSED(state);
this->closeOverlay();

View File

@@ -120,7 +120,7 @@ namespace swift::gui
void onResetAircraft();
//! Model preview
void onModelPreviewChanged(int state);
void onModelPreviewChanged(Qt::CheckState state);
//! Request update for models from backend
void onModelsUpdateRequested();

View File

@@ -251,7 +251,7 @@ namespace swift::gui::components
void CNavigatorDialog::enterEvent(QEnterEvent *event)
{
// event called when mouse is over, acts as auto-focus
QApplication::setActiveWindow(this);
activateWindow();
QDialog::enterEvent(event);
}

View File

@@ -16,13 +16,13 @@ namespace swift::gui::components
const bool crashDumpUploadEnabled = m_crashDumpUploadEnabled.getThreadLocal();
ui->cb_crashDumpsUpload->setChecked(crashDumpUploadEnabled);
connect(ui->cb_crashDumpsUpload, &QCheckBox::stateChanged, this,
connect(ui->cb_crashDumpsUpload, &QCheckBox::checkStateChanged, this,
&CSettingsAdvancedComponent::crashDumpUploadEnabledChanged);
}
CSettingsAdvancedComponent::~CSettingsAdvancedComponent() {}
void CSettingsAdvancedComponent::crashDumpUploadEnabledChanged(int state)
void CSettingsAdvancedComponent::crashDumpUploadEnabledChanged(Qt::CheckState state)
{
auto text = ui->cb_crashDumpsUpload->text();
if (!text.endsWith("(restart needed)"))

View File

@@ -33,7 +33,7 @@ namespace swift::gui::components
virtual ~CSettingsAdvancedComponent();
private:
void crashDumpUploadEnabledChanged(int state);
void crashDumpUploadEnabledChanged(Qt::CheckState state);
QScopedPointer<Ui::CSettingsAdvancedComponent> ui;
swift::misc::CSetting<swift::core::application::TCrashDumpUploadEnabled> m_crashDumpUploadEnabled { this };

View File

@@ -20,7 +20,7 @@ namespace swift::gui::editors
m_allCheckBoxes = this->findChildren<QCheckBox *>(QString(), Qt::FindDirectChildrenOnly);
for (QCheckBox *cb : std::as_const(m_allCheckBoxes))
{
connect(cb, &QCheckBox::stateChanged, this, &CInterpolationSetupForm::onCheckboxChanged);
connect(cb, &QCheckBox::checkStateChanged, this, &CInterpolationSetupForm::onCheckboxChanged);
}
// one connect is enough, otherwise 2 change signals
@@ -79,7 +79,7 @@ namespace swift::gui::editors
return CStatusMessageList();
}
void CInterpolationSetupForm::onCheckboxChanged(int state)
void CInterpolationSetupForm::onCheckboxChanged(Qt::CheckState state)
{
Q_UNUSED(state)
emit this->valueChanged();

View File

@@ -53,7 +53,7 @@ namespace swift::gui::editors
QList<QCheckBox *> m_allCheckBoxes;
//! Checkbox has been changed
void onCheckboxChanged(int state);
void onCheckboxChanged(Qt::CheckState state);
//! Interpolator mode
void onInterpolatorModeChanged(bool checked);

View File

@@ -194,7 +194,7 @@ namespace swift::gui
Q_ASSERT(m_widget);
if (m_windowMode == WindowFrameless && event->button() == Qt::LeftButton)
{
m_framelessDragPosition = event->globalPos() - m_widget->frameGeometry().topLeft();
m_framelessDragPosition = event->globalPosition().toPoint() - m_widget->frameGeometry().topLeft();
event->accept();
return true;
}
@@ -217,7 +217,7 @@ namespace swift::gui
return false;
}
m_widget->move(event->globalPos() - m_framelessDragPosition);
m_widget->move(event->globalPosition().toPoint() - m_framelessDragPosition);
event->accept();
return true;
}

View File

@@ -377,7 +377,7 @@ namespace swift::gui
const QJsonDocument jsonDoc(QJsonDocument::fromJson(utf8Data));
const QJsonObject jsonObj(jsonDoc.object());
const QString typeName(jsonObj.value("type").toString());
const int typeId = QMetaType::type(qPrintable(typeName));
const int typeId = QMetaType::fromName(qPrintable(typeName)).id();
// check if a potential valid value object
if (typeName.isEmpty() || typeId == QMetaType::UnknownType) { return CVariant(); }
@@ -397,7 +397,7 @@ namespace swift::gui
Q_ASSERT_X(!jsonObj.isEmpty(), Q_FUNC_INFO, "Empty JSON object");
const QString typeName(jsonObj.value("type").toString());
if (typeName.isEmpty()) { return Unknown; }
const int typeId = QMetaType::type(qPrintable(typeName));
const int typeId = QMetaType::fromName(qPrintable(typeName)).id();
return typeId;
}
@@ -724,14 +724,7 @@ namespace swift::gui
return effect;
}
QFontMetrics CGuiUtility::currentFontMetrics()
{
const QWidget *w = CGuiUtility::mainApplicationWidget();
if (w) { return w->fontMetrics(); }
return QApplication::fontMetrics();
}
QFontMetricsF CGuiUtility::currentFontMetricsF() { return QFontMetricsF(CGuiUtility::currentFontMetrics()); }
QFontMetricsF CGuiUtility::currentFontMetricsF() { return QFontMetricsF(qApp->font()); }
QFont CGuiUtility::currentFont()
{
@@ -754,7 +747,7 @@ namespace swift::gui
{
// 43 characters 0123456789012345678901234567890123456789012
static const QString s("The quick brown fox jumps over the lazy dog");
const QFontMetricsF fm = CGuiUtility::currentFontMetrics();
const QFontMetricsF fm = CGuiUtility::currentFontMetricsF();
const qreal scale = withRatio ? CGuiUtility::mainApplicationWidgetPixelRatio() : 1.0;
const QSizeF size = fm.size(Qt::TextSingleLine, s);
return size * scale;

View File

@@ -227,9 +227,6 @@ namespace swift::gui
static QGraphicsOpacityEffect *fadeOutWidget(int durationMs, QWidget *widget, double startValue = 1.0,
double endValue = 0.0);
//! Main window font metrics or default metrics
static QFontMetrics currentFontMetrics();
//! Main window font metrics or default metrics
static QFontMetricsF currentFontMetricsF();

View File

@@ -41,7 +41,7 @@ namespace swift::gui
QCheckBox *cb = new QCheckBox(name);
cb->setObjectName(identifier);
cb->setProperty("pluginIdentifier", identifier);
connect(cb, &QCheckBox::stateChanged, this, &CPluginSelector::handlePluginStateChange);
connect(cb, &QCheckBox::checkStateChanged, this, &CPluginSelector::handlePluginStateChange);
if (enabled) { cb->setCheckState(Qt::Checked); }
else { cb->setCheckState(Qt::Unchecked); }

View File

@@ -616,7 +616,7 @@ namespace swift::misc
for (auto it = m_timestamps.cbegin(); it != m_timestamps.cend(); ++it)
{
result.push_back(it.key() + "(" +
QDateTime::fromMSecsSinceEpoch(it.value(), Qt::UTC).toString(Qt::ISODate) + ")");
QDateTime::fromMSecsSinceEpoch(it.value(), QTimeZone::UTC).toString(Qt::ISODate) + ")");
}
return result.join(",");
}

View File

@@ -55,7 +55,7 @@ namespace swift::misc
if (!file.open(QIODevice::WriteOnly)) { return false; }
const qint64 c = file.write(data);
file.close();
return c == data.count();
return c == data.size();
}
bool CFileUtils::writeStringToLockedFile(const QString &content, const QString &fileNameAndPath)

View File

@@ -122,7 +122,7 @@ namespace swift::misc
{
list.push_back(fromQStringList(T::getLogCategories()));
}
if constexpr (QMetaTypeId<T>::Defined) { list.push_back(QMetaType::typeName(qMetaTypeId<T>())); }
if constexpr (QMetaTypeId<T>::Defined) { list.push_back(QMetaType(qMetaTypeId<T>()).name()); }
if constexpr (std::is_base_of_v<QObject, T>)
{
list.appendCategoriesFromMetaObject(T::staticMetaObject);

View File

@@ -29,9 +29,9 @@ namespace swift::misc
meta = meta.append("type: ")
.append(QString::number(mt))
.append(" name: ")
.append(QMetaType::typeName(mt))
.append(metaType.name())
.append(" | ")
.append(QString::number(QMetaType::sizeOf(mt)))
.append(QString::number(metaType.sizeOf()))
.append(" / ")
.append(QString::number(swift::misc::heapSizeOf(metaType)))
.append(separator);

View File

@@ -67,7 +67,7 @@ namespace swift::misc
template <class Derived>
QString MetaType<Derived>::getClassName() const
{
return QMetaType::typeName(getMetaTypeId());
return QMetaType(getMetaTypeId()).name();
}
template <class Derived>

View File

@@ -49,7 +49,7 @@ namespace swift::misc
// doing this in the switch gives gcc warning as IndexIcon is no member of ColumnIndex
if (static_cast<int>(i) == static_cast<int>(IndexIcon))
{
if (static_cast<QMetaType::Type>(variant.type()) == QMetaType::Int)
if (static_cast<QMetaType::Type>(variant.typeId()) == QMetaType::Int)
{
CIcons::IconIndex iconIndex = variant.value<CIcons::IconIndex>();
this->m_icon = CIcon::iconByIndex(iconIndex);

View File

@@ -115,7 +115,8 @@ namespace swift::misc
void CRgbColor::setByString(const QString &color, bool isName)
{
if (color.isEmpty()) { return; }
else if (isName)
if (isName)
{
const QColor q(color);
m_r = q.red();
@@ -132,7 +133,7 @@ namespace swift::misc
this->setInvalid();
return;
}
q.setNamedColor("#" + c);
q = QColor::fromString("#" + c);
this->setQColor(q);
}
}

View File

@@ -320,7 +320,7 @@ namespace swift::misc::simulation
else if (variant.canConvert<qint64>()) { m_fileTimestamp = variant.value<qint64>(); }
break;
case IndexModelMode:
if (static_cast<QMetaType::Type>(variant.type()) == QMetaType::QString)
if (static_cast<QMetaType::Type>(variant.typeId()) == QMetaType::QString)
{
this->setModelModeAsString(variant.toString());
}
@@ -519,7 +519,8 @@ namespace swift::misc::simulation
QDateTime CAircraftModel::getFileTimestamp() const
{
return this->hasValidFileTimestamp() ? QDateTime::fromMSecsSinceEpoch(m_fileTimestamp, Qt::UTC) : QDateTime();
return this->hasValidFileTimestamp() ? QDateTime::fromMSecsSinceEpoch(m_fileTimestamp, QTimeZone::utc()) :
QDateTime();
}
QString CAircraftModel::getFormattedFileTimestampYmdhms() const

View File

@@ -412,12 +412,12 @@ namespace swift::misc::simulation::fscommon
{
return {}; // normal when there is no settings value
}
else if (static_cast<QMetaType::Type>(qv.type()) == QMetaType::QStringList)
if (static_cast<QMetaType::Type>(qv.typeId()) == QMetaType::QStringList)
{
const QStringList l = qv.toStringList();
return l.join(",").trimmed();
}
else if (static_cast<QMetaType::Type>(qv.type()) == QMetaType::QString) { return qv.toString().trimmed(); }
if (static_cast<QMetaType::Type>(qv.typeId()) == QMetaType::QString) { return qv.toString().trimmed(); }
Q_ASSERT(false);
return {};
}

View File

@@ -273,7 +273,7 @@ namespace swift::misc
if (dateTimeString.isEmpty() || format.isEmpty()) { return {}; }
QDateTime dt = QDateTime::fromString(dateTimeString, format);
if (!dt.isValid()) { return dt; }
dt.setOffsetFromUtc(0); // must only be applied to valid timestamps
dt.setTimeZone(QTimeZone::utc()); // must only be applied to valid timestamps
return dt;
}
@@ -282,7 +282,7 @@ namespace swift::misc
if (dateTimeString.isEmpty()) { return {}; }
QDateTime dt = QDateTime::fromString(dateTimeString, format);
if (!dt.isValid()) { return dt; }
dt.setOffsetFromUtc(0); // must only be applied to valid timestamps
dt.setTimeZone(QTimeZone::utc()); // must only be applied to valid timestamps
return dt;
}
@@ -291,7 +291,7 @@ namespace swift::misc
if (dateTimeString.isEmpty()) { return {}; }
QDateTime dt = locale.toDateTime(dateTimeString, format);
if (!dt.isValid()) { return dt; }
dt.setOffsetFromUtc(0); // must only be applied to valid timestamps
dt.setTimeZone(QTimeZone::utc()); // must only be applied to valid timestamps
return dt;
}
@@ -348,7 +348,7 @@ namespace swift::misc
QDate date;
date.setDate(year, month, day);
QDateTime dt;
dt.setOffsetFromUtc(0);
dt.setTimeZone(QTimeZone::utc());
dt.setDate(date);
if (dateTimeString.length() < 12) { return dt; }

View File

@@ -116,8 +116,9 @@ namespace swift::misc
QStringList result;
for (const auto &key : keys)
{
QString time = contains(key) ?
QDateTime::fromMSecsSinceEpoch(value(key).second, Qt::UTC).toString(Qt::ISODate) :
QString time =
contains(key) ?
QDateTime::fromMSecsSinceEpoch(value(key).second, QTimeZone::utc()).toString(Qt::ISODate) :
"no timestamp";
result.push_back(key + " (" + time + ")");
}
@@ -255,7 +256,7 @@ namespace swift::misc
if (values.isEmpty()) { return; }
m_elements.detach(); //! \fixme see http://doc.qt.io/qt-5/containers.html#implicit-sharing-iterator-problem
auto out = std::as_const(m_elements).lowerBound(values.cbegin().key());
auto end = std::as_const(m_elements).upperBound((values.cend() - 1).key());
auto end = std::as_const(m_elements).upperBound((std::prev(values.cend())).key());
for (auto in = values.cbegin(); in != values.cend(); ++in)
{
while (out != end && out.key() < in.key()) { ++out; }
@@ -292,7 +293,7 @@ namespace swift::misc
CValueCachePacket ackedChanges(values.isSaved());
m_elements.detach(); //! \fixme see http://doc.qt.io/qt-5/containers.html#implicit-sharing-iterator-problem
auto out = std::as_const(m_elements).lowerBound(values.cbegin().key());
auto end = std::as_const(m_elements).upperBound((values.cend() - 1).key());
auto end = std::as_const(m_elements).upperBound((std::prev(values.cend())).key());
for (auto in = values.cbegin(); in != values.cend(); ++in)
{
while (out != end && out.key() < in.key()) { ++out; }
@@ -822,24 +823,21 @@ namespace swift::misc
{
return CStatusMessage(this, invalidSeverity, u"Empty cache value %1", true) << element.m_nameWithKey;
}
else if (value.userType() != element.m_metaType)
if (value.userType() != element.m_metaType)
{
return CStatusMessage(this).error(u"Expected %1 but got %2 for %3")
<< QMetaType::typeName(element.m_metaType) << value.typeName() << element.m_nameWithKey;
<< QMetaType(element.m_metaType).name() << value.typeName() << element.m_nameWithKey;
}
else if (element.m_validator && !element.m_validator(value, reason))
if (element.m_validator && !element.m_validator(value, reason))
{
if (reason.isEmpty())
{
return CStatusMessage(this).error(u"%1 is not valid for %2")
<< value.toQString() << element.m_nameWithKey;
}
else
{
return CStatusMessage(this).error(u"%1 (%2 for %3)")
<< reason << value.toQString() << element.m_nameWithKey;
}
}
else { return {}; }
}

View File

@@ -29,9 +29,9 @@ namespace swift::misc
//! \private
int qMetaTypeId_CVariantList = -1; // referenced in variantlist.cpp
private_ns::IValueObjectMetaInfo *private_ns::getValueObjectMetaInfo(int typeId)
private_ns::IValueObjectMetaInfo *private_ns::getValueObjectMetaInfo(QMetaType mt)
{
return getValueObjectMetaInfo(QVariant(QMetaType(typeId), nullptr));
return getValueObjectMetaInfo(QVariant(mt, nullptr));
}
private_ns::IValueObjectMetaInfo *private_ns::getValueObjectMetaInfo(const QVariant &v)
@@ -41,14 +41,15 @@ namespace swift::misc
bool CVariant::canConvert(int typeId) const
{
if (m_v.canConvert(typeId)) { return true; }
const QMetaType mt(typeId);
if (m_v.canConvert(mt)) { return true; }
if (typeId == qMetaTypeId_CVariantList)
{
return m_v.canConvert<QVector<CVariant>>() || m_v.canConvert<QVariantList>();
}
if (userType() == qMetaTypeId_CVariantList)
{
return QVariant::fromValue(QVector<CVariant>()).canConvert(typeId) ||
return QVariant::fromValue(QVector<CVariant>()).canConvert(mt) ||
QVariant(QMetaType(typeId), nullptr).canConvert<QVariantList>();
}
return false;
@@ -56,14 +57,15 @@ namespace swift::misc
bool CVariant::convert(int typeId)
{
if (!m_v.canConvert(typeId))
const QMetaType mt(typeId);
if (!m_v.canConvert(mt))
{
if (!canConvert(typeId)) { return false; }
if (typeId == qMetaTypeId_CVariantList)
{
if (m_v.canConvert<QVector<CVariant>>())
{
if (!m_v.convert(qMetaTypeId<QVector<CVariant>>())) { return false; }
if (!m_v.convert(QMetaType(qMetaTypeId<QVector<CVariant>>()))) { return false; }
}
else if (m_v.canConvert<QVariantList>())
{
@@ -77,14 +79,14 @@ namespace swift::misc
}
if (userType() == qMetaTypeId_CVariantList)
{
if (QVariant::fromValue(QVector<CVariant>()).canConvert(typeId))
if (QVariant::fromValue(QVector<CVariant>()).canConvert(mt))
{
if (!m_v.convert(qMetaTypeId<QVector<CVariant>>())) { return false; }
if (!m_v.convert(QMetaType(qMetaTypeId<QVector<CVariant>>()))) { return false; }
}
else { return false; }
}
}
return m_v.convert(typeId);
return m_v.convert(mt);
}
bool CVariant::isVariantList() const { return userType() == qMetaTypeId_CVariantList; }
@@ -168,22 +170,22 @@ namespace swift::misc
QJsonObject json;
json.insert("type", this->typeName());
switch (m_v.type())
switch (m_v.metaType().id())
{
case QVariant::Invalid: json.insert("value", 0); break;
case QVariant::Int: json.insert("value", m_v.toInt()); break;
case QVariant::UInt: json.insert("value", m_v.toInt()); break;
case QVariant::Bool: json.insert("value", m_v.toBool()); break;
case QVariant::Double: json.insert("value", m_v.toDouble()); break;
case QVariant::LongLong: json.insert("value", m_v.toLongLong()); break;
case QVariant::ULongLong: json.insert("value", m_v.toLongLong()); break;
case QVariant::String: json.insert("value", m_v.toString()); break;
case QVariant::Char: json.insert("value", m_v.toString()); break;
case QVariant::ByteArray: json.insert("value", m_v.toString()); break;
case QVariant::DateTime: json.insert("value", m_v.toDateTime().toString(Qt::ISODate)); break;
case QVariant::Date: json.insert("value", m_v.toDate().toString(Qt::ISODate)); break;
case QVariant::Time: json.insert("value", m_v.toTime().toString(Qt::ISODate)); break;
case QVariant::StringList: json.insert("value", QJsonArray::fromStringList(m_v.toStringList())); break;
case QMetaType::UnknownType: json.insert("value", 0); break;
case QMetaType::Int: json.insert("value", m_v.toInt()); break;
case QMetaType::UInt: json.insert("value", m_v.toInt()); break;
case QMetaType::Bool: json.insert("value", m_v.toBool()); break;
case QMetaType::Double: json.insert("value", m_v.toDouble()); break;
case QMetaType::LongLong: json.insert("value", m_v.toLongLong()); break;
case QMetaType::ULongLong: json.insert("value", m_v.toLongLong()); break;
case QMetaType::QString: json.insert("value", m_v.toString()); break;
case QMetaType::Char: json.insert("value", m_v.toString()); break;
case QMetaType::QByteArray: json.insert("value", m_v.toString()); break;
case QMetaType::QDateTime: json.insert("value", m_v.toDateTime().toString(Qt::ISODate)); break;
case QMetaType::QDate: json.insert("value", m_v.toDate().toString(Qt::ISODate)); break;
case QMetaType::QTime: json.insert("value", m_v.toTime().toString(Qt::ISODate)); break;
case QMetaType::QStringList: json.insert("value", QJsonArray::fromStringList(m_v.toStringList())); break;
default:
try
{
@@ -222,44 +224,44 @@ namespace swift::misc
m_v.clear();
return;
}
const int typeId = QMetaType::type(qPrintable(typeName));
const QMetaType mt = QMetaType::fromName(qPrintable(typeName));
const QJsonValue value = json.value("value");
if (value.isUndefined()) { throw CJsonException("Missing 'value'"); }
switch (typeId)
switch (mt.id())
{
case QVariant::Invalid: throw CJsonException("Type not recognized by QMetaType");
case QVariant::Int: m_v.setValue(value.toInt()); break;
case QVariant::UInt: m_v.setValue<uint>(static_cast<uint>(value.toInt())); break;
case QVariant::Bool: m_v.setValue(value.toBool()); break;
case QVariant::Double: m_v.setValue(value.toDouble()); break;
case QVariant::LongLong: m_v.setValue(static_cast<qlonglong>(value.toDouble())); break;
case QVariant::ULongLong: m_v.setValue(static_cast<qulonglong>(value.toDouble())); break;
case QVariant::String: m_v.setValue(value.toString()); break;
case QVariant::Char: m_v.setValue(value.toString().size() > 0 ? value.toString().at(0) : '\0'); break;
case QVariant::ByteArray: m_v.setValue(value.toString().toLatin1()); break;
case QVariant::DateTime: m_v.setValue(fromStringUtc(value.toString(), Qt::ISODate)); break;
case QVariant::Date: m_v.setValue(QDate::fromString(value.toString(), Qt::ISODate)); break;
case QVariant::Time: m_v.setValue(QTime::fromString(value.toString(), Qt::ISODate)); break;
case QVariant::StringList: m_v.setValue(QVariant(value.toArray().toVariantList()).toStringList()); break;
case QMetaType::UnknownType: throw CJsonException("Type not recognized by QMetaType");
case QMetaType::Int: m_v.setValue(value.toInt()); break;
case QMetaType::UInt: m_v.setValue<uint>(static_cast<uint>(value.toInt())); break;
case QMetaType::Bool: m_v.setValue(value.toBool()); break;
case QMetaType::Double: m_v.setValue(value.toDouble()); break;
case QMetaType::LongLong: m_v.setValue(static_cast<qlonglong>(value.toDouble())); break;
case QMetaType::ULongLong: m_v.setValue(static_cast<qulonglong>(value.toDouble())); break;
case QMetaType::QString: m_v.setValue(value.toString()); break;
case QMetaType::Char: m_v.setValue(value.toString().size() > 0 ? value.toString().at(0) : '\0'); break;
case QMetaType::QByteArray: m_v.setValue(value.toString().toLatin1()); break;
case QMetaType::QDateTime: m_v.setValue(fromStringUtc(value.toString(), Qt::ISODate)); break;
case QMetaType::QDate: m_v.setValue(QDate::fromString(value.toString(), Qt::ISODate)); break;
case QMetaType::QTime: m_v.setValue(QTime::fromString(value.toString(), Qt::ISODate)); break;
case QMetaType::QStringList: m_v.setValue(QVariant(value.toArray().toVariantList()).toStringList()); break;
default:
try
{
auto *meta = private_ns::getValueObjectMetaInfo(typeId);
auto *meta = private_ns::getValueObjectMetaInfo(mt);
if (meta)
{
CJsonScope scope("value"); // tracker
Q_UNUSED(scope);
m_v = QVariant(QMetaType(typeId), nullptr);
m_v = QVariant(mt, nullptr);
// this will call convertFromJson if there is no MemoizedJson
meta->convertFromMemoizedJson(value.toObject(), data(), true);
}
else if (QMetaType::hasRegisteredConverterFunction(QMetaType(qMetaTypeId<QString>()),
QMetaType(typeId)))
else if (QMetaType::hasRegisteredConverterFunction(QMetaType(qMetaTypeId<QString>()), mt))
{
m_v.setValue(value.toString());
if (!m_v.convert(typeId)) { throw CJsonException("Failed to convert from JSON string"); }
if (!m_v.convert(mt)) { throw CJsonException("Failed to convert from JSON string"); }
}
else { throw CJsonException("Type not supported by convertFromJson"); }
}
@@ -315,9 +317,9 @@ namespace swift::misc
m_v.clear();
return;
}
int typeId = QMetaType::type(qPrintable(typeName));
const QMetaType mt = QMetaType::fromName(qPrintable(typeName));
auto *meta = private_ns::getValueObjectMetaInfo(typeId);
auto *meta = private_ns::getValueObjectMetaInfo(mt);
if (meta)
{
try
@@ -326,7 +328,7 @@ namespace swift::misc
if (value.isUndefined()) { throw CJsonException("Missing 'value'"); }
CJsonScope scope("value");
m_v = QVariant(QMetaType(typeId), nullptr);
m_v = QVariant(mt, nullptr);
meta->convertFromMemoizedJson(value.toObject(), data(), allowFallbackToJson);
}
catch (const private_ns::CVariantException &ex)
@@ -353,18 +355,18 @@ namespace swift::misc
size_t CVariant::getValueHash() const
{
switch (m_v.type())
switch (m_v.metaType().id())
{
case QVariant::Invalid: return 0;
case QVariant::Int: return qHash(m_v.toInt());
case QVariant::UInt: return qHash(m_v.toUInt());
case QVariant::Bool: return qHash(m_v.toUInt());
case QVariant::Double: return qHash(m_v.toUInt());
case QVariant::LongLong: return qHash(m_v.toLongLong());
case QVariant::ULongLong: return qHash(m_v.toULongLong());
case QVariant::String: return qHash(m_v.toString());
case QVariant::Char: return qHash(m_v.toChar());
case QVariant::ByteArray: return qHash(m_v.toByteArray());
case QMetaType::UnknownType: return 0;
case QMetaType::Int: return qHash(m_v.toInt());
case QMetaType::UInt: return qHash(m_v.toUInt());
case QMetaType::Bool: return qHash(m_v.toUInt());
case QMetaType::Double: return qHash(m_v.toUInt());
case QMetaType::LongLong: return qHash(m_v.toLongLong());
case QMetaType::ULongLong: return qHash(m_v.toULongLong());
case QMetaType::QString: return qHash(m_v.toString());
case QMetaType::Char: return qHash(m_v.toChar());
case QMetaType::QByteArray: return qHash(m_v.toByteArray());
default:
try
{
@@ -397,7 +399,7 @@ namespace swift::misc
* 2 functions required for unmarshallFromDbus
* \internal
*/
QVariant fixQVariantFromDbusArgument(const QVariant &variant, int localUserType, const QString &typeName);
QVariant fixQVariantFromDbusArgument(const QVariant &variant, QMetaType localUserType, const QString &typeName);
QVariant complexQtTypeFromDbusArgument(const QDBusArgument &argument, int type);
//! @}
@@ -410,7 +412,7 @@ namespace swift::misc
if (typeName.isEmpty()) { *this = CVariant(); }
else
{
*this = fixQVariantFromDbusArgument(dbusVar.variant(), QMetaType::type(qPrintable(typeName)), typeName);
*this = fixQVariantFromDbusArgument(dbusVar.variant(), QMetaType::fromName(qPrintable(typeName)), typeName);
}
}
@@ -481,10 +483,9 @@ namespace swift::misc
QPixmap CVariant::toPixmap() const
{
if (m_v.type() == QVariant::Pixmap) { return m_v.value<QPixmap>(); }
if (m_v.type() == QVariant::Image) { return QPixmap::fromImage(m_v.value<QImage>()); }
if (m_v.type() == QVariant::Icon) { return iconToPixmap(m_v.value<QIcon>()); }
if (m_v.typeId() == QMetaType::QPixmap) { return m_v.value<QPixmap>(); }
if (m_v.typeId() == QMetaType::QImage) { return QPixmap::fromImage(m_v.value<QImage>()); }
if (m_v.typeId() == QMetaType::QIcon) { return iconToPixmap(m_v.value<QIcon>()); }
return CIcon(toIcon()).toPixmap();
}
@@ -492,7 +493,7 @@ namespace swift::misc
int CVariant::getMetaTypeId() const { return private_ns::MetaTypeHelper<CVariant>::maybeGetMetaTypeId(); }
QString CVariant::getClassName() const { return QMetaType::typeName(getMetaTypeId()); }
QString CVariant::getClassName() const { return QMetaType(getMetaTypeId()).name(); }
bool CVariant::isA(int metaTypeId) const
{
@@ -521,24 +522,23 @@ namespace swift::misc
}
}
QVariant fixQVariantFromDbusArgument(const QVariant &variant, int localUserType, const QString &typeName)
QVariant fixQVariantFromDbusArgument(const QVariant &variant, QMetaType localUserType, const QString &typeName)
{
if (localUserType == static_cast<int>(QVariant::Invalid))
if (localUserType.id() == static_cast<int>(QMetaType::UnknownType))
{
CLogMessage(&variant).warning(u"Invalid type for unmarshall: %1") << typeName;
}
// my business?
if (!variant.canConvert<QDBusArgument>()) { return variant; }
// complex, user type
// it has to be made sure, that the cast works
const QDBusArgument arg = variant.value<QDBusArgument>();
constexpr int userType = static_cast<int>(QVariant::UserType);
if (localUserType < userType)
constexpr int userType = static_cast<int>(QMetaType::User);
if (localUserType.id() < userType)
{
// complex Qt type, e.g. QDateTime
return complexQtTypeFromDbusArgument(arg, localUserType);
return complexQtTypeFromDbusArgument(arg, localUserType.id());
}
else if (QMetaType(localUserType).flags() & QMetaType::IsEnumeration)
{
@@ -593,7 +593,7 @@ namespace swift::misc
}
default:
{
const char *name = QMetaType::typeName(type);
const char *name = QMetaType(type).name();
qFatal("Type cannot be resolved: %s (%d)", name ? name : "", type);
}
}

View File

@@ -84,9 +84,6 @@ namespace swift::misc
//! Move-construct from a QVariant.
CVariant(QVariant &&var) noexcept : m_v(std::move(var)) {}
//! Construct a null variant of the given type.
CVariant(QVariant::Type type) : m_v(type) {}
//! Avoid unexpected implicit cast to QVariant::Type. (Use CVariant::from() instead.)
CVariant(int) = delete;
@@ -252,7 +249,11 @@ namespace swift::misc
bool isValid() const { return m_v.isValid(); }
//! Return the metatype ID of the value in this variant, or QMetaType::User if it is a user type.
QMetaType::Type type() const { return static_cast<QMetaType::Type>(m_v.type()); }
QMetaType::Type type() const
{
const int type = m_v.typeId();
return type >= QMetaType::Type::User ? QMetaType::Type::User : static_cast<QMetaType::Type>(type);
}
//! Return the typename of the value in this variant.
const char *typeName() const { return m_v.typeName(); }

View File

@@ -78,7 +78,7 @@ namespace swift::misc
static QString blurb(int typeId, const QString &operationName)
{
return QString("CVariant requested unsupported operation of contained ") + QMetaType::typeName(typeId) +
return QString("CVariant requested unsupported operation of contained ") + QMetaType(typeId).name() +
" object: " + operationName;
}
};
@@ -369,7 +369,7 @@ namespace swift::misc
}
//! \private Getter to obtain the IValueObjectMetaInfo which was stored by swift::misc::registerMetaValueType.
IValueObjectMetaInfo *getValueObjectMetaInfo(int typeId);
IValueObjectMetaInfo *getValueObjectMetaInfo(QMetaType mt);
//! \private Getter to obtain the IValueObjectMetaInfo which was stored by swift::misc::registerMetaValueType.
IValueObjectMetaInfo *getValueObjectMetaInfo(const QVariant &);

View File

@@ -410,7 +410,7 @@ bool CSwiftLauncher::warnAboutOtherSwiftApplications()
const QString msg = u"While using the wizard no other application should run.\nClose applications and try "
u"again.\nCurrently running: " %
running.processNames().join(',');
QMessageBox::question(this, "Wizard", msg, QMessageBox::Close);
QMessageBox::question(this, "Wizard", msg, QMessageBox::StandardButtons(QMessageBox::StandardButton::Close));
return false;
}

View File

@@ -728,9 +728,9 @@ namespace SwiftFsdTest
// Server without ICAOEQ capability is set by default (in init())
QSignalSpy spy(m_client, &CFSDClient::rawFsdMessage);
QDateTime takeoffTimePlanned = QDateTime::fromString("1530", "hhmm");
takeoffTimePlanned.setTimeSpec(Qt::UTC);
takeoffTimePlanned.setTimeZone(QTimeZone::utc());
QDateTime takeoffTimeActual = QDateTime::fromString("1535", "hhmm");
takeoffTimeActual.setTimeSpec(Qt::UTC);
takeoffTimeActual.setTimeZone(QTimeZone::utc());
CAltitude flightLevel(35000, CAltitude::FlightLevel, CLengthUnit::ft());
CFlightPlanAircraftInfo info("H/B744/L");
CFlightPlan fp({}, info, "EGLL", "KORD", "NONE", takeoffTimePlanned, takeoffTimeActual,
@@ -755,9 +755,9 @@ namespace SwiftFsdTest
QSignalSpy spy(m_client, &CFSDClient::rawFsdMessage);
QDateTime takeoffTimePlanned = QDateTime::fromString("1530", "hhmm");
takeoffTimePlanned.setTimeSpec(Qt::UTC);
takeoffTimePlanned.setTimeZone(QTimeZone::utc());
QDateTime takeoffTimeActual = QDateTime::fromString("1535", "hhmm");
takeoffTimeActual.setTimeSpec(Qt::UTC);
takeoffTimeActual.setTimeZone(QTimeZone::utc());
CAltitude flightLevel(35000, CAltitude::FlightLevel, CLengthUnit::ft());
CFlightPlanAircraftInfo info("B748/H-SDE3FGHIM1M2RWXY/LB1");
CFlightPlan fp({}, info, "EGLL", "KORD", "NONE", takeoffTimePlanned, takeoffTimeActual,

View File

@@ -84,7 +84,7 @@ namespace MiscTest
(c.length() == size) ? fromStringUtc(c, "yyyyMMddHHmmss") : fromStringUtc(c, "yyyyMMddHHmmsszzz");
QDateTime dt3 = (c.length() == size) ? QDateTime::fromString(c, "yyyyMMddHHmmss") :
QDateTime::fromString(c, "yyyyMMddHHmmsszzz");
dt3.setOffsetFromUtc(0);
dt3.setTimeZone(QTimeZone::utc());
const qint64 ms1 = dt1.toMSecsSinceEpoch();
const qint64 ms2 = dt2.toMSecsSinceEpoch();

View File

@@ -16,3 +16,4 @@ target_include_directories(SimpleCrypt
${PROJECT_SOURCE_DIR}/third_party
)
set_property(TARGET SimpleCrypt PROPERTY POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(SimpleCrypt PRIVATE QT_NO_DEPRECATED_WARNINGS)