diff --git a/.clang-tidy b/.clang-tidy index 15e77a9..afb709a 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,3 +1,4 @@ +HeaderFilterRegex: .* Checks: -*, cppcoreguidelines-*, @@ -16,9 +17,11 @@ Checks: -bugprone-suspicious-missing-comma, -clang-analyzer-core.UndefinedBinaryOperatorResult, -clang-analyzer-cplusplus.NewDeleteLeaks, + -clang-analyzer-cplusplus.NewDelete, -clang-analyzer-optin.cplusplus.VirtualCall, -clang-analyzer-security.FloatLoopCounter, -cppcoreguidelines-avoid-c-arrays, + -cppcoreguidelines-avoid-do-while, -cppcoreguidelines-avoid-goto, -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-explicit-virtual-functions, diff --git a/.github/actions/appimage/action.yml b/.github/actions/appimage/action.yml index ffbdd5e..3014645 100644 --- a/.github/actions/appimage/action.yml +++ b/.github/actions/appimage/action.yml @@ -46,7 +46,7 @@ runs: shell: bash - name: Upload AppImage - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: shvspy-${{ env.VERSION }}-x86_64.Appimage path: shvspy-*-x86_64.AppImage diff --git a/.github/actions/cmake/action.yml b/.github/actions/cmake/action.yml index 41eca85..ff21b4a 100644 --- a/.github/actions/cmake/action.yml +++ b/.github/actions/cmake/action.yml @@ -4,8 +4,9 @@ inputs: qt_version: description: "Specify Qt version to use" required: true + default: "6.5.3" qt_arch: - description: "Specify Qt version to use" + description: "Specify Qt arch to use" default: "gcc_64" use_qt6: description: "Specify whether we're using Qt 5 or Qt 6" @@ -21,9 +22,9 @@ runs: using: "composite" steps: # Linux deps - - name: Install/cache clazy, ninja, openldap, doctest libfuse, and Qt's dependencies + - name: Install apt packages if: runner.os != 'Windows' - uses: awalsh128/cache-apt-pkgs-action@v1.3.0 + uses: awalsh128/cache-apt-pkgs-action@v1.4.2 with: packages: ninja-build libgl1-mesa-dev libpulse-dev libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-shape0 libxcb-util1 libxcb-xinerama0 libxkbcommon-x11-0 libxcb-cursor-dev clazy libfuse-dev version: 1.0 @@ -45,6 +46,15 @@ runs: arch: ${{ inputs.qt_arch }} install-deps: false modules: ${{ inputs.modules }} + extra: --autodesktop + + - name: WASM-specific stuff + if: inputs.qt_arch == 'wasm_singlethread' + run: | + chmod +x "${Qt6_DIR}/bin/qt-cmake" + echo cmake_extra_args="'-DBUILD_SHARED_LIBS=OFF' '-DQT_HOST_PATH=$(realpath "${Qt6_DIR}/../gcc_64")'" >> "$GITHUB_ENV" + echo CMAKE_BIN="${Qt6_DIR}/bin/qt-cmake" >> "$GITHUB_ENV" + shell: bash - name: ccache uses: hendrikmuhs/ccache-action@v1.2.12 @@ -55,15 +65,15 @@ runs: run: | CFLAGS="-Werror ${CFLAGS}" \ CXXFLAGS="-Werror ${CXXFLAGS}" \ - cmake \ - -S '${{github.workspace}}' \ - -B '${{github.workspace}}/build' \ - -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_TESTING=OFF \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DSHVSPY_USE_QT6=${{ inputs.use_qt6 }} \ - ${{ env.cmake_extra_args }} \ - ${{ inputs.additional_cmake_args }} + "${CMAKE_BIN:-cmake}" \ + -S '${{github.workspace}}' \ + -B '${{github.workspace}}/build' \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_TESTING=OFF \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DSHVSPY_USE_QT6=${{ inputs.use_qt6 }} \ + ${{ env.cmake_extra_args }} \ + ${{ inputs.additional_cmake_args }} shell: bash diff --git a/.github/actions/run-linter/action.yml b/.github/actions/run-linter/action.yml index 222b81f..594f5ca 100644 --- a/.github/actions/run-linter/action.yml +++ b/.github/actions/run-linter/action.yml @@ -14,7 +14,7 @@ runs: CC: clang-15 CXX: clang++-15 with: - qt_version: 6.5.0 + qt_version: 6.5.3 use_qt6: ON modules: qtserialport qtwebsockets qtnetworkauth additional_cmake_args: -DCMAKE_GLOBAL_AUTOGEN_TARGET=ON -DCMAKE_AUTOGEN_ORIGIN_DEPENDS=OFF @@ -24,24 +24,35 @@ runs: with: os: ubuntu-latest + - name: Install ctcache + run: | + CTCACHE_REF=e70da77cb867d74ccadce3f3c5862fc9cf4d22a7 + curl --location "https://github.com/matus-chochlik/ctcache/archive/${CTCACHE_REF}.tar.gz" | tar --extract --to-stdout --gzip --file - "ctcache-${CTCACHE_REF}/clang-tidy-cache" | sudo tee /usr/bin/clang-tidy-cache > /dev/null + sudo chmod +x /usr/bin/clang-tidy-cache + echo CTCACHE_DIR='${{github.workspace}}/.ctcache' >> "$GITHUB_ENV" + shell: bash + + - name: Generate timestamp + run: echo "NOW=$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")" >> $GITHUB_ENV + shell: bash + + - name: Setup clang-tidy cache + uses: actions/cache@v4 + with: + key: ctcache-${{ github.job }}-${{ env.NOW }} + path: ${{github.workspace}}/.ctcache + restore-keys: ctcache-${{ github.job }}- + - name: Build autogenerated stuff shell: bash run: cmake --build ${{github.workspace}}/build --parallel "$(nproc)" --target autogen - - name: Copy compile_commands.json + - name: Mark generated files as system shell: bash - run: cp build/compile_commands.json compile_commands.json + run: sed -i "s@-I$(pwd)/build@-isystem $(pwd)/build@" build/compile_commands.json - name: Run the linter shell: bash run: | - BASE_REF="${{github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before}}" - git fetch --depth=1 origin "$BASE_REF" - readarray -t CHANGED_FILES < <(git diff --name-only "$BASE_REF" | grep 'cpp$') - if [[ "${#CHANGED_FILES[@]}" -eq 0 ]]; then - echo "No changed cpp files." - exit 0 - fi - echo "Changed files:" - printf '%s\n' "${CHANGED_FILES[@]}" - printf '%s\n' "${CHANGED_FILES[@]}" | parallel --verbose --jobs "$(nproc)" --plus _=[{#}/{##}] ${{ inputs.lint_program_with_args }} {} + readarray -t FILES < <(find '${{github.workspace}}' -name \*.cpp | grep -v 3rdparty/ | grep -v build/ | grep -v emsdk-cache/) + printf '%s\n' "${FILES[@]}" | parallel --verbose --jobs "$(nproc)" --plus _=[{#}/{##}] ${{ inputs.lint_program_with_args }} {} diff --git a/.github/workflows/appimage.yml b/.github/workflows/appimage.yml index 471983b..07b0c77 100644 --- a/.github/workflows/appimage.yml +++ b/.github/workflows/appimage.yml @@ -12,18 +12,17 @@ on: jobs: ubuntu-qt6: - name: Qt 6.5.0 / Ubuntu 22.04 + name: Qt 6.5.3 / Ubuntu 22.04 runs-on: ubuntu-22.04 steps: - name: Clone the repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: true - name: Setup CMake uses: ./.github/actions/cmake with: - qt_version: 6.5.0 use_qt6: ON modules: qtserialport qtwebsockets qtnetworkauth additional_cmake_args: -DCMAKE_INSTALL_PREFIX='${{ github.workspace }}/install/usr' @@ -40,7 +39,7 @@ jobs: CXXFLAGS: -Wno-stringop-overflow steps: - name: Clone the repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: true diff --git a/.github/workflows/installer.yml b/.github/workflows/installer.yml index e352e40..8640761 100644 --- a/.github/workflows/installer.yml +++ b/.github/workflows/installer.yml @@ -12,18 +12,17 @@ on: jobs: windows: - name: Qt 6.5.0 / Windows + name: Qt 6.5.3 / Windows runs-on: windows-2022 steps: - name: Clone the repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: true - name: Setup CMake uses: ./.github/actions/cmake with: - qt_version: 6.5.0 qt_arch: win64_mingw use_qt6: ON modules: qtserialport qtwebsockets qtnetworkauth @@ -36,9 +35,7 @@ jobs: run: cmake --install '${{ github.workspace }}/build' - name: Run windeployqt - # --no-translations is needed because https://bugreports.qt.io/browse/QTBUG-112204 - # FIXME: Remove when 6.5.1 becomes available. - run: windeployqt --no-translations -websockets -serialport '${{ github.workspace }}/install/bin/shvspy.exe' + run: windeployqt -websockets -serialport '${{ github.workspace }}/install/bin/shvspy.exe' - name: Copy MinGW runtime libraries # windeployqt is unable to copy those, because it looks for them next to where g++.exe is. On the GitHub runner, @@ -54,7 +51,7 @@ jobs: run: iscc "-DBUILD_DIR=${{ github.workspace }}/install" "-DVERSION=${{ env.VERSION }}" shvspy/shvspy.iss - name: Upload installer - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: shvspy-${{ env.VERSION }}-setup.exe path: ${{ github.workspace }}/install/_inno/shvspy/shvspy-*-setup.exe diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3e89753..9c6d2d9 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,25 +16,25 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Clone the repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: true - name: Run clang-tidy uses: ./.github/actions/run-linter with: - lint_program_with_args: clang-tidy-15 --quiet --warnings-as-errors=* + lint_program_with_args: clang-tidy-cache clang-tidy-15 -p build --quiet --warnings-as-errors=* clazy: name: clazy / Ubuntu 22.04 runs-on: ubuntu-22.04 steps: - name: Clone the repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: true - name: Run clazy uses: ./.github/actions/run-linter with: - lint_program_with_args: clazy-standalone --checks=level1,no-fully-qualified-moc-types,no-non-pod-global-static + lint_program_with_args: clang-tidy-cache clazy-standalone -p build --checks=level1,no-fully-qualified-moc-types,no-non-pod-global-static diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c6016e..0d32eba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,11 +15,11 @@ jobs: name: Qt 6.6.2 / NixOS runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - name: Install Nix - uses: cachix/install-nix-action@v20 + uses: cachix/install-nix-action@v26 with: nix_path: nixpkgs=channel:nixos-unstable - name: Build diff --git a/.github/workflows/webassembly.yml b/.github/workflows/webassembly.yml new file mode 100644 index 0000000..4e69af4 --- /dev/null +++ b/.github/workflows/webassembly.yml @@ -0,0 +1,71 @@ +name: WebAssembly + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + id-token: write + pages: write + +env: + emsdk_cache_dir: "emsdk-cache" + +jobs: + ubuntu-qt6-wasm: + name: Qt 6.6.3 / Ubuntu 22.04 + runs-on: ubuntu-22.04 + steps: + - name: Clone the repository + uses: actions/checkout@v4 + with: + submodules: true + + - name: Setup emsdk cache + uses: actions/cache@v4 + with: + key: emsdk-cache + path: ${{ env.emsdk_cache_dir }} + + - uses: mymindstorm/setup-emsdk@v14 + with: + version: 3.1.37 + actions-cache-folder: ${{ env.emsdk_cache_dir }} + + - name: Setup CMake + uses: ./.github/actions/cmake + with: + qt_version: 6.6.3 + qt_arch: wasm_singlethread + use_qt6: ON + modules: qtwebsockets + + - name: Build + run: cmake --build '${{github.workspace}}/build' --parallel "$(nproc)" + shell: bash + + - name: Consolidate WebAssembly artifacts + run: | + mkdir gh-sources + cp '${{github.workspace}}'/build/shvspy/*.{js,wasm,html} gh-sources/ + mv gh-sources/shvspy.html gh-sources/index.html + cp '${{github.workspace}}'/distro/shvspy.AppDir/shvspy.svg gh-sources/qtlogo.svg + shell: bash + + - name: Setup Pages + uses: actions/configure-pages@v5 + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: 'gh-sources/' + + - name: Deploy to GitHub Pages + if: github.ref == 'refs/heads/master' + uses: actions/deploy-pages@v4 diff --git a/3rdparty/libshv b/3rdparty/libshv index e2b69fa..365fe0b 160000 --- a/3rdparty/libshv +++ b/3rdparty/libshv @@ -1 +1 @@ -Subproject commit e2b69fa7f16173ce036d193dd2b1288c5d463567 +Subproject commit 365fe0b99001c05fbc6486a1ff07cb4a44e21ccb diff --git a/CMakeLists.txt b/CMakeLists.txt index 73049df..da0b3c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,7 @@ if(SHVSPY_USE_LOCAL_LIBSHV) else() set(WITH_BROKER OFF CACHE BOOL "") set(LIBSHV_USE_QT6 "${SHVSPY_USE_QT6}" CACHE BOOL "") - add_subdirectory(3rdparty/libshv) + add_subdirectory(3rdparty/libshv SYSTEM) endif() if(NOT TARGET libshv::libshvvisu) diff --git a/README.md b/README.md index db48394..c68f11e 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ Qt GUI tool for shvbroker administration and browsing image +## ShvSpy in the web browser +ShvSpy for the browser is available at https://silicon-heaven.github.io/shvspy. + ## Graph view short-cuts | short-cut | action | |-----------|--------| diff --git a/shvspy/CMakeLists.txt b/shvspy/CMakeLists.txt index 8c0e456..2e8d6c0 100644 --- a/shvspy/CMakeLists.txt +++ b/shvspy/CMakeLists.txt @@ -32,7 +32,7 @@ qt_add_executable(shvspy config/config.qrc ) -if(USE_QT6 AND NOT EMSCRIPTEN) +if(SHVSPY_USE_QT6 AND NOT EMSCRIPTEN) target_link_libraries(shvspy PRIVATE libshv::libshvvisu Qt::NetworkAuth) target_compile_definitions(shvspy PRIVATE "WITH_AZURE_SUPPORT") else() diff --git a/shvspy/src/accessmodel/accessitemdelegate.cpp b/shvspy/src/accessmodel/accessitemdelegate.cpp index 72beeb2..4514f3b 100644 --- a/shvspy/src/accessmodel/accessitemdelegate.cpp +++ b/shvspy/src/accessmodel/accessitemdelegate.cpp @@ -15,17 +15,17 @@ QWidget *AccessItemDelegate::createEditor(QWidget *parent, const QStyleOptionVie Q_UNUSED(option); Q_UNUSED(index); - QLineEdit *editor = new QLineEdit(parent); + auto *editor = new QLineEdit(parent); return editor; } void AccessItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { - QLineEdit *e = qobject_cast(editor); + auto *e = qobject_cast(editor); if (index.isValid() && e) { std::string val = e->text().trimmed().toStdString(); - if (index.column() == AccessModel::Columns::ColAccess) { + if (index.column() == AccessModel::Columns::ColAccess) { std::string err; shv::chainpack::RpcValue rv = shv::chainpack::RpcValue::fromCpon(val, &err); if (!err.empty()) { diff --git a/shvspy/src/accessmodel/accessmodel.cpp b/shvspy/src/accessmodel/accessmodel.cpp index 8f97058..d2f919b 100644 --- a/shvspy/src/accessmodel/accessmodel.cpp +++ b/shvspy/src/accessmodel/accessmodel.cpp @@ -30,11 +30,9 @@ AccessModel::AccessModel(QObject *parent) { } -AccessModel::~AccessModel() -{ -} +AccessModel::~AccessModel() = default; -void AccessModel::setRules(const shv::chainpack::RpcValue &role_rules) +void AccessModel::setRules(const cp::RpcValue &role_rules) { beginResetModel(); m_legacyRulesFormat = role_rules.isMap(); @@ -42,7 +40,7 @@ void AccessModel::setRules(const shv::chainpack::RpcValue &role_rules) endResetModel(); } -shv::chainpack::RpcValue AccessModel::rules() +cp::RpcValue AccessModel::rules() { if(m_legacyRulesFormat) return m_rules.toRpcValue_legacy(); @@ -82,10 +80,10 @@ QVariant AccessModel::data(const QModelIndex &ix, int role) const if(role == Qt::DisplayRole || role == Qt::EditRole) { switch (ix.column()) { - case Columns::ColPath: - return QString::fromStdString(rule.path); + case Columns::ColPath: return QString::fromStdString(rule.path); case Columns::ColMethod: return QString::fromStdString(rule.method); case Columns::ColAccess: return QString::fromStdString(rule.access); + default: break; } } else if(role == Qt::ToolTipRole) { @@ -94,6 +92,7 @@ QVariant AccessModel::data(const QModelIndex &ix, int role) const return tr("'path/to/node' or 'path/to/subtree/**' can be used here"); case Columns::ColMethod: return tr("Rule is applied to this method only or to any method if blank."); + default: break; } } diff --git a/shvspy/src/attributesmodel/attributesmodel.cpp b/shvspy/src/attributesmodel/attributesmodel.cpp index 116330e..8f10204 100644 --- a/shvspy/src/attributesmodel/attributesmodel.cpp +++ b/shvspy/src/attributesmodel/attributesmodel.cpp @@ -144,7 +144,7 @@ QVariant AttributesModel::data(const QModelIndex &ix, int role) const auto attrs = m_rows[static_cast(ix.row())][ColAttributes].asMap(); QStringList lines; for(const auto &kv : attrs) { - lines << tr("%1: %2").arg(kv.first.c_str()).arg(kv.second.toCpon().c_str()); + lines << tr("%1: %2").arg(kv.first.c_str(), kv.second.toCpon().c_str()); } return lines.join('\n'); } diff --git a/shvspy/src/attributesmodel/attributesmodel.h b/shvspy/src/attributesmodel/attributesmodel.h index 1dce3ba..0986e58 100644 --- a/shvspy/src/attributesmodel/attributesmodel.h +++ b/shvspy/src/attributesmodel/attributesmodel.h @@ -9,7 +9,7 @@ class ShvNodeItem; struct ShvMetaMethod; -namespace shv { namespace chainpack { class RpcMessage; }} +namespace shv::chainpack { class RpcMessage; } class AttributesModel : public QAbstractTableModel { diff --git a/shvspy/src/dlgaddeditrole.cpp b/shvspy/src/dlgaddeditrole.cpp index 61b9107..c23389c 100644 --- a/shvspy/src/dlgaddeditrole.cpp +++ b/shvspy/src/dlgaddeditrole.cpp @@ -282,7 +282,7 @@ void DlgAddEditRole::setRoles(const std::vector &roles) if(!roles.empty()) rls = std::accumulate(std::next(roles.begin()), roles.end(), QString::fromStdString(roles[0]), [](const QString &s1, const std::string &s2) -> QString { return s1 + ',' + QString::fromStdString(s2); }); - ui->leRoles->setText(rls); QString g; + ui->leRoles->setText(rls); } QString DlgAddEditRole::roleName() const diff --git a/shvspy/src/dlgaddedituser.cpp b/shvspy/src/dlgaddedituser.cpp index ef41e12..06c8168 100644 --- a/shvspy/src/dlgaddedituser.cpp +++ b/shvspy/src/dlgaddedituser.cpp @@ -42,7 +42,8 @@ DlgAddEditUser::~DlgAddEditUser() delete ui; } -static std::string sha1_hex(const std::string &s) +namespace { +std::string sha1_hex(const std::string &s) { QCryptographicHash hash(QCryptographicHash::Algorithm::Sha1); #if QT_VERSION_MAJOR >= 6 && QT_VERSION_MINOR >= 3 @@ -52,6 +53,7 @@ static std::string sha1_hex(const std::string &s) #endif return std::string(hash.result().toHex().constData()); } +} DlgAddEditUser::DialogType DlgAddEditUser::dialogType() { diff --git a/shvspy/src/dlgcallshvmethod.h b/shvspy/src/dlgcallshvmethod.h index 5144386..29a96eb 100644 --- a/shvspy/src/dlgcallshvmethod.h +++ b/shvspy/src/dlgcallshvmethod.h @@ -7,7 +7,7 @@ namespace Ui { class DlgCallShvMethod; } -namespace shv { namespace iotqt { namespace rpc { class ClientConnection; }}} +namespace shv::iotqt::rpc { class ClientConnection; } class DlgCallShvMethod : public QDialog { diff --git a/shvspy/src/dlgmountseditor.cpp b/shvspy/src/dlgmountseditor.cpp index 722463a..5c1fa30 100644 --- a/shvspy/src/dlgmountseditor.cpp +++ b/shvspy/src/dlgmountseditor.cpp @@ -163,7 +163,7 @@ void DlgMountsEditor::onRpcCallsFinished() m_dataModel->setRowCount(static_cast(m_mountPoints.count())); int i = 0; - for (const MountPointInfo &info : qAsConst(m_mountPoints)) { + for (const MountPointInfo &info : std::as_const(m_mountPoints)) { auto *id_item = new QStandardItem(info.id); id_item->setFlags(id_item->flags() & ~Qt::ItemIsEditable); m_dataModel->setItem(i, 0, id_item); @@ -214,8 +214,8 @@ void DlgMountsEditor::listMounts() const auto result = response.result(); const auto &res = result.asList(); - for (size_t i = 0; i < res.size(); i++){ - QString id = QString::fromStdString(res.at(i).asString()); + for (const auto & re : res){ + QString id = QString::fromStdString(re.asString()); m_mountPoints[id].id = id; getMountPointDefinition(id); } @@ -258,7 +258,7 @@ void DlgMountsEditor::getMountPointDefinition(const QString &id) void DlgMountsEditor::checkRpcCallsFinished() { - for (const auto &mount_point : qAsConst(m_mountPoints)) { + for (const auto &mount_point : std::as_const(m_mountPoints)) { if (mount_point.status != Ok) { return; } diff --git a/shvspy/src/dlgmountseditor.h b/shvspy/src/dlgmountseditor.h index 27c20d1..6a51349 100644 --- a/shvspy/src/dlgmountseditor.h +++ b/shvspy/src/dlgmountseditor.h @@ -18,7 +18,7 @@ class DlgMountsEditor : public QDialog public: explicit DlgMountsEditor(QWidget *parent, shv::iotqt::rpc::ClientConnection *rpc_connection); - ~DlgMountsEditor(); + ~DlgMountsEditor() override; void init(const std::string &acl_node_path); private: diff --git a/shvspy/src/dlgroleseditor.h b/shvspy/src/dlgroleseditor.h index c6fd997..8e69171 100644 --- a/shvspy/src/dlgroleseditor.h +++ b/shvspy/src/dlgroleseditor.h @@ -17,7 +17,7 @@ class DlgRolesEditor : public QDialog public: explicit DlgRolesEditor(QWidget *parent, shv::iotqt::rpc::ClientConnection *rpc_connection); - ~DlgRolesEditor(); + ~DlgRolesEditor() override; void init(const std::string &acl_node_path); private: diff --git a/shvspy/src/dlgselectroles.h b/shvspy/src/dlgselectroles.h index 81b7a3e..28b843b 100644 --- a/shvspy/src/dlgselectroles.h +++ b/shvspy/src/dlgselectroles.h @@ -17,7 +17,7 @@ class DlgSelectRoles : public QDialog public: explicit DlgSelectRoles(QWidget *parent); - ~DlgSelectRoles(); + ~DlgSelectRoles() override; void init(shv::iotqt::rpc::ClientConnection *rpc_connection, const std::string &acl_etc_node_path, const std::vector &roles); diff --git a/shvspy/src/dlgsubscriptionparameters.h b/shvspy/src/dlgsubscriptionparameters.h index 5e93660..bf6a52c 100644 --- a/shvspy/src/dlgsubscriptionparameters.h +++ b/shvspy/src/dlgsubscriptionparameters.h @@ -14,8 +14,8 @@ class DlgSubscriptionParameters : public QDialog Q_OBJECT public: - explicit DlgSubscriptionParameters(QWidget *parent = 0); - ~DlgSubscriptionParameters(); + explicit DlgSubscriptionParameters(QWidget *parent = nullptr); + ~DlgSubscriptionParameters() override; //void setSubscriptionParameters(const qfopcua::SubscriptionParameters ¶ms); //qfopcua::SubscriptionParameters subscriptionParameters(); diff --git a/shvspy/src/dlguserseditor.h b/shvspy/src/dlguserseditor.h index 4643c45..68e1174 100644 --- a/shvspy/src/dlguserseditor.h +++ b/shvspy/src/dlguserseditor.h @@ -20,7 +20,7 @@ class DlgUsersEditor : public QDialog public: explicit DlgUsersEditor(QWidget *parent, shv::iotqt::rpc::ClientConnection *rpc_connection); - ~DlgUsersEditor(); + ~DlgUsersEditor() override; void init(const std::string &path); private: diff --git a/shvspy/src/log/rpcnotificationsmodel.cpp b/shvspy/src/log/rpcnotificationsmodel.cpp index 1a22867..90cd735 100644 --- a/shvspy/src/log/rpcnotificationsmodel.cpp +++ b/shvspy/src/log/rpcnotificationsmodel.cpp @@ -20,7 +20,7 @@ QVariant RpcNotificationsModel::headerData(int section, Qt::Orientation orientat case ColShvPath: return tr("Source"); case ColMethod: return tr("Method"); case ColParams: return tr("Params"); - case ColCnt: break; + default: break; } } return QVariant(); diff --git a/shvspy/src/log/rpcnotificationsmodel.h b/shvspy/src/log/rpcnotificationsmodel.h index fb6ce0e..693d9a0 100644 --- a/shvspy/src/log/rpcnotificationsmodel.h +++ b/shvspy/src/log/rpcnotificationsmodel.h @@ -2,7 +2,7 @@ #include -namespace shv { namespace chainpack { class RpcMessage; }} +namespace shv::chainpack { class RpcMessage; } class RpcNotificationsModel : public shv::visu::LogTableModelBase { diff --git a/shvspy/src/main.cpp b/shvspy/src/main.cpp index d42ad8b..454b24f 100644 --- a/shvspy/src/main.cpp +++ b/shvspy/src/main.cpp @@ -116,8 +116,7 @@ int main(int argc, char *argv[]) shvInfo() << "======================================================================================"; shvInfo() << "Starting" << QCoreApplication::applicationName() << "ver." << QCoreApplication::applicationVersion() - << "PID:" << QCoreApplication::applicationPid() - << "build:" << __DATE__ << __TIME__; + << "PID:" << QCoreApplication::applicationPid(); #ifdef GIT_COMMIT shvInfo() << "GIT commit:" << SHV_EXPAND_AND_QUOTE(GIT_COMMIT); #endif diff --git a/shvspy/src/mainwindow.cpp b/shvspy/src/mainwindow.cpp index 198c973..7e99285 100644 --- a/shvspy/src/mainwindow.cpp +++ b/shvspy/src/mainwindow.cpp @@ -328,7 +328,7 @@ void MainWindow::onTreeServers_customContextMenuRequested(const QPoint &pos) } else { m->popup(ui->treeServers->viewport()->mapToGlobal(pos)); - connect(m, &QMenu::triggered, this, [=, this](QAction *a) { + connect(m, &QMenu::triggered, this, [this, a_reloadNode, a_subscribeNode, a_callShvMethod, a_usersEditor, a_rolesEditor, a_mountsEditor, m](QAction *a) { //shvInfo() << "MENU ACTION:" << a; if(a == a_reloadNode) { ShvNodeItem *nd = TheApp::instance()->serverTreeModel()->itemFromIndex(ui->treeServers->currentIndex()); @@ -452,7 +452,7 @@ void MainWindow::editMethodParameters(const QModelIndex &ix) QString method = TheApp::instance()->attributesModel()->method(ix.row()); auto *dlg = new MethodParametersDialog(path, method, rv, this); dlg->setWindowTitle(tr("Parameters")); - connect(dlg, &QDialog::finished, this, [=, this](int result) { + connect(dlg, &QDialog::finished, this, [this, dlg, ix](int result) { if (result == QDialog::Accepted) { cp::RpcValue val = dlg->value(); if (val.isValid()) { @@ -477,7 +477,7 @@ void MainWindow::editStringParameter(const QModelIndex &ix) dlg->setWindowTitle(tr("Parameters")); dlg->setReadOnly(false); dlg->setText(cpon); - connect(dlg, &QDialog::finished, this, [=, this](int result) { + connect(dlg, &QDialog::finished, this, [this, dlg, ix](int result) { if (result == QDialog::Accepted) { auto rv = cp::RpcValue(dlg->text().toStdString()); auto cpon = QString::fromStdString(rv.toCpon()); @@ -498,7 +498,7 @@ void MainWindow::editCponParameters(const QModelIndex &ix) dlg->setReadOnly(false); dlg->setValidateContent(true); dlg->setText(cpon); - connect(dlg, &QDialog::finished, this, [=, this](int result) { + connect(dlg, &QDialog::finished, this, [this, dlg, ix](int result) { if (result == QDialog::Accepted) { auto cpon = dlg->text(); ui->tblAttributes->model()->setData(ix, cpon, Qt::EditRole); @@ -631,7 +631,7 @@ void MainWindow::editServer(ShvBrokerNodeItem *srv, bool copy_server) } auto *dlg = new DlgBrokerProperties(this); dlg->setBrokerProperties(broker_props); - connect(dlg, &QDialog::finished, this, [=, this](int result) { + connect(dlg, &QDialog::finished, this, [this, dlg, srv, copy_server](int result) { if(result == QDialog::Accepted) { QVariantMap broker_props = dlg->brokerProperties(); if(!srv || copy_server) diff --git a/shvspy/src/methodparametersdialog.cpp b/shvspy/src/methodparametersdialog.cpp index 975cbef..97828ac 100644 --- a/shvspy/src/methodparametersdialog.cpp +++ b/shvspy/src/methodparametersdialog.cpp @@ -12,12 +12,14 @@ namespace cp = shv::chainpack; -static int TAB_INDEX_SINGLE_PARAMETER = 0; -static int TAB_INDEX_PARAMETER_MAP = 1; -static int TAB_INDEX_PARAMETER_LIST = 2; -static int TAB_INDEX_CPON = 3; +namespace { +const int TAB_INDEX_SINGLE_PARAMETER = 0; +const int TAB_INDEX_PARAMETER_MAP = 1; +const int TAB_INDEX_PARAMETER_LIST = 2; +const int TAB_INDEX_CPON = 3; +} -QVector MethodParametersDialog::m_supportedTypes { +const QVector MethodParametersDialog::m_supportedTypes { cp::RpcValue::Type::String, cp::RpcValue::Type::Int, cp::RpcValue::Type::UInt, @@ -32,9 +34,7 @@ MethodParametersDialog::MethodParametersDialog(const QString &path, const QStrin , m_syntaxCheckTimer(this) , m_path(path) , m_method(method) - , m_usedParamsWidget(nullptr) , m_currentTabIndex(TAB_INDEX_CPON) - , m_cponEdited(false) { shvLogFuncFrame() << "method:" << method << "params:" << params.toCpon(); ui->setupUi(this); @@ -56,7 +56,7 @@ MethodParametersDialog::MethodParametersDialog(const QString &path, const QStrin connect(ui->parameterListTable, &QTableWidget::currentCellChanged, this, &MethodParametersDialog::onListCurrentCellChanged); connect(ui->parameterMapTable, &QTableWidget::currentCellChanged, this, &MethodParametersDialog::onMapCurrentCellChanged); connect(ui->rawCponEdit, &QPlainTextEdit::textChanged, &m_syntaxCheckTimer, QOverload<>::of(&QTimer::start)); - connect(ui->rawCponEdit, &QPlainTextEdit::textChanged, [this]() { + connect(ui->rawCponEdit, &QPlainTextEdit::textChanged, this, [this]() { m_cponEdited = true; }); @@ -96,18 +96,18 @@ cp::RpcValue MethodParametersDialog::value() const if (ui->tabWidget->currentIndex() == TAB_INDEX_SINGLE_PARAMETER) { return singleParamValue(); } - else if (ui->tabWidget->currentIndex() == TAB_INDEX_PARAMETER_MAP) { + if (ui->tabWidget->currentIndex() == TAB_INDEX_PARAMETER_MAP) { return mapParamValue(); } if (ui->tabWidget->currentIndex() == TAB_INDEX_PARAMETER_LIST) { return listParamValue(); } - else if (ui->tabWidget->currentIndex() == TAB_INDEX_CPON) { + if (ui->tabWidget->currentIndex() == TAB_INDEX_CPON) { std::string cpon = ui->rawCponEdit->toPlainText().toStdString(); - if (cpon.size()) { + if (!cpon.empty()) { std::string err; cp::RpcValue val = cp::RpcValue::fromCpon(ui->rawCponEdit->toPlainText().toStdString(), &err); - if (err.size() == 0) { + if (err.empty()) { return val; } } @@ -151,7 +151,7 @@ void MethodParametersDialog::newMapParameter(const QString &key, const cp::RpcVa ui->parameterMapTable->setRowCount(row + 1); ui->parameterMapTable->setItem(row, 0, new QTableWidgetItem(key)); - QComboBox *combo = new QComboBox(this); + auto *combo = new QComboBox(this); ui->parameterMapTable->setCellWidget(row, 1, combo); for (cp::RpcValue::Type t : m_supportedTypes) { combo->addItem(cp::RpcValue::typeToName(t), static_cast(t)); @@ -172,7 +172,7 @@ void MethodParametersDialog::newMapParameter(const QString &key, const cp::RpcVa combo->setCurrentIndex(index); switchToString(ui->parameterMapTable, row, 2, m_mapValueGetters, m_mapValueSetters); } - connect(combo, QOverload::of(&QComboBox::currentIndexChanged), [this, combo, row](int index) { + connect(combo, QOverload::of(&QComboBox::currentIndexChanged), this, [this, combo, row](int index) { auto t = static_cast(combo->itemData(index).toInt()); switchByType(t, ui->parameterMapTable, row, 2, m_mapValueGetters, m_mapValueSetters); }); @@ -183,7 +183,7 @@ void MethodParametersDialog::newListParameter(const cp::RpcValue ¶m) int row = ui->parameterListTable->rowCount(); ui->parameterListTable->setRowCount(row + 1); - QComboBox *combo = new QComboBox(this); + auto *combo = new QComboBox(this); ui->parameterListTable->setCellWidget(row, 0, combo); for (cp::RpcValue::Type t : m_supportedTypes) { combo->addItem(cp::RpcValue::typeToName(t), static_cast(t)); @@ -204,7 +204,7 @@ void MethodParametersDialog::newListParameter(const cp::RpcValue ¶m) combo->setCurrentIndex(index); switchToString(ui->parameterListTable, row, 1, m_listValueGetters, m_listValueSetters); } - connect(combo, QOverload::of(&QComboBox::currentIndexChanged), [this, combo, row](int index) { + connect(combo, QOverload::of(&QComboBox::currentIndexChanged), this, [this, combo, row](int index) { auto t = static_cast(combo->itemData(index).toInt()); switchByType(t, ui->parameterListTable, row, 1, m_listValueGetters, m_listValueSetters); }); @@ -291,7 +291,7 @@ bool MethodParametersDialog::tryParseMapParams(const cp::RpcValue ¶ms) void MethodParametersDialog::switchToBool(QTableWidget *table, int row, int col, QVector &getters, QVector &setters) { - QCheckBox *checkbox = new QCheckBox(this); + auto *checkbox = new QCheckBox(this); table->setCellWidget(row, col, checkbox); getters[row] = [checkbox]() { return cp::RpcValue(checkbox->isChecked() ? true : false); @@ -303,7 +303,7 @@ void MethodParametersDialog::switchToBool(QTableWidget *table, int row, int col, void MethodParametersDialog::switchToInt(QTableWidget *table, int row, int col, QVector &getters, QVector &setters) { - QLineEdit *line_edit = new QLineEdit(this); + auto *line_edit = new QLineEdit(this); table->setCellWidget(row, col, line_edit); line_edit->setValidator(new QIntValidator(line_edit)); getters[row] = [line_edit]() { @@ -316,7 +316,7 @@ void MethodParametersDialog::switchToInt(QTableWidget *table, int row, int col, void MethodParametersDialog::switchToUInt(QTableWidget *table, int row, int col, QVector &getters, QVector &setters) { - QLineEdit *line_edit = new QLineEdit(this); + auto *line_edit = new QLineEdit(this); table->setCellWidget(row, col, line_edit); line_edit->setValidator(new QIntValidator(0, std::numeric_limits::max(), line_edit)); getters[row] = [line_edit]() { @@ -329,7 +329,7 @@ void MethodParametersDialog::switchToUInt(QTableWidget *table, int row, int col, void MethodParametersDialog::switchToString(QTableWidget *table, int row, int col, QVector &getters, QVector &setters) { - QLineEdit *line_edit = new QLineEdit(this); + auto *line_edit = new QLineEdit(this); table->setCellWidget(row, col, line_edit); getters[row] = [line_edit]() { return cp::RpcValue(line_edit->text().toStdString()); @@ -341,9 +341,9 @@ void MethodParametersDialog::switchToString(QTableWidget *table, int row, int co void MethodParametersDialog::switchToDouble(QTableWidget *table, int row, int col, QVector &getters, QVector &setters) { - QLineEdit *line_edit = new QLineEdit(this); + auto *line_edit = new QLineEdit(this); table->setCellWidget(row, col, line_edit); - QDoubleValidator *v = new QDoubleValidator(line_edit); + auto *v = new QDoubleValidator(line_edit); v->setLocale(QLocale::C); line_edit->setValidator(v); getters[row] = [line_edit]() { @@ -356,12 +356,12 @@ void MethodParametersDialog::switchToDouble(QTableWidget *table, int row, int co void MethodParametersDialog::switchToDateTime(QTableWidget *table, int row, int col, QVector &getters, QVector &setters) { - QWidget *datetime_widget = new QWidget(this); - QDateTimeEdit *edit = new QDateTimeEdit(datetime_widget); + auto *datetime_widget = new QWidget(this); + auto *edit = new QDateTimeEdit(datetime_widget); edit->setTimeSpec(Qt::TimeSpec::UTC); - QPushButton *today = new QPushButton("...", datetime_widget); + auto *today = new QPushButton("...", datetime_widget); today->setFixedWidth(20); - QHBoxLayout *layout = new QHBoxLayout; + auto *layout = new QHBoxLayout; layout->setContentsMargins(0,0,0,0); layout->setSpacing(0); layout->addWidget(edit); @@ -370,7 +370,7 @@ void MethodParametersDialog::switchToDateTime(QTableWidget *table, int row, int edit->setDisplayFormat("dd.MM.yyyy HH:mm:ss"); edit->setCalendarPopup(true); table->setCellWidget(row, col, datetime_widget); - connect(today, &QPushButton::clicked, [edit]() { + connect(today, &QPushButton::clicked, edit, [edit]() { edit->setDateTime(QDateTime::currentDateTime()); }); getters[row] = [edit]() { @@ -459,13 +459,13 @@ void MethodParametersDialog::switchToMap() (m_currentTabIndex == TAB_INDEX_PARAMETER_LIST && ui->parameterListTable->isHidden() && m_cponEdited) || (m_currentTabIndex == TAB_INDEX_SINGLE_PARAMETER && ui->singleParameterTable->isHidden() && m_cponEdited)) { std::string cpon = ui->rawCponEdit->toPlainText().toStdString(); - if (cpon.size() == 0) { + if (cpon.empty()) { parsed = true; } else { std::string err; cp::RpcValue val = cp::RpcValue::fromCpon(cpon, &err); - if (err.size() == 0) { + if (err.empty()) { parsed = tryParseMapParams(val); } } @@ -499,13 +499,13 @@ void MethodParametersDialog::switchToList() (m_currentTabIndex == TAB_INDEX_PARAMETER_MAP && ui->parameterMapTable->isHidden() && m_cponEdited) || (m_currentTabIndex == TAB_INDEX_SINGLE_PARAMETER && ui->singleParameterTable->isHidden() && m_cponEdited)) { std::string cpon = ui->rawCponEdit->toPlainText().toStdString(); - if (cpon.size() == 0) { + if (cpon.empty()) { parsed = true; } else { std::string err; cp::RpcValue val = cp::RpcValue::fromCpon(cpon, &err); - if (err.size() == 0) { + if (err.empty()) { parsed = tryParseListParams(val); } } @@ -539,13 +539,13 @@ void MethodParametersDialog::switchToSingle() (m_currentTabIndex == TAB_INDEX_PARAMETER_MAP && ui->parameterMapTable->isHidden() && m_cponEdited) || (m_currentTabIndex == TAB_INDEX_PARAMETER_LIST && ui->parameterListTable->isHidden() && m_cponEdited)) { std::string cpon = ui->rawCponEdit->toPlainText().toStdString(); - if (cpon.size() == 0) { + if (cpon.empty()) { parsed = true; } else { std::string err; cp::RpcValue val = cp::RpcValue::fromCpon(cpon, &err); - if (err.size() == 0) { + if (err.empty()) { parsed = tryParseSingleParam(val); } } @@ -626,10 +626,10 @@ void MethodParametersDialog::onCurrentTabChanged(int index) void MethodParametersDialog::checkSyntax() { std::string cpon = ui->rawCponEdit->toPlainText().toStdString(); - if (cpon.size()) { + if (!cpon.empty()) { std::string err; cp::RpcValue val = cp::RpcValue::fromCpon(ui->rawCponEdit->toPlainText().toStdString(), &err); - if (err.size()) { + if (!err.empty()) { QPalette pal = ui->rawCponEdit->palette(); pal.setColor(QPalette::ColorRole::Text, Qt::red); ui->rawCponEdit->setPalette(pal); @@ -675,7 +675,7 @@ cp::RpcValue MethodParametersDialog::singleParamValue() const } cp::RpcValue val = m_singleValueGetters[0](); - if (val.isString() && val.asString().size() == 0) { + if (val.isString() && val.asString().empty()) { return cp::RpcValue(); } return val; diff --git a/shvspy/src/methodparametersdialog.h b/shvspy/src/methodparametersdialog.h index 0762146..8f2e486 100644 --- a/shvspy/src/methodparametersdialog.h +++ b/shvspy/src/methodparametersdialog.h @@ -21,7 +21,7 @@ class MethodParametersDialog : public QDialog public: explicit MethodParametersDialog(const QString &path, const QString &method, const shv::chainpack::RpcValue ¶ms, QWidget *parent = nullptr); - ~MethodParametersDialog(); + ~MethodParametersDialog() override; shv::chainpack::RpcValue value() const; @@ -78,11 +78,11 @@ class MethodParametersDialog : public QDialog QVector m_listValueSetters; QVector m_mapValueGetters; QVector m_mapValueSetters; - static QVector m_supportedTypes; + const static QVector m_supportedTypes; QTimer m_syntaxCheckTimer; QString m_path; QString m_method; - LastUsedParamsWidget *m_usedParamsWidget; + LastUsedParamsWidget *m_usedParamsWidget = nullptr; int m_currentTabIndex; - bool m_cponEdited; + bool m_cponEdited = false; }; diff --git a/shvspy/src/rolestreemodel/rolestreemodel.cpp b/shvspy/src/rolestreemodel/rolestreemodel.cpp index 018361c..94f96aa 100644 --- a/shvspy/src/rolestreemodel/rolestreemodel.cpp +++ b/shvspy/src/rolestreemodel/rolestreemodel.cpp @@ -55,7 +55,7 @@ void RolesTreeModel::load(shv::iotqt::rpc::ClientConnection *rpc_connection, con } } else{ - emit loadError(tr("Request timeout expired for method: %1 path: %2").arg("ls").arg(QString::fromStdString(acl_etc_roles_node_path))); + emit loadError(tr("Request timeout expired for method: %1 path: %2").arg("ls", QString::fromStdString(acl_etc_roles_node_path))); } }); @@ -95,7 +95,7 @@ void RolesTreeModel::loadRoles(shv::iotqt::rpc::ClientConnection *rpc_connection } } else{ - emit loadError(tr("Request timeout expired for method: %1 path: %2").arg(QString::fromStdString(VALUE_METHOD)).arg(QString::fromStdString(role_path))); + emit loadError(tr("Request timeout expired for method: %1 path: %2").arg(QString::fromStdString(VALUE_METHOD), QString::fromStdString(role_path))); } }); @@ -145,7 +145,12 @@ void RolesTreeModel::generateTree() QStandardItem *parent_item = invisibleRootItem(); - for (const QString &role_name: m_shvRoles.keys()){ +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + for (const auto &[role_name, role_value] : m_shvRoles.asKeyValueRange()){ +#else + for (const auto &role_name: m_shvRoles.keys()){ + const auto& role_value = m_shvRoles.value(role_name); +#endif QList row; auto *it = new QStandardItem(role_name); it->setData(role_name, NameRole); @@ -154,7 +159,7 @@ void RolesTreeModel::generateTree() row << it; parent_item->appendRow(row); - std::vector sub_roles = m_shvRoles.value(role_name); + std::vector sub_roles = role_value; QSet created_roles{role_name}; for (const auto &subrole : sub_roles) { diff --git a/shvspy/src/rolestreemodel/rolestreemodel.h b/shvspy/src/rolestreemodel/rolestreemodel.h index 7253760..a66640c 100644 --- a/shvspy/src/rolestreemodel/rolestreemodel.h +++ b/shvspy/src/rolestreemodel/rolestreemodel.h @@ -21,7 +21,7 @@ class RolesTreeModel : public QStandardItemModel Q_SIGNAL void loadError(QString error); protected: - virtual bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); + bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override; void loadRoles(shv::iotqt::rpc::ClientConnection *rpc_connection, const std::string &acl_etc_roles_node_path, QVector role_names); private: diff --git a/shvspy/src/servertreemodel/shvbrokernodeitem.cpp b/shvspy/src/servertreemodel/shvbrokernodeitem.cpp index 036dbb0..ca79be0 100644 --- a/shvspy/src/servertreemodel/shvbrokernodeitem.cpp +++ b/shvspy/src/servertreemodel/shvbrokernodeitem.cpp @@ -5,7 +5,6 @@ #include "../appclioptions.h" #include "../log/rpcnotificationsmodel.h" #include "../attributesmodel/attributesmodel.h" -#include "../brokerproperty.h" #include "../subscriptionsmodel/subscriptionsmodel.h" #include diff --git a/shvspy/src/servertreemodel/shvbrokernodeitem.h b/shvspy/src/servertreemodel/shvbrokernodeitem.h index f7c3c82..ac3d4ae 100644 --- a/shvspy/src/servertreemodel/shvbrokernodeitem.h +++ b/shvspy/src/servertreemodel/shvbrokernodeitem.h @@ -6,8 +6,8 @@ #include -namespace shv { namespace chainpack { class RpcValue; class RpcMessage; } } -namespace shv { namespace iotqt { namespace rpc { class ClientConnection; } } } +namespace shv::chainpack { class RpcValue; class RpcMessage; } +namespace shv::iotqt::rpc { class ClientConnection; } class ShvBrokerNodeItem : public ShvNodeItem { @@ -25,7 +25,7 @@ class ShvBrokerNodeItem : public ShvNodeItem OpenStatus openStatus() const {return m_openStatus;} - bool isOpen() {return openStatus() == OpenStatus::Connected;} + bool isOpen() const {return openStatus() == OpenStatus::Connected;} void open(); void close(); //QString connectionErrorString(); diff --git a/shvspy/src/subscriptionsmodel/subscriptionsmodel.cpp b/shvspy/src/subscriptionsmodel/subscriptionsmodel.cpp index 1585ae5..8dca9f1 100644 --- a/shvspy/src/subscriptionsmodel/subscriptionsmodel.cpp +++ b/shvspy/src/subscriptionsmodel/subscriptionsmodel.cpp @@ -10,8 +10,6 @@ #include -namespace cp = shv::chainpack; - namespace { auto constexpr KEY_Path = "Path"; auto constexpr KEY_Method = "Method"; @@ -25,9 +23,7 @@ SubscriptionsModel::SubscriptionsModel(QObject *parent) { } -SubscriptionsModel::~SubscriptionsModel() -{ -} +SubscriptionsModel::~SubscriptionsModel() = default; int SubscriptionsModel::rowCount(const QModelIndex &parent) const { @@ -213,10 +209,10 @@ void SubscriptionsModel::onBrokerConnectedChanged(int broker_id, bool is_connect if(v.isValid()) { QVariantList subs = v.toList(); - for (int i = 0; i < subs.size(); i++) { - if (subs.at(i).toMap().contains(KEY_IsPermanent)){ + for (const auto & sub : subs) { + if (sub.toMap().contains(KEY_IsPermanent)){ SubscriptionsModel::Subscription s(broker_id, QString::fromStdString(nd->nodeId())); - s.setConfig(subs.at(i).toMap()); + s.setConfig(sub.toMap()); m_subscriptions.append(s); } @@ -224,7 +220,6 @@ void SubscriptionsModel::onBrokerConnectedChanged(int broker_id, bool is_connect } } else{ - QVariantList subs; for (auto i = m_subscriptions.size() -1; i >= 0; i--) { if (m_subscriptions.at(i).brokerId() == broker_id){ m_subscriptions.removeAt(i); diff --git a/shvspy/src/subscriptionsmodel/subscriptionsmodel.h b/shvspy/src/subscriptionsmodel/subscriptionsmodel.h index f59404c..eff84b6 100644 --- a/shvspy/src/subscriptionsmodel/subscriptionsmodel.h +++ b/shvspy/src/subscriptionsmodel/subscriptionsmodel.h @@ -7,7 +7,7 @@ #include #include -namespace shv { namespace chainpack { class RpcMessage; }} +namespace shv::chainpack { class RpcMessage; } class SubscriptionsModel : public QAbstractTableModel { diff --git a/shvspy/src/subscriptionsmodel/subscriptionstableitemdelegate.cpp b/shvspy/src/subscriptionsmodel/subscriptionstableitemdelegate.cpp index 904f2a9..cb86fe4 100644 --- a/shvspy/src/subscriptionsmodel/subscriptionstableitemdelegate.cpp +++ b/shvspy/src/subscriptionsmodel/subscriptionstableitemdelegate.cpp @@ -14,7 +14,7 @@ SubscriptionsTableItemDelegate::SubscriptionsTableItemDelegate(QObject *parent): QWidget *SubscriptionsTableItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (index.column() == SubscriptionsModel::Columns::ColMethod){ - QComboBox *editor = new QComboBox(parent); + auto *editor = new QComboBox(parent); editor->setEditable(true); editor->setInsertPolicy(QComboBox::NoInsert); editor->addItem(shv::chainpack::Rpc::SIG_VAL_CHANGED); @@ -30,7 +30,7 @@ QWidget *SubscriptionsTableItemDelegate::createEditor(QWidget *parent, const QSt void SubscriptionsTableItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { if (index.column() == SubscriptionsModel::Columns::ColMethod){ - QComboBox *cb = static_cast(editor); + auto *cb = static_cast(editor); cb->setCurrentText(index.data(Qt::DisplayRole).toString()); for(int i = 0; i < cb->count(); ++i){ @@ -47,7 +47,7 @@ void SubscriptionsTableItemDelegate::setEditorData(QWidget *editor, const QModel void SubscriptionsTableItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { if (index.column() == SubscriptionsModel::Columns::ColMethod){ - QComboBox *cb = static_cast(editor); + auto *cb = static_cast(editor); model->setData(index, cb->currentText(), Qt::EditRole); } else{ diff --git a/shvspy/src/subscriptionswidget.cpp b/shvspy/src/subscriptionswidget.cpp index a62b6c3..7771694 100644 --- a/shvspy/src/subscriptionswidget.cpp +++ b/shvspy/src/subscriptionswidget.cpp @@ -9,8 +9,6 @@ #include -namespace cp = shv::chainpack; - SubscriptionsWidget::SubscriptionsWidget(QWidget *parent) : QWidget(parent), ui(new Ui::SubscriptionsWidget) diff --git a/shvspy/src/subscriptionswidget.h b/shvspy/src/subscriptionswidget.h index d749072..d9f8d9f 100644 --- a/shvspy/src/subscriptionswidget.h +++ b/shvspy/src/subscriptionswidget.h @@ -20,7 +20,7 @@ class SubscriptionsWidget : public QWidget public: explicit SubscriptionsWidget(QWidget *parent = nullptr); - ~SubscriptionsWidget(); + ~SubscriptionsWidget() override; SubscriptionsModel &subscriptionsModel(); void onBrokerConnectedChanged(int broker_id, bool is_connected); diff --git a/shvspy/src/texteditdialog.cpp b/shvspy/src/texteditdialog.cpp index b463467..ad597ed 100644 --- a/shvspy/src/texteditdialog.cpp +++ b/shvspy/src/texteditdialog.cpp @@ -178,11 +178,10 @@ cp::RpcValue CponEditDialog::validateContent() ui->lblError->setVisible(false); return rv; } - else { - ui->lblError->setText(tr("Malformed Cpon: ") + QString::fromStdString(err)); - ui->lblError->setVisible(true); - return cp::RpcValue(); - } + + ui->lblError->setText(tr("Malformed Cpon: ") + QString::fromStdString(err)); + ui->lblError->setVisible(true); + return cp::RpcValue(); } void CponEditDialog::onBtCompactCponClicked() diff --git a/shvspy/src/texteditdialog.h b/shvspy/src/texteditdialog.h index ef0eee3..30410c7 100644 --- a/shvspy/src/texteditdialog.h +++ b/shvspy/src/texteditdialog.h @@ -2,7 +2,7 @@ #include -namespace shv { namespace chainpack { class RpcValue; }} +namespace shv::chainpack { class RpcValue; } namespace Ui { class TextEditDialog; diff --git a/shvspy/src/theapp.cpp b/shvspy/src/theapp.cpp index 13bc136..7e23f7e 100644 --- a/shvspy/src/theapp.cpp +++ b/shvspy/src/theapp.cpp @@ -31,10 +31,7 @@ TheApp::TheApp(int &argc, char **argv, AppCliOptions *cli_opts) m_errorLogModel = new shv::visu::ErrorLogModel(this); } -TheApp::~TheApp() -{ - //shvWarning() << __FUNCTION__; -} +TheApp::~TheApp() = default; void TheApp::loadSettings(QSettings &settings) { diff --git a/shvspy/src/theapp.h b/shvspy/src/theapp.h index 9090044..f39f7a3 100644 --- a/shvspy/src/theapp.h +++ b/shvspy/src/theapp.h @@ -12,7 +12,7 @@ class RpcNotificationsModel; class AppCliOptions; class QSettings; -namespace shv { namespace visu { class ErrorLogModel; } } +namespace shv::visu { class ErrorLogModel; } class TheApp : public QApplication {