From 2af6b1b3ba169e8dde66b3727780c038e6e3908c Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Mon, 6 Jan 2025 17:58:25 +0800 Subject: [PATCH] feat: QT6 adaptation QT6 adaptation Log: QT6 adaptation --- CMakeLists.txt | 13 ++++-- debian/control | 18 ++++---- src/include/ui/queryurl.h | 3 +- src/src/aria2/CMakeLists.txt | 4 +- src/src/aria2/aria2rpcinterface.cpp | 48 ++++++++++++++++++++- src/src/database/CMakeLists.txt | 4 +- src/src/database/database.cpp | 2 +- src/src/downloader/CMakeLists.txt | 2 +- src/src/downloader/main.cpp | 11 +++++ src/src/extensionService/CMakeLists.txt | 14 +++++- src/src/log/CMakeLists.txt | 2 +- src/src/log/log.cpp | 8 ++-- src/src/ui/CMakeLists.txt | 20 ++++----- src/src/ui/createTask/btheaderview.cpp | 2 +- src/src/ui/createTask/btinfodialog.cpp | 10 +++-- src/src/ui/createTask/createtaskwidget.cpp | 18 ++++++++ src/src/ui/createTask/taskModel.cpp | 3 +- src/src/ui/createTask/taskdelegate.cpp | 5 +++ src/src/ui/func.cpp | 9 +++- src/src/ui/mainFrame/itemDelegate.cpp | 17 ++++++++ src/src/ui/mainFrame/mainframe.cpp | 46 +++++++++++++++++--- src/src/ui/mainFrame/tableModel.cpp | 13 ++++++ src/src/ui/mainFrame/tableView.cpp | 11 +++++ src/src/ui/mainFrame/tabledatacontrol.cpp | 8 ++++ src/src/ui/settings/diagnostictool.cpp | 39 +++++++++++++++++ src/src/ui/settings/filesavepathchooser.cpp | 4 ++ src/src/ui/settings/settings.cpp | 2 + src/src/ui/settings/settingswidget.cpp | 6 +++ src/src/ui/settings/timeEdit.cpp | 11 +++++ tests/CMakeLists.txt | 15 ++++++- tests/ui/mainFrame/ut_mainframe.cpp | 5 --- tests/ui/settings/ut_settings.cpp | 4 ++ translate_generation.sh | 2 +- 33 files changed, 321 insertions(+), 58 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf222a73..ab7fd590 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,13 +69,18 @@ set(CMAKE_AUTORCC ON) #打开全局uic set(CMAKE_AUTOUIC ON) +set(QT_VERSION_MAJOR 6) +if (${QT_VERSION_MAJOR} GREATER_EQUAL 6) + set(DTK_VERSION 6) +endif() + set(QT Core Gui Widgets Network DBus Sql LinguistTools Svg Test WebChannel WebSockets) -find_package(Qt5 COMPONENTS ${QT} REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${QT} REQUIRED) #应用DTK库 -find_package(DtkWidget REQUIRED) -find_package(DtkCore REQUIRED) -find_package(DtkGui REQUIRED) +find_package(Dtk${DTK_VERSION}Widget REQUIRED) +find_package(Dtk${DTK_VERSION}Core REQUIRED) +find_package(Dtk${DTK_VERSION}Gui REQUIRED) #安装 # qm files. diff --git a/debian/control b/debian/control index 30db687d..eb8d2ab0 100644 --- a/debian/control +++ b/debian/control @@ -6,14 +6,16 @@ Build-Depends: debhelper (>= 12), cmake, pkg-config, - libqt5widgets5, - qtbase5-dev, - qttools5-dev, - libqt5network5, - libqt5webchannel5-dev, - libqt5websockets5-dev, - libdtkwidget-dev, - libdtkgui-dev, + libqt6widgets6, + qt6-base-dev, + qt6-tools-dev, + qt6-svg-dev, + qt6-l10n-tools, + libqt6network6, + qt6-webchannel-dev, + qt6-websockets-dev, + libdtk6widget-dev, + libdtk6gui-dev, libdframeworkdbus-dev, libgtest-dev, libgmock-dev, diff --git a/src/include/ui/queryurl.h b/src/include/ui/queryurl.h index 96b84135..dea698ce 100644 --- a/src/include/ui/queryurl.h +++ b/src/include/ui/queryurl.h @@ -12,7 +12,8 @@ class QueryUrl : public QObject Q_OBJECT public: - explicit QueryUrl(QObject *parent = nullptr); + explicit QueryUrl(QObject *parent = nullptr) + {}; private: }; diff --git a/src/src/aria2/CMakeLists.txt b/src/src/aria2/CMakeLists.txt index 2bbd44f2..6f5038c3 100644 --- a/src/src/aria2/CMakeLists.txt +++ b/src/src/aria2/CMakeLists.txt @@ -19,7 +19,7 @@ set (DWM_ARIA_HEADERS ) #需要生成的moc文件,输出文件名称放在变量 mocfiles中,必须在find QT5 package才能调用 -QT5_WRAP_CPP (DWM_ARIA_HEADERS_MOC ${DWM_ARIA_HEADERS}) +qt_wrap_cpp (DWM_ARIA_HEADERS_MOC ${DWM_ARIA_HEADERS}) #设置输出dll的名称、类型(动态库、静态库)及所用到的文件 add_library(dlmaria2 SHARED @@ -28,7 +28,7 @@ add_library(dlmaria2 SHARED ${DWM_ARIA_HEADERS_MOC} ) -target_link_libraries(dlmaria2 dlmlog Qt5::Core) +target_link_libraries(dlmaria2 dlmlog Qt${QT_VERSION_MAJOR}::Core) #install(TARGETS dlmaria2 DESTINATION lib) diff --git a/src/src/aria2/aria2rpcinterface.cpp b/src/src/aria2/aria2rpcinterface.cpp index d7192802..10042642 100644 --- a/src/src/aria2/aria2rpcinterface.cpp +++ b/src/src/aria2/aria2rpcinterface.cpp @@ -95,6 +95,51 @@ bool Aria2RPCInterface::startUp() //QProcess::execute("touch", QStringList() << dhtFile); //创建dht文件 //QProcess::execute("touch", QStringList() << dht6File); //创建dht6文件 +#if QT_VERSION_MAJOR > 5 + QStringList opt; + opt += "--enable-rpc=true"; //启动RPC + opt += "--rpc-secret=" + getToken(); + opt += "--rpc-listen-port=" + this->m_rpcPort; //RPC监听的端口 + opt += "--check-certificate=false"; //停用rpc身份验证 + opt += "--rpc-allow-origin-all=true"; // 允许所有来源 + opt += "--rpc-max-request-size=99999999"; //设置rpc最大接收数 + opt += "--rpc-save-upload-metadata=true"; // + + //opt += "--not-conf=true";//不使用配置文件 + if (!this->m_configPath.isEmpty()) { + opt += "--conf-path=" + this->m_configPath; //加载指定的配置文件 + } + if (!this->m_defaultDownloadPath.isEmpty()) { + opt += "--dir=" + this->m_defaultDownloadPath; //配置默认下载路径。优先级高于配置文件,已移动到配置文件中 + } + opt += "--continue=true"; //http续传配置 + opt += "--disable-ipv6"; //禁用ipv6 + //opt += "--seed-time=0";//bt完成不做种 + opt += "--bt-metadata-only=true"; //仅下载bt metadata,不自动发起follow下载 + opt += "--bt-save-metadata=true"; //保存magnet metadata到同目录下.torrent文件 + opt += "--follow-torrent=false"; //当下载的文件是以.torrent结尾的,是否继续下载。true,是;false,否,只下载torrent文件;mem,不写文件保存在内存 + //opt += "--follow-metalink=false";//类似torrent + opt += "--bt-remove-unselected-file=true"; + //opt += "--input-file=" + inputFile; + opt += "--save-session=" + sessionCacheFile; + opt += "--save-session-interval=" + saveSessionInterval; + opt += "--enable-dht=true"; //启动dht文件 + opt += "--enable-dht6=false"; //禁用dht6文件 + opt += "--dht-file-path=" + dhtFile; + opt += "--dht-file-path6=" + dht6File; + opt += "--follow-metalink=false"; + if(QSysInfo::currentCpuArchitecture() == "loongarch64"){ + opt += "--async-dns=false"; + } + + QProcess proc; // = new QProcess; + proc.setStandardOutputFile("/dev/null"); + proc.setStandardErrorFile("/dev/null"); + proc.setProgram(m_basePath + m_aria2cCmd); + proc.setArguments(opt); + proc.startDetached(); + proc.waitForStarted(); +#else QString opt; opt += " --enable-rpc=true"; //启动RPC opt += " --rpc-secret=" + getToken(); @@ -131,13 +176,14 @@ bool Aria2RPCInterface::startUp() opt += " --async-dns=false"; } - // qDebug() << m_basePath + m_aria2cCmd << opt.join(' '); + // qDebug() << m_basePath + m_aria2cCmd << opt.join(' '); QProcess proc; // = new QProcess; proc.setStandardOutputFile("/dev/null"); proc.setStandardErrorFile("/dev/null"); proc.startDetached("sh -c \"" + m_basePath + m_aria2cCmd + " " + opt + "\""); proc.waitForStarted(); +#endif // proc.start("ulimit -n 40"); // bool b = proc.waitForFinished(); diff --git a/src/src/database/CMakeLists.txt b/src/src/database/CMakeLists.txt index d0b41bb9..5d4ac9a9 100644 --- a/src/src/database/CMakeLists.txt +++ b/src/src/database/CMakeLists.txt @@ -17,7 +17,7 @@ set (DWM_DATABASE_HEADERS ) #需要生成的moc文件,输出文件名称放在变量 mocfiles中,必须在find QT5 package才能调用 -QT5_WRAP_CPP (DWM_DATABASE_HEADERS_MOC ${DWM_DATABASE_HEADERS}) +qt_wrap_cpp (DWM_DATABASE_HEADERS_MOC ${DWM_DATABASE_HEADERS}) #设置输出dll的名称、类型(动态库、静态库)及所用到的文件 add_library(dlmdatabase SHARED @@ -26,6 +26,6 @@ add_library(dlmdatabase SHARED ${DWM_DATABASE_HEADERS_MOC} ) -target_link_libraries(dlmdatabase dlmlog Qt5::Core Qt5::Widgets Qt5::Sql) +target_link_libraries(dlmdatabase dlmlog Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Sql) #install(TARGETS dlmdatabase DESTINATION lib) diff --git a/src/src/database/database.cpp b/src/src/database/database.cpp index 2f937ceb..614482fb 100644 --- a/src/src/database/database.cpp +++ b/src/src/database/database.cpp @@ -18,7 +18,7 @@ DataBase::DataBase() //如果数据库文件不存在 if (!databaseFile.isFile()) { //拷贝数据库文件 - qDebug() << "error: no db file "; //<< QString(UOS_DONWLOAD_DATABASE_PATH) + UOS_DOWNLOAD_DATABASE_FILENAME << QString(_dataBasePath) + UOS_DOWNLOAD_DATABASE_FILENAME << endl; + qDebug() << "error: no db file "; //<< QString(UOS_DONWLOAD_DATABASE_PATH) + UOS_DOWNLOAD_DATABASE_FILENAME << QString(_dataBasePath) + UOS_DOWNLOAD_DATABASE_FILENAME << Qt::endl; QFile::copy(QString(UOS_DONWLOAD_DATABASE_PATH) + UOS_DOWNLOAD_DATABASE_OLD_FILENAME, dbPath); QString strold = UOS_DONWLOAD_DATABASE_PATH + "downloader.db"; diff --git a/src/src/downloader/CMakeLists.txt b/src/src/downloader/CMakeLists.txt index ad65317a..2b0134f0 100644 --- a/src/src/downloader/CMakeLists.txt +++ b/src/src/downloader/CMakeLists.txt @@ -23,7 +23,7 @@ add_executable(downloader main.cpp accessiblewidget.cpp ) -target_link_libraries(downloader dlmcontrolui dlmlog Qt5::Core) +target_link_libraries(downloader dlmcontrolui dlmlog Qt${QT_VERSION_MAJOR}::Core) #INSTALL(TARGETS downloader DESTINATION share/downloader) #install(TARGETS downloader DESTINATION bin) diff --git a/src/src/downloader/main.cpp b/src/src/downloader/main.cpp index 934205e7..ee4910ef 100644 --- a/src/src/downloader/main.cpp +++ b/src/src/downloader/main.cpp @@ -30,10 +30,13 @@ */ #include +#include #include #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include #include @@ -70,9 +73,11 @@ int main(int argc, char *argv[]) auto e = QProcessEnvironment::systemEnvironment(); QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE")); +#if QT_VERSION_MAJOR <= 5 if (XDG_SESSION_TYPE == QLatin1String("x11")) { DlmApplication::loadDXcbPlugin(); } +#endif QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); DlmApplication a(argc, argv); a.setQuitOnLastWindowClosed(false); @@ -134,9 +139,11 @@ int main(int argc, char *argv[]) char *to = static_cast(sharedMemory.data()); memset(to, 0, 199); } +#if QT_VERSION_MAJOR <= 5 // 保存程序的窗口主题设置 DApplicationSettings as; Q_UNUSED(as) +#endif QDir dirCheck; QString LogPath = QString("%1/%2/%3/Log/") .arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)) @@ -205,8 +212,12 @@ bool checkProcessExist() { QProcess process; QStringList list; +#if QT_VERSION_MAJOR > 5 + process.start("pgrep", {"downloader"}); +#else process.start("pgrep downloader"); process.start(); +#endif process.waitForStarted(1000); process.waitForFinished(1000); QString str = process.readAll(); diff --git a/src/src/extensionService/CMakeLists.txt b/src/src/extensionService/CMakeLists.txt index bf0e09eb..a9002112 100644 --- a/src/src/extensionService/CMakeLists.txt +++ b/src/src/extensionService/CMakeLists.txt @@ -18,7 +18,7 @@ set (DWM_EXTENSIONSERVICE_HEADERS ) #需要生成的moc文件,输出文件名称放在变量 mocfiles中,必须在find QT5 package才能调用 -QT5_WRAP_CPP (DWM_EXTENSIONSERVICE_HEADERS_MOC ${DWM_EXTENSIONSERVICE_HEADERS}) +qt_wrap_cpp (DWM_EXTENSIONSERVICE_HEADERS_MOC ${DWM_EXTENSIONSERVICE_HEADERS}) #设置输出dll的名称、类型(动态库、静态库)及所用到的文件 add_executable(dlmextensionservice @@ -30,6 +30,16 @@ add_executable(dlmextensionservice ${DWM_EXTENSIONSERVICE_HEADERS_MOC} ) -target_link_libraries(dlmextensionservice Qt5::Core Qt5::Widgets Qt5::WebChannel Qt5::WebSockets Qt5::Network Qt5::DBus dtkcore dtkwidget ) +target_link_libraries(dlmextensionservice + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::WebChannel + Qt${QT_VERSION_MAJOR}::WebSockets + Qt${QT_VERSION_MAJOR}::Network + Qt${QT_VERSION_MAJOR}::DBus + Dtk${DTK_VERSION}::Core + Dtk${DTK_VERSION}::Gui + Dtk${DTK_VERSION}::Widget +) install(TARGETS dlmextensionservice DESTINATION bin) diff --git a/src/src/log/CMakeLists.txt b/src/src/log/CMakeLists.txt index 126d0b71..024cb189 100644 --- a/src/src/log/CMakeLists.txt +++ b/src/src/log/CMakeLists.txt @@ -12,6 +12,6 @@ ADD_DEFINITIONS(-DLM_LOG_LIB ) add_library(dlmlog SHARED log.cpp ) -target_link_libraries(dlmlog Qt5::Core) +target_link_libraries(dlmlog Qt${QT_VERSION_MAJOR}::Core) #install(TARGETS dlmlog DESTINATION lib) diff --git a/src/src/log/log.cpp b/src/src/log/log.cpp index 9b97b848..ca08a786 100644 --- a/src/src/log/log.cpp +++ b/src/src/log/log.cpp @@ -72,7 +72,7 @@ void CheckLogTime() auto logList = GetLogList(); for (int i = 0; i < logList.size() - 1; ++i) { auto logInfo = logList[i]; - auto createdTime = logInfo.created(); + auto createdTime = logInfo.birthTime(); auto elapseDays = createdTime.daysTo(curTime); if (elapseDays > _logDaysRemain) { auto logPath = logInfo.absoluteFilePath(); @@ -120,7 +120,7 @@ bool CheckRotateSize() bool CheckRotateTimePoint() { QFileInfo curLogInfo(_logFile); - auto curLogCreateDate = curLogInfo.created(); + auto curLogCreateDate = curLogInfo.birthTime(); auto curDate = QDateTime::currentDateTime(); auto dayElapse = curLogCreateDate.daysTo(curDate); if (dayElapse >= 1) { @@ -152,7 +152,7 @@ void WriteVersion() QTextStream ts(&outFile); auto appName = QCoreApplication::applicationName(); auto version = QCoreApplication::applicationVersion(); - ts << appName << " " << version << endl; + ts << appName << " " << version << Qt::endl; outFile.close(); s_logMutex.unlock(); } @@ -207,7 +207,7 @@ void customLogMessageHandler(QtMsgType type, const QMessageLogContext &ctx, cons return; } QTextStream ts(&outFile); - ts << message.toUtf8() << endl; + ts << message.toUtf8() << Qt::endl; std::cout << msg.toStdString() << std::endl; outFile.close(); s_logMutex.unlock(); diff --git a/src/src/ui/CMakeLists.txt b/src/src/ui/CMakeLists.txt index 5e84f9e0..0f0184af 100644 --- a/src/src/ui/CMakeLists.txt +++ b/src/src/ui/CMakeLists.txt @@ -79,11 +79,11 @@ set (UDLC_UI_HEADERS #需要生成的moc文件,输出文件名称放在变量 mocfiles中,必须在find QT5 package才能调用 -QT5_WRAP_CPP (UDLC_UI_HEADERS_MOC ${UDLC_UI_HEADERS}) +qt_wrap_cpp (UDLC_UI_HEADERS_MOC ${UDLC_UI_HEADERS}) #添加资源文件 set(QRC_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/resource/resource.qrc) -qt5_add_resources(QRC_FILES ${QRC_SOURCE_FILES}) +qt_add_resources(QRC_FILES ${QRC_SOURCE_FILES}) #设置输出dll的名称、类型(动态库、静态库)及所用到的文件 add_library(dlmcontrolui SHARED @@ -129,14 +129,14 @@ target_link_libraries(dlmcontrolui dlmlog dlmaria2 dlmdatabase - ${DtkCore_LIBRARIES} - ${DtkWidget_LIBRARIES} - ${DtkGui_LIBRARIES} - Qt5::Core - Qt5::Network - Qt5::Widgets - Qt5::Svg - Qt5::DBus + Dtk${DTK_VERSION}::Core + Dtk${DTK_VERSION}::Gui + Dtk${DTK_VERSION}::Widget + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Network + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Svg + Qt${QT_VERSION_MAJOR}::DBus ) #install(TARGETS dlmcontrolui DESTINATION lib) diff --git a/src/src/ui/createTask/btheaderview.cpp b/src/src/ui/createTask/btheaderview.cpp index a2e27f6d..194482ac 100644 --- a/src/src/ui/createTask/btheaderview.cpp +++ b/src/src/ui/createTask/btheaderview.cpp @@ -94,7 +94,7 @@ void headerView::onPalettetypechanged(DGuiApplicationHelper::ColorType type) // p.setColor(QPalette::Base, QColor(0,0,0,20)); QColor c = DGuiApplicationHelper::instance()->applicationPalette().base().color(); c.setAlpha(70); - p.setColor(DPalette::Background, c); + p.setColor(DPalette::Window, c); //p.setColor(QPalette::Base, DGuiApplicationHelper::instance()->applicationPalette().base().color()); } setPalette(p); diff --git a/src/src/ui/createTask/btinfodialog.cpp b/src/src/ui/createTask/btinfodialog.cpp index 87bf9016..fd6af0bc 100644 --- a/src/src/ui/createTask/btinfodialog.cpp +++ b/src/src/ui/createTask/btinfodialog.cpp @@ -233,7 +233,11 @@ void BtInfoDialog::initUI() QString str = getFileEditText(m_defaultDownloadDir); m_editDir->setText(str); m_editDir->setClearButtonEnabled(false); +#if QT_VERSION_MAJOR > 5 + m_editDir->setFileMode(QFileDialog::Directory); +#else m_editDir->setFileMode(QFileDialog::DirectoryOnly); +#endif m_editDir->lineEdit()->setEnabled(false); connect(m_editDir, &DFileChooserEdit::fileChoosed, this, &BtInfoDialog::onFilechoosed); QList btnList = m_editDir->findChildren(); @@ -631,7 +635,7 @@ void BtInfoDialog::onPaletteTypeChanged(DGuiApplicationHelper::ColorType type) m_delegate->setHoverColor(DGuiApplicationHelper::instance()->applicationPalette().frameBorder()); if (themeType == 1) { - p.setColor(QPalette::Background, Qt::white); + p.setColor(QPalette::Window, Qt::white); m_delegate->setHoverColor(QColor(0, 0, 0, 13)); QPalette pal; @@ -665,7 +669,7 @@ QString BtInfoDialog::getFileEditText(QString text) for (int i = 0; i < flieEditText.size(); i++) { //判断字符中是否包含中文或者大写字母 if ((flieEditText[i] >= 'A' && flieEditText[i] <= 'Z') - || (flieEditText[i] >= 0x4E00 && flieEditText[i] <= 0x9FA5)) { + || (flieEditText[i] >= QChar(0x4E00) && flieEditText[i] <= QChar(0x9FA5))) { count++; } } @@ -675,7 +679,7 @@ QString BtInfoDialog::getFileEditText(QString text) for (int i = 0; i < text.size(); i++) { //判断字符中是否包含中文或者大写字母 if ((text[i] >= 'A' && text[i] <= 'Z') - || (text[i] >= 0x4E00 && text[i] <= 0x9FA5)) { + || (text[i] >= QChar(0x4E00) && text[i] <= QChar(0x9FA5))) { hasLongStr++; } } diff --git a/src/src/ui/createTask/createtaskwidget.cpp b/src/src/ui/createTask/createtaskwidget.cpp index fead94fc..60815762 100644 --- a/src/src/ui/createTask/createtaskwidget.cpp +++ b/src/src/ui/createTask/createtaskwidget.cpp @@ -42,7 +42,11 @@ #include #include #include +#if QT_VERSION_MAJOR <= 5 #include +#else +#include +#endif #include #include "btinfodialog.h" #include "messagebox.h" @@ -301,7 +305,11 @@ void CreateTaskWidget::initUi() m_editDir->lineEdit()->setTextMargins(0, 0, m_editDir->lineEdit()->width(), 0); m_editDir->lineEdit()->setLayout(siezhlyt); m_editDir->setFont(font); +#if QT_VERSION_MAJOR > 5 + m_editDir->setFileMode(QFileDialog::Directory); +#else m_editDir->setFileMode(QFileDialog::FileMode::DirectoryOnly); +#endif connect(m_editDir, &DFileChooserEdit::fileChoosed, this, &CreateTaskWidget::onFilechoosed); m_editDir->setDirectoryUrl(QUrl(m_defaultDownloadDir)); @@ -333,7 +341,9 @@ void CreateTaskWidget::initUi() QWidget *boxBtn = new QWidget(this); QHBoxLayout *layout = new QHBoxLayout(boxBtn); +#if QT_VERSION_MAJOR <= 5 layout->setMargin(0); +#endif layout->setContentsMargins(0, 0, 0, 0); DIconButton *iconBtn = new DIconButton(boxBtn); iconBtn->setAccessibleName("bticonBtn"); @@ -977,7 +987,11 @@ void CreateTaskWidget::getUrlToName(QString url, QString &name, QString &type) } name = QString(url).right(url.length() - url.lastIndexOf('/') - 1); // 对url进行转码 +#if QT_VERSION_MAJOR > 5 + if (!name.contains(QRegularExpression("[\\x4e00-\\x9fa5]+"))) { +#else if (!name.contains(QRegExp("[\\x4e00-\\x9fa5]+"))) { +#endif const QByteArray byte = name.toLatin1(); QString decode = QUrl::fromPercentEncoding(byte); if (decode.contains("?")) { @@ -1013,7 +1027,11 @@ void CreateTaskWidget::setData(int index, QString name, QString type, QString si QString str = m_model->data(m_model->index(index, 1),1).toString(); //获取不到名称就加默认名称 if(!str.size() && !size.isEmpty() && !type.isEmpty()){ +#if QT_VERSION_MAJOR > 5 + QElapsedTimer t; +#else QTime t; +#endif t.start(); while(t.elapsed()<10); QDateTime dateTime = QDateTime::currentDateTime(); diff --git a/src/src/ui/createTask/taskModel.cpp b/src/src/ui/createTask/taskModel.cpp index edaba6db..6881b9b1 100644 --- a/src/src/ui/createTask/taskModel.cpp +++ b/src/src/ui/createTask/taskModel.cpp @@ -203,7 +203,8 @@ bool TaskModel::removeRow(int position, const QModelIndex &index) Q_UNUSED(index); beginRemoveRows(QModelIndex(), position, position); - m_linkInfo.removeAt(position); + if (m_linkInfo.size() > position) + m_linkInfo.removeAt(position); endRemoveRows(); return true; diff --git a/src/src/ui/createTask/taskdelegate.cpp b/src/src/ui/createTask/taskdelegate.cpp index 4f5fee58..05955a3d 100644 --- a/src/src/ui/createTask/taskdelegate.cpp +++ b/src/src/ui/createTask/taskdelegate.cpp @@ -192,8 +192,13 @@ QWidget *TaskDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem return nullptr; } DLineEdit *pEdit = new DLineEdit(parent); +#if QT_VERSION_MAJOR > 5 + QRegularExpression regx("[^\\\\/\':\\*\\?\"<>|#%?]+"); + QValidator *validator = new QRegularExpressionValidator(regx, pEdit); +#else QRegExp regx("[^\\\\/\':\\*\\?\"<>|#%?]+"); //屏蔽特殊字符 QValidator *validator = new QRegExpValidator(regx, pEdit); +#endif pEdit->lineEdit()->setValidator(validator); pEdit->lineEdit()->setMaxLength(83); connect(pEdit, &DLineEdit::textChanged, this, [=](QString filename) { diff --git a/src/src/ui/func.cpp b/src/src/ui/func.cpp index 7e42422e..426da742 100644 --- a/src/src/ui/func.cpp +++ b/src/src/ui/func.cpp @@ -11,6 +11,9 @@ #include #include #include +#if QT_VERSION_MAJOR > 5 +#include +#endif bool Func::isNetConnect() { @@ -120,7 +123,7 @@ bool Func::setMimeappsValue(QString key, QString value) QTextStream writeData(&writerFile); for (int i = 0; i < DefaultList.size(); i++) { - writeData << DefaultList[i] << endl; + writeData << DefaultList[i] << Qt::endl; } writeData.flush(); writerFile.close(); @@ -257,7 +260,11 @@ QString Func::chineseToPinyin(QString input) QString value = input; for(int i = input.size() - 1; i >= 0; i--) { QString ch = input.at(i); +#if QT_VERSION_MAJOR > 5 + if (ch.contains(QRegularExpression("[\\x4e00-\\x9fa5]+"))) { +#else if(ch.contains(QRegExp("[\\x4e00-\\x9fa5]+"))){ +#endif QString pinyin = removeDigital(DTK_NAMESPACE::Core::Chinese2Pinyin(ch)); value.replace(ch, pinyin); } diff --git a/src/src/ui/mainFrame/itemDelegate.cpp b/src/src/ui/mainFrame/itemDelegate.cpp index b39aa431..a7746f45 100644 --- a/src/src/ui/mainFrame/itemDelegate.cpp +++ b/src/src/ui/mainFrame/itemDelegate.cpp @@ -120,7 +120,11 @@ void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, if (isSelected) { painter->setPen(Dtk::Gui::DGuiApplicationHelper::instance()->applicationPalette().highlight().color()); painter->setBrush(QBrush(Dtk::Gui::DGuiApplicationHelper::instance()->applicationPalette().highlight())); +#if QT_VERSION_MAJOR > 5 + painter->drawRoundedRect(rect.x(), rect.y(), 25, rect.height(), 25, 25); +#else painter->drawRoundRect(rect.x(), rect.y(), 25, rect.height(), 25, 25); +#endif painter->drawRect(rect.x() + 15, rect.y(), rect.width() - 15, rect.height()); painter->setPen(QColor("#FFFFFF")); QItemEditorFactory::setDefaultFactory(new QItemEditorFactory); @@ -172,7 +176,11 @@ void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, if (isSelected) { painter->setPen(Dtk::Gui::DGuiApplicationHelper::instance()->applicationPalette().highlight().color()); painter->setBrush(Dtk::Gui::DGuiApplicationHelper::instance()->applicationPalette().highlight()); +#if QT_VERSION_MAJOR > 5 + painter->drawRoundedRect(rect.x() + rect.width() - 25, rect.y(), 25, rect.height(), 25, 25); +#else painter->drawRoundRect(rect.x() + rect.width() - 25, rect.y(), 25, rect.height(), 25, 25); +#endif painter->drawRect(rect.x(), rect.y(), rect.width() - 15, rect.height()); painter->setPen(QColor("#FFFFFF")); @@ -289,7 +297,11 @@ void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, if (isSelected) { painter->setPen(Dtk::Gui::DGuiApplicationHelper::instance()->applicationPalette().highlight().color()); painter->setBrush(QBrush(Dtk::Gui::DGuiApplicationHelper::instance()->applicationPalette().highlight())); +#if QT_VERSION_MAJOR > 5 + painter->drawRoundedRect(rect.x() + rect.width() - 25, rect.y(), 25, rect.height(), 25, 25); +#else painter->drawRoundRect(rect.x() + rect.width() - 25, rect.y(), 25, rect.height(), 25, 25); +#endif painter->drawRect(rect.x(), rect.y(), rect.width() - 15, rect.height()); painter->setPen(QColor("#FFFFFF")); } @@ -352,8 +364,13 @@ QWidget *ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem { Q_UNUSED(option); DLineEdit *pEdit = new DLineEdit(parent); +#if QT_VERSION_MAJOR > 5 + QRegularExpression regx("[^\\\\/\':\\*\\?\"<>|#%?]+"); // 屏蔽特殊字符 + QValidator *validator = new QRegularExpressionValidator(regx, pEdit); +#else QRegExp regx("[^\\\\/\':\\*\\?\"<>|#%?]+"); //屏蔽特殊字符 QValidator *validator = new QRegExpValidator(regx, pEdit); +#endif pEdit->lineEdit()->setValidator(validator); pEdit->lineEdit()->setMaxLength(83); connect(pEdit, &DLineEdit::textChanged, this, [=](QString filename) { diff --git a/src/src/ui/mainFrame/mainframe.cpp b/src/src/ui/mainFrame/mainframe.cpp index bdaf7023..ae5ad04d 100644 --- a/src/src/ui/mainFrame/mainframe.cpp +++ b/src/src/ui/mainFrame/mainframe.cpp @@ -7,7 +7,9 @@ #include #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include @@ -17,7 +19,9 @@ #include #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include #include @@ -132,7 +136,7 @@ void MainFrame::init() titlebar()->setObjectName("titlebar"); QPalette p; - p.setColor(QPalette::Background, QColor(255, 255, 255)); + p.setColor(QPalette::Window, QColor(255, 255, 255)); QFrame *pMainWidget = new QFrame; pMainWidget->setFrameShape(QFrame::NoFrame); @@ -195,7 +199,11 @@ void MainFrame::init() m_TaskNumWidget->setFixedHeight(30); //m_pTaskNumWidget->setPalette(pa); QHBoxLayout *TaskNumWidgetlayout = new QHBoxLayout(m_TaskNumWidget); +#if QT_VERSION_MAJOR > 5 + TaskNumWidgetlayout->setContentsMargins(0, 0, 0, 0); +#else TaskNumWidgetlayout->setMargin(0); +#endif m_TaskNum = new QLabel(tr("0 tasks")); m_TaskNum->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); m_TaskNum->setPalette(DGuiApplicationHelper::instance()->applicationPalette()); @@ -417,11 +425,19 @@ void MainFrame::updateDHTFile() QString dhtpah = QDir::homePath() + "/.config/uos/downloader/"; static QProcess p; +#if QT_VERSION_MAJOR > 5 + p.start("curl", {"--connect-timeout", "10", "-m", "20", "https://github.com/P3TERX/aria2.conf/raw/master/dht6.dat", "-o", dhtpah, "dht6.dat -O"}); +#else p.start("curl --connect-timeout 10 -m 20 https://github.com/P3TERX/aria2.conf/raw/master/dht6.dat -o" + dhtpah + "dht6.dat -O"); +#endif p.setStandardOutputFile("/dev/null"); static QProcess p2; +#if QT_VERSION_MAJOR > 5 + p2.start("curl", {"--connect-timeout", "10", "-m", "20", "https://github.com/P3TERX/aria2.conf/raw/master/dht.dat", "-o", dhtpah, "dht.dat -O"}); +#else p2.start("curl --connect-timeout 10 -m 20 https://github.com/P3TERX/aria2.conf/raw/master/dht.dat -o" + dhtpah + "dht.dat -O"); +#endif p2.setStandardOutputFile("/dev/null"); } @@ -610,7 +626,7 @@ void MainFrame::onTrayQuitClick(bool force) Aria2RPCInterface::instance()->shutdown(); // qApp->quit(); QTimer::singleShot(3000, this, [&]() { - qApp->quit(); + qApp->exit(); }); } @@ -711,13 +727,17 @@ void MainFrame::setTaskNum() void MainFrame::setPaletteType() { +#if QT_VERSION_MAJOR > 5 + DPalette pb = m_LeftList->viewport()->palette(); +#else DPalette pb = DApplicationHelper::instance()->palette(m_LeftList->viewport()); +#endif pb.setBrush(DPalette::Base, QColor(0, 0, 0, 0)); m_LeftList->setPalette(pb); if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType) { DPalette deepthemePalette; - deepthemePalette.setBrush(DPalette::Background, + deepthemePalette.setBrush(DPalette::Window, DGuiApplicationHelper::instance()->applicationPalette().base()); m_LeftWidget->setPalette(deepthemePalette); //m_pdownloadingItem->setBackground(DGuiApplicationHelper::instance()->applicationPalette().base()); @@ -739,7 +759,7 @@ void MainFrame::setPaletteType() DPalette palette; QColor c = DGuiApplicationHelper::instance()->applicationPalette().base().color(); c.setAlpha(70); - palette.setColor(DPalette::Background, c); + palette.setColor(DPalette::Window, c); m_TaskNumWidget->setPalette(palette); m_NotaskLabel->setWindowOpacity(0.2); m_DownloadingItem->setIcon(QIcon::fromTheme("dcc_list_downloading_dark", QIcon(":/icons/deepin/builtin/dark/actions/dcc_list_downloading_dark_11px.svg"))); @@ -751,7 +771,7 @@ void MainFrame::setPaletteType() m_TaskNum->setPalette(notaskTipLabelP); } else if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) { DPalette p; - p.setBrush(DPalette::Background, + p.setBrush(DPalette::Window, DGuiApplicationHelper::instance()->applicationPalette().base()); DPalette tableviewPalette; tableviewPalette.setBrush(DPalette::Base, DGuiApplicationHelper::instance()->applicationPalette().window()); @@ -762,7 +782,7 @@ void MainFrame::setPaletteType() DPalette palette; QColor c = DGuiApplicationHelper::instance()->applicationPalette().base().color(); c.setAlpha(70); - palette.setColor(DPalette::Background, c); + palette.setColor(DPalette::Window, c); m_TaskNumWidget->setPalette(palette); m_NotaskLabel->setWindowOpacity(0.2); m_DownloadingItem->setIcon(QIcon::fromTheme("dcc_list_downloading", QIcon(":/icons/deepin/builtin/dark/actions/dcc_list_downloading_dark_11px.svg"))); @@ -1877,7 +1897,11 @@ void MainFrame::onDownloadFirstBtnClicked() } if (m_CheckItem->status == Global::DownloadTaskStatus::Paused) { Aria2RPCInterface::instance()->unpause(m_CheckItem->gid, m_CheckItem->taskId); +#if QT_VERSION_MAJOR > 5 + QElapsedTimer time; +#else QTime time; +#endif time.start(); while (time.elapsed() < 400) { QCoreApplication::processEvents(); @@ -2804,7 +2828,11 @@ void MainFrame::onParseUrlList(QVector &urlList, QString path) } onDownloadNewUrl(url, path, info.urlName, info.type, info.urlSize); +#if QT_VERSION_MAJOR > 5 + QElapsedTimer time; +#else QTime time; +#endif time.start(); while (time.elapsed() < 1000) { QCoreApplication::processEvents(); @@ -2979,7 +3007,7 @@ void MainFrame::setAutoStart(bool ret) } QTextStream writeData(&writerFile); for (int i = 0; i < list.size(); i++) { - writeData << list[i] << endl; + writeData << list[i] << Qt::endl; } writeData.flush(); writerFile.close(); @@ -3190,7 +3218,11 @@ bool MainFrame::checkIsHasSameTask(QString infoHash) } } } +#if QT_VERSION_MAJOR > 5 + QElapsedTimer time; +#else QTime time; +#endif time.start(); while (time.elapsed() < 500) { QCoreApplication::processEvents(); diff --git a/src/src/ui/mainFrame/tableModel.cpp b/src/src/ui/mainFrame/tableModel.cpp index 522d3201..4911b8e9 100644 --- a/src/src/ui/mainFrame/tableModel.cpp +++ b/src/src/ui/mainFrame/tableModel.cpp @@ -234,6 +234,8 @@ bool TableModel::switchDownloadingMode() bool TableModel::switchFinishedMode() { + beginResetModel(); + m_Mode = Finished; m_RenderList.clear(); @@ -242,7 +244,10 @@ bool TableModel::switchFinishedMode() m_RenderList.append(item); } } + sortDownload(m_SortColumn, m_SortOrder); + + endResetModel(); return true; } @@ -650,13 +655,21 @@ typedef bool (*LessThan)(const QPair &left, bool itemLessThan(const QPair &left, const QPair &right) { +#if QT_VERSION_MAJOR > 5 + return left.first.toDouble() < right.first.toDouble(); +#else return left.first < right.first; +#endif } bool itemGreaterThan(const QPair &left, const QPair &right) { +#if QT_VERSION_MAJOR > 5 + return right.first.toDouble() < left.first.toDouble(); +#else return right.first < left.first; +#endif } void TableModel::sort(int column, Qt::SortOrder order) diff --git a/src/src/ui/mainFrame/tableView.cpp b/src/src/ui/mainFrame/tableView.cpp index 36d96cbe..105b30d3 100644 --- a/src/src/ui/mainFrame/tableView.cpp +++ b/src/src/ui/mainFrame/tableView.cpp @@ -41,7 +41,9 @@ #include #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include "../database/dbinstance.h" @@ -245,6 +247,9 @@ bool TableView::refreshTableView(const int &index) //getTableHeader()->setSortIndicator(4, Qt::AscendingOrder); break; } +#if QT_VERSION_MAJOR > 5 + resizeColumnToContents(4); +#endif update(); return true; } @@ -285,8 +290,14 @@ void LeftListView::currentChanged(const QModelIndex ¤t, const QModelIndex void LeftListView::paintEvent(QPaintEvent *e) { DPalette pa; +#if QT_VERSION_MAJOR > 5 + pa = this->palette(); + pa.setBrush(DPalette::ItemBackground, pa.brush(DPalette::Base)); + this->setPalette(pa); +#else pa = DApplicationHelper::instance()->palette(this); pa.setBrush(DPalette::ItemBackground, pa.brush(DPalette::Base)); DApplicationHelper::instance()->setPalette(this, pa); +#endif DListView::paintEvent(e); } diff --git a/src/src/ui/mainFrame/tabledatacontrol.cpp b/src/src/ui/mainFrame/tabledatacontrol.cpp index 096ea983..ed77c010 100644 --- a/src/src/ui/mainFrame/tabledatacontrol.cpp +++ b/src/src/ui/mainFrame/tabledatacontrol.cpp @@ -47,6 +47,9 @@ #include #include #include +#if QT_VERSION_MAJOR > 5 +#include +#endif #include #include #include @@ -968,7 +971,12 @@ bool TableDataControl::reDownloadTask(QString taskId, QString filePath, QString opt.insert("out", fileName); Aria2RPCInterface::instance()->addUri(url, opt, strId); QString filename = QString(url).right(url.length() - url.lastIndexOf('/') - 1); +#if QT_VERSION_MAJOR > 5 + QRegularExpression regex("[\\x4e00-\\x9fa5]+"); + if (!filename.contains(regex)) { +#else if (!filename.contains(QRegExp("[\\x4e00-\\x9fa5]+"))) { +#endif const QByteArray filenameByte = filename.toLatin1(); QString filenameDecode = QUrl::fromPercentEncoding(filenameByte); filename = filenameDecode; diff --git a/src/src/ui/settings/diagnostictool.cpp b/src/src/ui/settings/diagnostictool.cpp index 102cbe57..b70fbf8b 100644 --- a/src/src/ui/settings/diagnostictool.cpp +++ b/src/src/ui/settings/diagnostictool.cpp @@ -45,6 +45,9 @@ #include "global.h" #include "func.h" #include "aria2rpcinterface.h" +#if QT_VERSION_MAJOR > 5 +#include +#endif DiagnosticTool::DiagnosticTool(QWidget *parent) : DDialog(parent) @@ -176,6 +179,32 @@ void DiagnosticTool::startDiagnostic() m_Model->appendData(Func::isIPV6Connect()); }); +#if QT_VERSION_MAJOR > 5 + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> distrib(0, 800); // 生成 0 到 800 之间的随机数 + + QTimer::singleShot(distrib(gen) + 200, this, [=]() { + m_Model->appendData(m_IsHasDHT & Func::isNetConnect()); + }); + + QTimer::singleShot(distrib(gen) + 800, this, [=]() { + m_Model->appendData(Func::isHTTPConnect()); + }); + + QTimer::singleShot(distrib(gen) + 1400, this, [=]() { + m_Model->appendData((m_IsHasTracks | m_IsHasDHT) & Func::isNetConnect()); + }); + + QTimer::singleShot(distrib(gen) + 2000, this, [=]() { + m_Model->appendData((m_IsHasTracks | m_IsHasDHT) & Func::isNetConnect()); + }); + + QTimer::singleShot(distrib(gen) + 2500, this, [=]() { + m_Model->appendData(Func::isNetConnect()); + m_Button->setEnabled(true); + }); +#else QTimer::singleShot(qrand() % (800) + 200, this, [=]() { m_Model->appendData(m_IsHasDHT & Func::isNetConnect()); }); @@ -195,6 +224,7 @@ void DiagnosticTool::startDiagnostic() m_Model->appendData(Func::isNetConnect()); m_Button->setEnabled(true); }); +#endif } DiagnosticModel::DiagnosticModel(QObject *parent) @@ -282,8 +312,13 @@ QVariant DiagnosticModel::data(const QModelIndex &index, int role) const return Qt::AlignLeft; } break; +#if QT_VERSION_MAJOR > 5 + case Qt::ForegroundRole: + return m_DiagnosticStatusList.at(index.row()) ? ("#00c77d") : ("#ff5736"); +#else case Qt::TextColorRole: return m_DiagnosticStatusList.at(index.row()) ? ("#00c77d") : ("#ff5736"); +#endif case Qt::AccessibleTextRole: case Qt::AccessibleDescriptionRole: { if (index.column() == 1) { @@ -336,7 +371,11 @@ void DiagnosticDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op QSize(radius * 2, radius * 2)), 270, 90); +#if QT_VERSION_MAJOR > 5 + painter->setPen(QColor(index.data(Qt::ForegroundRole).toString())); +#else painter->setPen(QColor(index.data(Qt::TextColorRole).toString())); +#endif if (index.row() % 2 != 0) { painter->fillRect(option.rect, QBrush(QColor(0, 0, 0, 8))); // } else { diff --git a/src/src/ui/settings/filesavepathchooser.cpp b/src/src/ui/settings/filesavepathchooser.cpp index f12005fb..799453b6 100644 --- a/src/src/ui/settings/filesavepathchooser.cpp +++ b/src/src/ui/settings/filesavepathchooser.cpp @@ -59,7 +59,11 @@ void FileSavePathChooser::initUI() m_fileChooserEdit->lineEdit()->setReadOnly(true); m_fileChooserEdit->lineEdit()->setClearButtonEnabled(false); +#if QT_VERSION_MAJOR > 5 + m_fileChooserEdit->setFileMode(QFileDialog::FileMode::Directory); +#else m_fileChooserEdit->setFileMode(QFileDialog::FileMode::DirectoryOnly); +#endif if (m_currentSelect == 1) { m_autoLastPathRadioButton->setChecked(true); diff --git a/src/src/ui/settings/settings.cpp b/src/src/ui/settings/settings.cpp index 02477823..b8a17a53 100644 --- a/src/src/ui/settings/settings.cpp +++ b/src/src/ui/settings/settings.cpp @@ -30,7 +30,9 @@ */ #include "settings.h" +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include #include diff --git a/src/src/ui/settings/settingswidget.cpp b/src/src/ui/settings/settingswidget.cpp index cdbf8c99..95b14681 100644 --- a/src/src/ui/settings/settingswidget.cpp +++ b/src/src/ui/settings/settingswidget.cpp @@ -40,7 +40,9 @@ #include #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include #include "settings.h" @@ -174,7 +176,11 @@ bool SettingsLineWidget::initUI(QString text, const QStringList &textList, QStri m_comboBox->setFixedWidth(150); m_comboBox->addItems(textList); m_comboBox->setCurrentText(currenttext); +#if QT_VERSION_MAJOR > 5 + m_comboBox->setAccessibleName(text.remove(QRegularExpression("\\s"))); +#else m_comboBox->setAccessibleName(text.remove(QRegExp("\\s"))); +#endif layout->addWidget(pLabel); layout->addStretch(); layout->addWidget(m_comboBox, 0, Qt::AlignRight); diff --git a/src/src/ui/settings/timeEdit.cpp b/src/src/ui/settings/timeEdit.cpp index e830e946..4adf699d 100644 --- a/src/src/ui/settings/timeEdit.cpp +++ b/src/src/ui/settings/timeEdit.cpp @@ -4,7 +4,12 @@ #include "timeEdit.h" +#if QT_VERSION_MAJOR <= 5 #include +#else +#include +#include +#endif #include CTimeEdit::CTimeEdit(QWidget *parent) @@ -44,9 +49,15 @@ void CTimeEdit::initUI() //m_timeEdit->lineEdit()->setInputMask("00:00;0"); m_timeEdit->setClearButtonEnabled(false); m_timeEdit->setMinimumHeight(22); +#if QT_VERSION_MAJOR > 5 + QRegularExpressionValidator *validator = nullptr; + QRegularExpression rx("0[0-9]:[0-5][0-9]|1[0-9]:[0-5][0-9]|2[0-3]:[0-5][0-9]"); + validator = new QRegularExpressionValidator(rx, this); +#else QRegExpValidator *validator = nullptr; QRegExp rx("0[0-9]:[0-5][0-9]|1[0-9]:[0-5][0-9]|2[0-3]:[0-5][0-9]"); validator = new QRegExpValidator(rx, this); +#endif m_timeEdit->lineEdit()->setValidator(validator); setLineEdit(m_timeEdit->lineEdit()); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bee19986..abeee3ef 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -79,14 +79,25 @@ file(GLOB ALL_SOURCES "../src/src/ui/*.cpp" file(GLOB SRC_QRC ${PROJECT_SOURCE_DIR}/src/src/ui/resource/*.qrc) #需要生成的moc文件,输出文件名称放在变量 mocfiles中,必须在find QT5 package才能调用 -QT5_WRAP_CPP (UDLC_UI_HEADERS_MOC ${ALL_HEADERS}) +qt_wrap_cpp (UDLC_UI_HEADERS_MOC ${ALL_HEADERS}) #将test文件,源文件,源头文件,moc文件加入到test程序中 add_executable(${PROJECT_NAME_TEST} ${SRC_LIST} ${ALL_HEADERS} ${ALL_SOURCES} ${UDLC_UI_HEADERS_MOC} ${SRC_QRC}) #添加gtest库,Qt库,dtk库 target_link_libraries(${PROJECT_NAME_TEST} gmock gmock_main gtest gtest_main pthread - Qt5::Core Qt5::Network Qt5::Widgets Qt5::Svg Qt5::DBus Qt5::Sql Qt5::Test ${DtkWidget_LIBRARIES} ${DtkGui_LIBRARIES} ${DtkCore_LIBRARIES} Qt5::WebChannel Qt5::WebSockets) + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Network + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Svg + Qt${QT_VERSION_MAJOR}::DBus + Qt${QT_VERSION_MAJOR}::Sql + Qt${QT_VERSION_MAJOR}::Test + Dtk${DTK_VERSION}::Core + Dtk${DTK_VERSION}::Gui + Dtk${DTK_VERSION}::Widget + Qt${QT_VERSION_MAJOR}::WebChannel + Qt${QT_VERSION_MAJOR}::WebSockets) # 添加 QTest 测试 add_test(${PROJECT_NAME_TEST} COMMAND ${PROJECT_NAME_TEST}) diff --git a/tests/ui/mainFrame/ut_mainframe.cpp b/tests/ui/mainFrame/ut_mainframe.cpp index a9c39521..40deb2b4 100644 --- a/tests/ui/mainFrame/ut_mainframe.cpp +++ b/tests/ui/mainFrame/ut_mainframe.cpp @@ -1113,11 +1113,6 @@ TEST_F(ut_MainFreme, modelList) MainFrame::instance()->m_DownLoadingTableView->getTableModel()->recyleList(); MainFrame::instance()->m_DownLoadingTableView->getTableModel()->getTableModelMap(); } -TEST_F(ut_MainFreme, setThemeType) -{ - DGuiApplicationHelper::instance()->setThemeType(DGuiApplicationHelper::DarkType); - DGuiApplicationHelper::instance()->setThemeType(DGuiApplicationHelper::LightType); -} TEST_F(ut_MainFreme, onIsMetalinkDownload) { MainFrame::instance()->onIsMetalinkDownload(true); diff --git a/tests/ui/settings/ut_settings.cpp b/tests/ui/settings/ut_settings.cpp index d8368012..e1a7bce3 100644 --- a/tests/ui/settings/ut_settings.cpp +++ b/tests/ui/settings/ut_settings.cpp @@ -570,7 +570,11 @@ TEST_F(ut_Settings, DiagnosticTool) model.columnCount(); QModelIndex index; index.r = 2; +#if QT_VERSION_MAJOR > 5 + model.data(index, Qt::ForegroundRole); +#else model.data(index, Qt::TextColorRole); +#endif model.data(index, 123); QTimer::singleShot(7000, this, [=]() { d->close(); diff --git a/translate_generation.sh b/translate_generation.sh index 473dc1a0..6117619c 100755 --- a/translate_generation.sh +++ b/translate_generation.sh @@ -7,5 +7,5 @@ ts_list=(`ls translations/*.ts`) for ts in "${ts_list[@]}" do printf "\nprocess ${ts}\n" - lrelease "${ts}" + /usr/lib/qt6/bin/lrelease "${ts}" done \ No newline at end of file