Support Qt 6 (commit 174154b)
This commit is contained in:
parent
4757b0a8b7
commit
cb3a4960e7
|
@ -9,8 +9,8 @@ set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
|
|||
set(META_APP_DESCRIPTION
|
||||
"Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models")
|
||||
set(META_VERSION_MAJOR 6)
|
||||
set(META_VERSION_MINOR 2)
|
||||
set(META_VERSION_PATCH 1)
|
||||
set(META_VERSION_MINOR 3)
|
||||
set(META_VERSION_PATCH 0)
|
||||
set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH})
|
||||
|
||||
project(${META_PROJECT_NAME})
|
||||
|
@ -24,6 +24,7 @@ set(HEADER_FILES
|
|||
misc/dialogutils.h
|
||||
misc/desktoputils.h
|
||||
misc/conversion.h
|
||||
misc/compat.h
|
||||
models/checklistmodel.h
|
||||
resources/qtconfigarguments.h
|
||||
resources/resources.h
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <c++utilities/application/argumentparser.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QMessageBox>
|
||||
#include <QStringBuilder>
|
||||
|
|
|
@ -62,7 +62,7 @@ macro (use_qt_module)
|
|||
endif ()
|
||||
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};${TARGET}")
|
||||
set("PKG_CONFIG_${ARGS_PREFIX}_${ARGS_MODULE}" "${ARGS_PREFIX}${ARGS_MODULE}")
|
||||
message(STATUS "Linking ${META_TARGET_NAME} against Qt 5 module ${TARGET}.")
|
||||
message(STATUS "Linking ${META_TARGET_NAME} against Qt module ${TARGET}.")
|
||||
|
||||
# hack for "StaticQt5": re-assign INTERFACE_LINK_LIBRARIES_RELEASE to INTERFACE_LINK_LIBRARIES
|
||||
get_target_property("${ARGS_MODULE}_INTERFACE_LINK_LIBRARIES_RELEASE" "${TARGET}"
|
||||
|
@ -86,7 +86,7 @@ macro (use_qt_module)
|
|||
continue()
|
||||
endif ()
|
||||
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};${ARGS_PREFIX}::Q${PLUGIN}Plugin")
|
||||
message(STATUS "Linking ${META_TARGET_NAME} against Qt 5 plugin ${ARGS_PREFIX}::Q${PLUGIN}Plugin.")
|
||||
message(STATUS "Linking ${META_TARGET_NAME} against Qt plugin ${ARGS_PREFIX}::Q${PLUGIN}Plugin.")
|
||||
endforeach ()
|
||||
|
||||
# unset variables (can not simply use a function because Qt's variables need to be exported)
|
||||
|
@ -95,13 +95,26 @@ macro (use_qt_module)
|
|||
endforeach ()
|
||||
endmacro ()
|
||||
|
||||
# define function to make qmake variable available within CMake
|
||||
# define function to make Qt variable available; queries qmake or uses variables provided by Qt 6
|
||||
function (query_qmake_variable QMAKE_VARIABLE)
|
||||
# prevent queries for variables already known
|
||||
if (NOT "${${QMAKE_VARIABLE}}" STREQUAL "")
|
||||
return()
|
||||
endif ()
|
||||
|
||||
# check configuration variables provided by Qt 6
|
||||
if (QMAKE_VARIABLE MATCHES "QT_(.*)")
|
||||
set(VARIABLE_NAME "${CMAKE_MATCH_1}")
|
||||
if (QT6_${VARIABLE_NAME})
|
||||
set(VARIABLE_NAME QT6_${VARIABLE_NAME})
|
||||
endif ()
|
||||
if (NOT "${${VARIABLE_NAME}}" STREQUAL "")
|
||||
set ("${QMAKE_VARIABLE}" "${${VARIABLE_NAME}}" PARENT_SCOPE)
|
||||
message(STATUS "Qt variable ${QMAKE_VARIABLE} taken from ${VARIABLE_NAME}: ${${VARIABLE_NAME}}")
|
||||
return()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# execute qmake
|
||||
get_target_property(QMAKE_BIN "${QT_QMAKE_TARGET}" IMPORTED_LOCATION)
|
||||
execute_process(
|
||||
|
@ -119,8 +132,6 @@ function (query_qmake_variable QMAKE_VARIABLE)
|
|||
string(REGEX REPLACE "\n$" "" "${QMAKE_VARIABLE}" "${${QMAKE_VARIABLE}}")
|
||||
|
||||
# export variable to parent scope
|
||||
set("${QMAKE_VARIABLE}"
|
||||
"${${QMAKE_VARIABLE}}"
|
||||
PARENT_SCOPE)
|
||||
message(STATUS "qmake variable ${QMAKE_VARIABLE} is ${${QMAKE_VARIABLE}}")
|
||||
set("${QMAKE_VARIABLE}" "${${QMAKE_VARIABLE}}" PARENT_SCOPE)
|
||||
message(STATUS "Qt variable ${QMAKE_VARIABLE} queried from qmake: ${${QMAKE_VARIABLE}}")
|
||||
endfunction ()
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
#ifndef QT_UTILITIES_COMPAT_H
|
||||
#define QT_UTILITIES_COMPAT_H
|
||||
|
||||
#include "../global.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
#define QT_UTILITIES_USE_Q_STRING_VIEW
|
||||
#endif
|
||||
// note: QStringView has been available since Qt 5.10 but for a consistent ABI/API regardless which
|
||||
// Qt 5.x version is used it makes sense to stick to QStringRef when using Qt 5.
|
||||
|
||||
#ifdef QT_UTILITIES_USE_Q_STRING_VIEW
|
||||
#include <QStringView>
|
||||
#else
|
||||
#include <QStringRef>
|
||||
#endif
|
||||
|
||||
namespace QtUtilities {
|
||||
|
||||
using Utf16CharType =
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
char16_t
|
||||
#else
|
||||
ushort
|
||||
#endif
|
||||
;
|
||||
|
||||
using StringView =
|
||||
#ifdef QT_UTILITIES_USE_Q_STRING_VIEW
|
||||
QStringView
|
||||
#else
|
||||
QStringRef
|
||||
#endif
|
||||
;
|
||||
|
||||
/*!
|
||||
* \brief Makes either a QStringView or a QStringRef depending on the Qt version.
|
||||
*/
|
||||
inline StringView makeStringView(const QString &str)
|
||||
{
|
||||
return StringView(
|
||||
#ifndef QT_UTILITIES_USE_Q_STRING_VIEW
|
||||
&
|
||||
#endif
|
||||
str);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Makes either a QStringView or a QStringRef depending on the Qt version, applying "mid()" parameters.
|
||||
*/
|
||||
inline StringView midRef(const QString &str, int pos, int n = -1)
|
||||
{
|
||||
#ifdef QT_UTILITIES_USE_Q_STRING_VIEW
|
||||
return QStringView(str).mid(pos, n);
|
||||
#else
|
||||
return str.midRef(pos, n);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Splits \a str into QStringViews, QStringRefs or QStrings depending on the Qt version.
|
||||
*/
|
||||
template <class... SplitArgs> inline auto splitRef(const QString &str, SplitArgs &&... args)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
return QStringView(str).split(std::forward<SplitArgs>(args)...);
|
||||
#elif QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
|
||||
return str.splitRef(std::forward<SplitArgs>(args)...);
|
||||
#else
|
||||
return str.split(std::forward<SplitArgs>(args)...);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace QtUtilities
|
||||
|
||||
#endif // QT_UTILITIES_COMPAT_H
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef CONVERSION_H
|
||||
#define CONVERSION_H
|
||||
#ifndef QT_UTILITIES_CONVERSION_H
|
||||
#define QT_UTILITIES_CONVERSION_H
|
||||
|
||||
#include "../global.h"
|
||||
|
||||
|
@ -38,4 +38,4 @@ inline QString fromNativeFileName(const std::string &nativeFileName)
|
|||
|
||||
} // namespace QtUtilities
|
||||
|
||||
#endif // CONVERSION_H
|
||||
#endif // QT_UTILITIES_CONVERSION_H
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
#if defined(QT_UTILITIES_GUI_QTWIDGETS)
|
||||
#include <QApplication>
|
||||
#include <QCursor>
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
|
||||
#include <QDesktopWidget>
|
||||
#endif
|
||||
#include <QScreen>
|
||||
#include <QStyle>
|
||||
#include <QWidget>
|
||||
|
|
|
@ -52,7 +52,13 @@ QPalette PaletteEditor::palette() const
|
|||
void PaletteEditor::setPalette(const QPalette &palette)
|
||||
{
|
||||
m_editPalette = palette;
|
||||
const uint mask = palette.resolve();
|
||||
const auto mask = palette.
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
resolveMask()
|
||||
#else
|
||||
resolve()
|
||||
#endif
|
||||
;
|
||||
for (int i = 0; i < static_cast<int>(QPalette::NColorRoles); ++i) {
|
||||
if (mask & (1 << i)) {
|
||||
continue;
|
||||
|
@ -64,7 +70,14 @@ void PaletteEditor::setPalette(const QPalette &palette)
|
|||
m_editPalette.setBrush(
|
||||
QPalette::Disabled, static_cast<QPalette::ColorRole>(i), m_parentPalette.brush(QPalette::Disabled, static_cast<QPalette::ColorRole>(i)));
|
||||
}
|
||||
m_editPalette.resolve(mask);
|
||||
m_editPalette.
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
setResolveMask(mask);
|
||||
m_editPalette = m_editPalette.resolve(m_editPalette)
|
||||
#else
|
||||
resolve(mask)
|
||||
#endif
|
||||
;
|
||||
updatePreviewPalette();
|
||||
updateStyledButton();
|
||||
m_paletteUpdated = true;
|
||||
|
@ -170,7 +183,13 @@ QPalette PaletteEditor::getPalette(QWidget *parent, const QPalette &init, const
|
|||
{
|
||||
PaletteEditor dlg(parent);
|
||||
auto parentPalette(parentPal);
|
||||
const uint mask = init.resolve();
|
||||
const auto mask = init.
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
resolveMask()
|
||||
#else
|
||||
resolve()
|
||||
#endif
|
||||
;
|
||||
for (int i = 0; i < static_cast<int>(QPalette::NColorRoles); ++i) {
|
||||
if (mask & (1 << i)) {
|
||||
continue;
|
||||
|
@ -224,7 +243,13 @@ QVariant PaletteModel::data(const QModelIndex &index, int role) const
|
|||
return m_roleNames[static_cast<QPalette::ColorRole>(index.row())];
|
||||
}
|
||||
if (role == Qt::EditRole) {
|
||||
const uint mask = m_palette.resolve();
|
||||
const auto mask = m_palette.
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
resolveMask()
|
||||
#else
|
||||
resolve()
|
||||
#endif
|
||||
;
|
||||
if (mask & (1 << index.row()))
|
||||
return true;
|
||||
return false;
|
||||
|
@ -284,7 +309,13 @@ bool PaletteModel::setData(const QModelIndex &index, const QVariant &value, int
|
|||
return true;
|
||||
}
|
||||
if (index.column() == 0 && role == Qt::EditRole) {
|
||||
uint mask = m_palette.resolve();
|
||||
auto mask = m_palette.
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
resolveMask()
|
||||
#else
|
||||
resolve()
|
||||
#endif
|
||||
;
|
||||
const bool isMask = qvariant_cast<bool>(value);
|
||||
const int r = index.row();
|
||||
if (isMask) {
|
||||
|
@ -298,7 +329,14 @@ bool PaletteModel::setData(const QModelIndex &index, const QVariant &value, int
|
|||
m_parentPalette.brush(QPalette::Disabled, static_cast<QPalette::ColorRole>(r)));
|
||||
mask &= ~(1 << index.row());
|
||||
}
|
||||
m_palette.resolve(mask);
|
||||
m_palette.
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
setResolveMask(mask);
|
||||
m_palette = m_palette.resolve(m_palette)
|
||||
#else
|
||||
resolve(mask)
|
||||
#endif
|
||||
;
|
||||
emit paletteChanged(m_palette);
|
||||
const QModelIndex idxEnd = PaletteModel::index(r, 3);
|
||||
emit dataChanged(index, idxEnd);
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
#include <QList>
|
||||
#include <QObject>
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
Q_MOC_INCLUDE("settingsdialog/optionpage.h")
|
||||
#endif
|
||||
|
||||
namespace QtUtilities {
|
||||
|
||||
class OptionPage;
|
||||
|
|
|
@ -22,9 +22,17 @@ bool OptionCategoryFilterModel::filterAcceptsRow(int sourceRow, const QModelInde
|
|||
{
|
||||
if (QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent))
|
||||
return true;
|
||||
if (OptionCategoryModel *model = qobject_cast<OptionCategoryModel *>(sourceModel())) {
|
||||
if (auto *const model = qobject_cast<OptionCategoryModel *>(sourceModel())) {
|
||||
if (OptionCategory *category = model->category(sourceRow)) {
|
||||
return category->matches(filterRegExp().pattern());
|
||||
return category->matches(
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
filterRegularExpression().pattern()
|
||||
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||
!filterRegularExpression().pattern().isEmpty() ? filterRegularExpression().pattern() : filterRegExp().pattern()
|
||||
#else
|
||||
filterRegExp().pattern()
|
||||
#endif
|
||||
);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -123,9 +123,9 @@ void QtSettings::restore(QSettings &settings)
|
|||
void QtSettings::save(QSettings &settings) const
|
||||
{
|
||||
settings.beginGroup(QStringLiteral("qt"));
|
||||
settings.setValue(QStringLiteral("font"), m_d->font.toString());
|
||||
settings.setValue(QStringLiteral("font"), QVariant(m_d->font.toString()));
|
||||
settings.setValue(QStringLiteral("customfont"), m_d->customFont);
|
||||
settings.setValue(QStringLiteral("palette"), m_d->palette);
|
||||
settings.setValue(QStringLiteral("palette"), QVariant(m_d->palette));
|
||||
settings.setValue(QStringLiteral("custompalette"), m_d->customPalette);
|
||||
settings.setValue(QStringLiteral("widgetstyle"), m_d->widgetStyle);
|
||||
settings.setValue(QStringLiteral("customwidgetstyle"), m_d->customWidgetStyle);
|
||||
|
@ -137,7 +137,7 @@ void QtSettings::save(QSettings &settings) const
|
|||
settings.setValue(QStringLiteral("customlocale"), m_d->customLocale);
|
||||
settings.setValue(QStringLiteral("plugindir"), m_d->additionalPluginDirectory);
|
||||
settings.setValue(QStringLiteral("iconthemepath"), m_d->additionalIconThemeSearchPath);
|
||||
settings.setValue(QStringLiteral("trpath"), TranslationFiles::additionalTranslationFilePath());
|
||||
settings.setValue(QStringLiteral("trpath"), QVariant(TranslationFiles::additionalTranslationFilePath()));
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ void QtSettings::apply()
|
|||
}
|
||||
|
||||
// apply locale
|
||||
QLocale::setDefault(m_d->customLocale ? m_d->localeName : m_d->defaultLocale);
|
||||
QLocale::setDefault(m_d->customLocale ? QLocale(m_d->localeName) : m_d->defaultLocale);
|
||||
|
||||
// apply environment
|
||||
if (m_d->additionalPluginDirectory.isEmpty()) {
|
||||
|
|
Loading…
Reference in New Issue