Skip to content

Commit

Permalink
feat: adapt for Qt 6.8
Browse files Browse the repository at this point in the history
Adaptation work based on Qt 6.8, modified relevant
interfaces and configuration files.
  • Loading branch information
JWWTSL committed Jan 14, 2025
1 parent 2b2df40 commit 9868214
Show file tree
Hide file tree
Showing 48 changed files with 700 additions and 411 deletions.
50 changes: 30 additions & 20 deletions 3rdparty/core/evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QRegularExpression>
#include <QStack>
#include <QDebug>
#include <QRegularExpression>

#define ALLOW_IMPLICIT_MULT

Expand Down Expand Up @@ -687,15 +688,19 @@ bool Evaluator::isRadixChar(const QChar &ch)
// Helper function: return true for valid thousand separator characters.
bool Evaluator::isSeparatorChar(const QChar &ch)
{
// Match everything that is not alphanumeric or an operator or NUL.
static const QRegExp s_separatorRE(
"[^a-zA-Z0-9\\+\\-−\\*×⋅÷/\\^;\\(\\)%!=\\\\&\\|<>\\?#\\x0000]"
);

// 仅当字符不是 radix 字符时,才执行正则匹配
if (isRadixChar(ch))
return false;

return s_separatorRE.exactMatch(ch);
static const QRegularExpression s_separatorRE(
"[^a-zA-Z0-9\\+\\-−\\*×⋅÷/\\^;\\(\\)%!=\\\\&\\|<>\\?#\\x0000]"
);

// 使用 match() 方法来匹配单个字符
QRegularExpressionMatch match = s_separatorRE.match(QString(ch));

// 如果 match.hasMatch() 返回 true,说明该字符是分隔符
return match.hasMatch();
}

QString Evaluator::fixNumberRadix(const QString &number)
Expand Down Expand Up @@ -1588,8 +1593,10 @@ void Evaluator::compile(const Tokens &tokens)
case Token::BitwiseLogicalXOR:
m_codes.append(Opcode::BXor);
break;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
case Token::UnitConversion: {
static const QRegExp unitNameNumberRE(

static const QRegularExpression unitNameNumberRE(
"(^[0-9e\\+\\-\\.,]|[0-9e\\.,]$)",
Qt::CaseInsensitive);
QString unitName =
Expand All @@ -1607,6 +1614,7 @@ void Evaluator::compile(const Tokens &tokens)
m_codes.append(Opcode(Opcode::Conv, unitName));
break;
}
#endif
default: break;
};
syntaxStack.reduce(3);
Expand Down Expand Up @@ -2532,18 +2540,18 @@ static void replaceSuperscriptPowersWithCaretEquivalent(QString &expr)
"(\\x{207B})?[\\x{2070}¹²³\\x{2074}-\\x{2079}]+"
);
static const QHash<QChar, QChar> s_superscriptPowersHash {
{L'\u207B', '-'},
{L'\u2070', '0'},
{L'\u00B9', '1'},
{L'\u00B2', '2'},
{L'\u00B3', '3'},
{L'\u2074', '4'},
{L'\u2075', '5'},
{L'\u2076', '6'},
{L'\u2077', '7'},
{L'\u2078', '8'},
{L'\u2079', '9'},
};
{QChar(0x207B), '-'}, // Replace L'\u207B' with QChar(0x207B)
{QChar(0x2070), '0'},
{QChar(0x00B9), '1'},
{QChar(0x00B2), '2'},
{QChar(0x00B3), '3'},
{QChar(0x2074), '4'},
{QChar(0x2075), '5'},
{QChar(0x2076), '6'},
{QChar(0x2077), '7'},
{QChar(0x2078), '8'},
{QChar(0x2079), '9'},
};

int offset = 0;
while (true) {
Expand All @@ -2552,9 +2560,10 @@ static void replaceSuperscriptPowersWithCaretEquivalent(QString &expr)
break;

QString power = match.captured();
// Replace superscript characters with normal numbers/characters
for (int pos = power.size() - 1; pos >= 0; --pos) {
QChar c = power.at(pos);
power.replace(pos, 1, s_superscriptPowersHash.value(c, c));
power.replace(pos, 1, s_superscriptPowersHash.value(c, c)); // Replace using the hash
}

bool isNegative = match.capturedStart(1) != -1;
Expand All @@ -2563,6 +2572,7 @@ static void replaceSuperscriptPowersWithCaretEquivalent(QString &expr)
else
power = "^" + power;

// Replace the matched substring with the new expression
expr.replace(match.capturedStart(), match.capturedLength(), power);
offset = match.capturedStart() + power.size();
}
Expand Down
13 changes: 10 additions & 3 deletions 3rdparty/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,16 @@ void Settings::save()

char Settings::radixCharacter() const
{
if (isRadixCharacterAuto() || isRadixCharacterBoth())
return QLocale().decimalPoint().toLatin1();
if (isRadixCharacterAuto() || isRadixCharacterBoth()) {
QByteArray decimalPoint = QLocale().decimalPoint().toLatin1();

// 确保返回的是第一个字符,如果 QByteArray 为空,返回一个默认的字符(如'.')
if (!decimalPoint.isEmpty()) {
return decimalPoint.at(0); // 返回 QByteArray 中的第一个字符
} else {
return '.'; // 如果为空,返回默认的十进制分隔符
}
}

return s_radixCharacter;
}
Expand All @@ -309,7 +317,6 @@ void Settings::setRadixCharacter(char c)
s_radixCharacter = (c != ',' && c != '.' && c != '*') ? 0 : c;
}


// Settings migration from legacy (0.11 and before) to 0.12 (ConfigVersion 1200).
static void migrateSettings_legacyTo1200(QSettings *settings, const QString &KEY)
{
Expand Down
3 changes: 2 additions & 1 deletion 3rdparty/math/hmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <QRegularExpression>

#define RATIONAL_TOL HNumber("1e-20")

Expand Down Expand Up @@ -892,7 +893,7 @@ char *formatGeneral(cfloatnum x, int prec, int base = 10)

//edit 20200509 当出现循环小数时,位数由于小于科学计数法的临界值,format后进位,导致0.999...变成1e0
QString strnew = QString(QLatin1String(str));
strnew.remove(QRegExp("[^0-9E]"));
strnew.remove(QRegularExpression("[^0-9E]"));
int e = strnew.indexOf("E");
if (e > 0) {
if (strnew.left(e).length() + (strnew.right(strnew.length() - e - 1)).toInt() < prec + 2)
Expand Down
12 changes: 12 additions & 0 deletions 3rdparty/math/rational.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,15 @@ double Rational::toDouble() const
{
return double(m_num) / m_denom;
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
unsigned int qHash(const Rational& key)
{
return qHash(key.numerator()) ^ qHash(key.denominator());
}
#else
size_t qHash(const Rational& key, size_t seed) noexcept
{
return qHash(key.numerator(), seed) ^ qHash(key.denominator(), seed);
}
#endif
9 changes: 9 additions & 0 deletions 3rdparty/math/rational.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#ifndef RATIONAL_H
#define RATIONAL_H

#include <QtGlobal>
#include <cstddef>

class HNumber;
class QString;

Expand Down Expand Up @@ -64,4 +67,10 @@ class Rational
double toDouble() const;
};

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
unsigned int qHash(const Rational& key);
#else
size_t qHash(const Rational& key, size_t seed = 0) noexcept;
#endif

#endif // RATIONAL_H
12 changes: 0 additions & 12 deletions 3rdparty/math/units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ void Units::pushUnit(Quantity q, QString name)
m_matchLookup.insert(q.getDimension(), u);
}

unsigned int qHash(QMap<QString, Rational> dimension)
{
QStringList keyList(dimension.keys());
QString blob("");
keyList.sort();
for (int i = 0; i < keyList.size(); ++i) {
keyList[i].append(dimension[keyList[i]].toString());
blob.append(keyList[i]);
}
return qHash(blob);
}

/*
* initialize the lookup table for automatic matching
*/
Expand Down
94 changes: 65 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.9.5)
cmake_minimum_required(VERSION 3.16.0)

if (NOT DEFINED VERSION)
set(VERSION 1.2.2)
Expand All @@ -11,14 +11,30 @@ include(GNUInstallDirs)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wl,--as-needed -fPIE")
set(QT_MINIMUM_VERSION "5.7.1")
set(QT_MINIMUM_VERSION "6.0.0")
set(CMAKE_EXE_LINKER_FLAGS "-pie")


# Find the Qt library
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
message("Using Qt version: ${QT_VERSION_MAJOR}")

#qt5
#find_package(Qt5 COMPONENTS Core REQUIRED)
# Select major DTK version.
if(QT_VERSION_MAJOR EQUAL "6")
set(BUILD_WITH_QT6 ON)
set(DTK_VERSION_MAJOR 6)
else()
set(DTK_VERSION_MAJOR "")
endif()
message("Using dtk version: ${DTK_VERSION_MAJOR}")

#add_definitions(-DQT_NO_DEBUG_OUTPUT)

if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "sw_64")
Expand Down Expand Up @@ -52,37 +68,56 @@ configure_file(src/environments.h.in environments.h @ONLY)

# Find the library
find_package(PkgConfig REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5DBus REQUIRED)
find_package(Qt5Xml REQUIRED)
find_package(Qt5Svg REQUIRED)
find_package(Qt5Test REQUIRED)

pkg_search_module(DtkWidget REQUIRED dtkwidget)
pkg_search_module(DtkGui REQUIRED dtkgui)
pkg_search_module(DtkCore REQUIRED dtkcore)
find_package(Qt6 REQUIRED COMPONENTS Widgets Core Gui DBus Xml Svg Test)

#qt5
#find_package(Qt5 REQUIRED COMPONENTS Widgets Core Gui DBus Xml Svg Test)

# 替换 pkg_search_module 为 find_package
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Widget Gui Core)

include_directories(${DtkWidget_INCLUDE_DIRS})
include_directories(${DtkGui_INCLUDE_DIRS})
include_directories(${DtkCore_INCLUDE_DIRS})

message(STATUS "DtkGui Include Directories111: ${DtkGui_INCLUDE_DIRS}")
message(STATUS "DtkCore Include Directories11: ${DtkCore_INCLUDE_DIRS}")
message(STATUS "DtkWidget Include Directories111: ${DtkWidget_INCLUDE_DIRS}")

set (EXE_NAME deepin-calculator)

set(LINK_LIBS
if (Qt6_FOUND)
# Qt6 environment
set(LINK_LIBS
Qt6::Core
Qt6::DBus
Qt6::Widgets
Qt6::Xml
Qt6::Svg
Qt6::Test

Dtk${DTK_VERSION_MAJOR}::Widget
Dtk${DTK_VERSION_MAJOR}::Gui
Dtk${DTK_VERSION_MAJOR}::Core
${DFrameworkDBus_LIBRARIES}
)
else()
# Qt5 environment
set(LINK_LIBS
Qt5::Core
Qt5::DBus
Qt5::Widgets
Qt5::Xml
Qt5::Svg
Qt5::Test

${DtkWidget_LIBRARIES}
${DtkCore_LIBRARIES}
${DtkGUI_LIBRARIES}
Dtk${DTK_VERSION_MAJOR}::Widget
Dtk${DTK_VERSION_MAJOR}::Gui
Dtk${DTK_VERSION_MAJOR}::Core
${DFrameworkDBus_LIBRARIES}
)
endif()


file(GLOB_RECURSE CAL_SRCH ${CMAKE_CURRENT_LIST_DIR}/src/*.h)
file(GLOB_RECURSE CAL_SRCC ${CMAKE_CURRENT_LIST_DIR}/src/*.c)
Expand All @@ -105,13 +140,13 @@ add_executable (${EXE_NAME}
${DC_QRC_FILES}
)

target_include_directories(${EXE_NAME} PUBLIC ${Qt5Widgets_LIBRARIES}
${Qt5DBus_LIBRARIES}
${Qt5TestLib_LIBRARIES}
target_include_directories(${EXE_NAME} PUBLIC ${Qt6Widgets_LIBRARIES}
${Qt6DBus_LIBRARIES}
${Qt6TestLib_LIBRARIES}
${PROJECT_BINARY_DIR}
${DtkWidget_INCLUDE_DIRS}
${DtkCore_LIBRARIES}
${DtkGUI_INCLUDE_DIRS}
${DtkGui_INCLUDE_DIRS}
${DFrameworkDBus_INCLUDE_DIRS})

target_link_libraries (${EXE_NAME} ${LINK_LIBS})
Expand All @@ -131,17 +166,18 @@ install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/src/assets/deepin-calculator
DESTINATION ${CMAKE_INSTALL_DATADIR}/deepin-manual/manual-assets/application/)

#if (NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
option (BUILD_TESTING "" ON)
if (BUILD_TESTING)
add_subdirectory(tests) #tests为ut测试文件夹名
endif ()
endif ()
# 禁用测试
# if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# option (BUILD_TESTING "" ON)
# if (BUILD_TESTING)
# add_subdirectory(tests) #tests为ut测试文件夹名
# endif ()
# endif ()
#endif ()


#代码覆盖率开关
if(CMAKE_COVERAGE_ARG STREQUAL "CMAKE_COVERAGE_ARG_ON")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -fprofile-arcs -ftest-coverage")
endif()

2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Source: deepin-calculator
Section: utils
Priority: optional
Maintainer: Deepin Packages Builder <[email protected]>
Build-Depends: debhelper (>= 9),cmake ,pkg-config, libdtkgui-dev, libdtkwidget-dev, libqt5svg5-dev, qttools5-dev-tools, libgtest-dev, libgmock-dev
Build-Depends: debhelper (>= 9),cmake ,pkg-config, libdtk6gui-dev, libdtk6widget-dev, qt6-svg-dev,qt6-tools-dev-tools, libgtest-dev, libgmock-dev
Standards-Version: 3.9.8
Homepage: http://www.deepin.org

Expand Down
6 changes: 5 additions & 1 deletion debian/rules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/make -f

export QT_SELECT=5
export QT_SELECT=qt6
include /usr/share/dpkg/default.mk

DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
Expand All @@ -16,5 +16,9 @@ export DH_VERBOSE=1
override_dh_auto_configure:
dh_auto_configure -- \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DCMAKE_SAFETYTEST_ARG="CMAKE_SAFETYTEST_ARG_OFF" \
-DAPP_VERSION=$(DEB_VERSION_UPSTREAM) -DVERSION=$(DEB_VERSION_UPSTREAM) LIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH)

override_dh_auto_test:
override_dh_shlibdeps: --dpkg-shlibdeps-params=--ignore-missing-info
Loading

0 comments on commit 9868214

Please sign in to comment.