From 818ac0450a4c19e0666df6802c12e8633b2b3bc7 Mon Sep 17 00:00:00 2001 From: x-tools-author Date: Thu, 21 Mar 2024 08:53:50 +0800 Subject: [PATCH] chore: update files of project --- CMakeLists.txt | 25 +++-- Source/Common/Common/xToolsInterface.cpp | 114 +++-------------------- Source/Common/Common/xToolsInterface.h | 9 -- 3 files changed, 32 insertions(+), 116 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e446a47..26cd8aef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,11 +19,10 @@ if(X_TOOLS_BUILD_FOR_STORE) endif() set(X_TOOLS_QT_COMPONENTS Core Gui Widgets WebSockets Network) - -if(NOT CMAKE_SYSTEM_NAME STREQUAL "iOS") +if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "iOS") list(APPEND X_TOOLS_QT_COMPONENTS SerialPort) list(APPEND X_TOOLS_QT_COMPONENTS SerialBus) - # add_compile_definitions(X_TOOLS_IMPORT_MODULE_SERIALPORT) + add_compile_definitions(X_TOOLS_IMPORT_MODULE_SERIALPORT) add_compile_definitions(X_TOOLS_IMPORT_MODULE_SERIALBUS) endif() @@ -152,7 +151,7 @@ target_link_libraries(xTools PRIVATE Qt${QT_VERSION_MAJOR}::Gui) target_link_libraries(xTools PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) target_link_libraries(xTools PRIVATE Qt${QT_VERSION_MAJOR}::Network) target_link_libraries(xTools PRIVATE Qt${QT_VERSION_MAJOR}::WebSockets) -if(NOT CMAKE_SYSTEM_NAME STREQUAL "iOS") +if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "iOS") target_link_libraries(xTools PRIVATE Qt${QT_VERSION_MAJOR}::SerialPort) target_link_libraries(xTools PRIVATE Qt${QT_VERSION_MAJOR}::SerialBus) endif() @@ -163,7 +162,17 @@ if(X_TOOLS_IMPORT_MODULE_BLUETOOTH) endif() # ------------------------------------------------------------------------------------------------- -# Assistants -add_subdirectory(${CMAKE_SOURCE_DIR}/Source/Assistants) -add_subdirectory(${CMAKE_SOURCE_DIR}/Source/ModbusStudio) -add_subdirectory(${CMAKE_SOURCE_DIR}/Source/CANBusStudio) +option(X_TOOLS_ENABLE_APP_ASSISTANTS "Enable assistant applications" OFF) +if(X_TOOLS_ENABLE_APP_ASSISTANTS) + add_subdirectory(${CMAKE_SOURCE_DIR}/Source/Assistants) +endif() + +option(X_TOOLS_ENABLE_APP_MODBUS_STUDIO "Enable Modbus Studio application" OFF) +if(X_TOOLS_ENABLE_APP_MODBUS_STUDIO) + add_subdirectory(${CMAKE_SOURCE_DIR}/Source/ModbusStudio) +endif() + +option(X_TOOLS_ENABLE_APP_CANBUS_STUDIO "Enable CANBus Studio application" OFF) +if(X_TOOLS_ENABLE_APP_CANBUS_STUDIO) + add_subdirectory(${CMAKE_SOURCE_DIR}/Source/CANBusStudio) +endif() diff --git a/Source/Common/Common/xToolsInterface.cpp b/Source/Common/Common/xToolsInterface.cpp index 08ac80e7..d1c41748 100644 --- a/Source/Common/Common/xToolsInterface.cpp +++ b/Source/Common/Common/xToolsInterface.cpp @@ -236,8 +236,8 @@ QByteArray xToolsInterface::arrayToHex(const QByteArray &array, char separator) } void xToolsInterface::setLineEditValidator(QLineEdit *lineEdit, - SAKEnumValidatorType type, - int maxLength) + SAKEnumValidatorType type, + int maxLength) { QMap regExpMap; regExpMap.insert(ValidatorBin, QRegularExpression("([01][01][01][01][01][01][01][01][ ])*")); @@ -263,95 +263,9 @@ void xToolsInterface::setLineEditValidator(QLineEdit *lineEdit, } } -#ifdef X_TOOLS_IMPORT_MODULE_SERIALPORT -void xToolsInterface::addSerialPortNametItemsToComboBox(QComboBox *comboBox) -{ - if (comboBox) { - comboBox->clear(); - QList coms = QSerialPortInfo::availablePorts(); - QStandardItemModel *itemModel = new QStandardItemModel(comboBox); - for (auto &var : coms) { - QStandardItem *item = new QStandardItem(var.portName()); - item->setToolTip(var.description()); - itemModel->appendRow(item); - } - - comboBox->setModel(itemModel); - } -} -#endif - -#ifdef X_TOOLS_IMPORT_MODULE_SERIALPORT -void xToolsInterface::addSerialPortBaudRateItemsToComboBox(QComboBox *comboBox) -{ - if (comboBox) { - comboBox->clear(); - QList bd = QSerialPortInfo::standardBaudRates(); - for (auto &var : bd) { - comboBox->addItem(QString::number(var), QVariant::fromValue(var)); - } - - comboBox->setCurrentText("9600"); - } -} -#endif - -#ifdef X_TOOLS_IMPORT_MODULE_SERIALPORT -void xToolsInterface::addSerialPortDataBitItemsToComboBox(QComboBox *comboBox) -{ - if (comboBox) { - comboBox->clear(); - comboBox->addItem("8", QVariant::fromValue(int(QSerialPort::Data8))); - comboBox->addItem("7", QVariant::fromValue(int(QSerialPort::Data7))); - comboBox->addItem("6", QVariant::fromValue(int(QSerialPort::Data6))); - comboBox->addItem("5", QVariant::fromValue(int(QSerialPort::Data5))); - } -} -#endif - -#ifdef X_TOOLS_IMPORT_MODULE_SERIALPORT -void xToolsInterface::addSerialPortStopBitItemsToComboBox(QComboBox *comboBox) -{ - if (comboBox) { - comboBox->clear(); - comboBox->addItem("1", QVariant::fromValue(int(QSerialPort::OneStop))); -#ifdef Q_OS_WINDOWS - comboBox->addItem("1.5", QVariant::fromValue(int(QSerialPort::OneAndHalfStop))); -#endif - comboBox->addItem("2", QVariant::fromValue(int(QSerialPort::TwoStop))); - } -} -#endif - -#ifdef X_TOOLS_IMPORT_MODULE_SERIALPORT -void xToolsInterface::addSerialPortParityItemsToComboBox(QComboBox *comboBox) -{ - if (comboBox) { - comboBox->clear(); - comboBox->addItem(tr("No"), QVariant::fromValue(int(QSerialPort::NoParity))); - comboBox->addItem(tr("Even"), QVariant::fromValue(int(QSerialPort::EvenParity))); - comboBox->addItem(tr("Odd"), QVariant::fromValue(int(QSerialPort::OddParity))); - comboBox->addItem(tr("Space"), QVariant::fromValue(int(QSerialPort::SpaceParity))); - comboBox->addItem(tr("Mark"), QVariant::fromValue(int(QSerialPort::MarkParity))); - } -} -#endif - -#ifdef X_TOOLS_IMPORT_MODULE_SERIALPORT -void xToolsInterface::addSerialPortFlowControlItemsToComboBox(QComboBox *comboBox) -{ - if (comboBox) { - comboBox->clear(); - comboBox->addItem(tr("No"), QVariant::fromValue(int(QSerialPort::NoFlowControl))); - comboBox->addItem(tr("Hardware"), QVariant::fromValue(int(QSerialPort::HardwareControl))); - comboBox->addItem(tr("Software"), QVariant::fromValue(int(QSerialPort::SoftwareControl))); - } -} -#endif - void xToolsInterface::setComboBoxIndexFromSettings(QSettings *settings, - QString key, - QComboBox *comboBox) + QString key, + QComboBox *comboBox) { int index = settings->value(key).toInt(); if (index >= 0 && index < comboBox->count()) { @@ -360,14 +274,16 @@ void xToolsInterface::setComboBoxIndexFromSettings(QSettings *settings, } void xToolsInterface::setSettingsValueFromComboBoxIndex(QSettings *settings, - QString key, - QComboBox *comboBox) + QString key, + QComboBox *comboBox) { int currentIndex = comboBox->currentIndex(); settings->setValue(key, currentIndex); } -void xToolsInterface::setLineEditTextFromSettings(QSettings *settings, QString key, QLineEdit *lineEdit) +void xToolsInterface::setLineEditTextFromSettings(QSettings *settings, + QString key, + QLineEdit *lineEdit) { QString text = settings->value(key).toString(); if (!text.isEmpty()) { @@ -376,23 +292,23 @@ void xToolsInterface::setLineEditTextFromSettings(QSettings *settings, QString k } void xToolsInterface::setSettingsValueFromLineEditText(QSettings *settings, - QString key, - QLineEdit *lineEdit) + QString key, + QLineEdit *lineEdit) { QString value = lineEdit->text(); settings->setValue(key, value); } void xToolsInterface::setCheckBoxValueFromSettings(QSettings *settings, - QString key, - QCheckBox *checkBox) + QString key, + QCheckBox *checkBox) { checkBox->setChecked(settings->value(key).toBool()); } void xToolsInterface::setSettingsValueFromCheckBox(QSettings *settings, - QString key, - QCheckBox *checkBox) + QString key, + QCheckBox *checkBox) { settings->setValue(key, checkBox->isChecked()); } diff --git a/Source/Common/Common/xToolsInterface.h b/Source/Common/Common/xToolsInterface.h index a9291fa9..8206e2c7 100644 --- a/Source/Common/Common/xToolsInterface.h +++ b/Source/Common/Common/xToolsInterface.h @@ -92,15 +92,6 @@ public: static void setLineEditValidator(QLineEdit *lineEdit, SAKEnumValidatorType type, int maxLength = INT_MAX); -#ifdef X_TOOLS_IMPORT_MODULE_SERIALPORT - // Serialport interfaces - static void addSerialPortNametItemsToComboBox(QComboBox *comboBox); - static void addSerialPortBaudRateItemsToComboBox(QComboBox *comboBox); - static void addSerialPortDataBitItemsToComboBox(QComboBox *comboBox); - static void addSerialPortStopBitItemsToComboBox(QComboBox *comboBox); - static void addSerialPortParityItemsToComboBox(QComboBox *comboBox); - static void addSerialPortFlowControlItemsToComboBox(QComboBox *comboBox); -#endif static void setComboBoxIndexFromSettings(QSettings *settings, QString key, QComboBox *comboBox); static void setSettingsValueFromComboBoxIndex(QSettings *settings, QString key,