diff --git a/3rdparty/QJsonModel/.gitignore b/3rdparty/QJsonModel/.gitignore deleted file mode 100644 index c45a326..0000000 --- a/3rdparty/QJsonModel/.gitignore +++ /dev/null @@ -1,155 +0,0 @@ -# macOS -.DS_Store - -# Windows -Thumbs.db -ehthumbs.db - -# Folder config file commonly created by Windows Explorer -Desktop.ini - -# Recycle Bin used on file shares and remote volumes -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# Thumbnail cache files created by Windows -Thumbs.db -Thumbs.db:encryptable - -# Windows Desktop Search -*.pst -*.ost -*.log - -# Compiled Object files, Static and Dynamic libs -*.o -*.lo -*.la -*.a -*.class -*.so -*.lib -*.dll -*.exe - -# Python -__pycache__/ -*.pyc -*.pyo -*.pyd - -# Java -*.class - -# Eclipse -.project -.classpath -.settings/ - -# IntelliJ -.idea/ - -# Visual Studio Code -.vscode/ -.vscodium/ - -# Node.js -node_modules/ - -# Jupyter Notebook -.ipynb_checkpoints/ - -# Thumbnails -Thumbs/ -Thumbs.db - -# macOS metadata -._* - -# TextMate -*.tmproj -*.tmproject -.tmtags - -# Sublime Text -*.sublime-workspace -*.sublime-project - -# VS Code directories -.vscode/ - -# CodeKit -.codekit-config.json - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Compiled files -*.com -*.class -*.dll -*.exe -*.o -*.so - -# Logs and databases -*.log -*.sql -*.sqlite -*.sqlite3 -*.xml - -# Binary and source packages -*.dmg -*.gz -*.iso -*.jar -*.tar -*.zip -*.rar -*.bin -*.war -*.ear -*.sar -*.bbl -*.pdf -*.xls -*.xlsx -*.ppt -*.pptx - -# Virtual environment -venv/ -env/ - -### Manually Entered -vim-debug/ -**/out/bin -**/out/lib -**/out/share -_deps -.cache/ -compile_commands.json -*.bak -docs/ -*.old - -# clangd cache -.cache/ -.vim/ -build/ -debug/ -realease/ -Release/ -Debug diff --git a/3rdparty/QJsonModel/CMakeLists.txt b/3rdparty/QJsonModel/CMakeLists.txt deleted file mode 100644 index c655342..0000000 --- a/3rdparty/QJsonModel/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -cmake_minimum_required(VERSION 3.26) - -project( - QJsonModel - VERSION 0.0.2 - LANGUAGES C CXX - # Save this for later: HOMEPAGE_URL - DESCRIPTION - "QJsonModel is a json tree model class for Qt6/C++17 based on QAbstractItemModel. MIT License." -) - -find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) -find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) - -if(MSVC) - string(APPEND CMAKE_CXX_FLAGS " /utf-8") - string(APPEND CMAKE_C_FLAGS " /utf-8") -endif() - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) - -add_library(QJsonModel STATIC include/details/QUtf8.hpp include/QJsonModel.hpp - QJsonModel.cpp) - -target_link_libraries(QJsonModel PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) diff --git a/3rdparty/QJsonModel/LICENSE b/3rdparty/QJsonModel/LICENSE deleted file mode 100644 index 97fdfda..0000000 --- a/3rdparty/QJsonModel/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2017 sacha schutz - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/3rdparty/QJsonModel/QJsonModel.cpp b/3rdparty/QJsonModel/QJsonModel.cpp deleted file mode 100644 index b31f20c..0000000 --- a/3rdparty/QJsonModel/QJsonModel.cpp +++ /dev/null @@ -1,518 +0,0 @@ -/* QJsonModel.cpp - * Copyright (c) 2011 SCHUTZ Sacha - * Copyright © 2024 Saul D. Beniquez - * - * License: - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -// NOLINTBEGIN - -#include "QJsonModel.hpp" -#include -#include -#include - -inline bool contains(const QStringList &list, const QString &value) { - for (auto val : list) - if (value.contains(val, Qt::CaseInsensitive)) - return true; - - return false; -} - -QJsonTreeItem::QJsonTreeItem(QJsonTreeItem *parent) { mParent = parent; } - -QJsonTreeItem::~QJsonTreeItem() { qDeleteAll(mChilds); } - -void QJsonTreeItem::appendChild(QJsonTreeItem *item) { mChilds.append(item); } - -QJsonTreeItem *QJsonTreeItem::child(int row) { return mChilds.value(row); } - -QJsonTreeItem *QJsonTreeItem::parent() { return mParent; } - -int QJsonTreeItem::childCount() const { return mChilds.count(); } - -int QJsonTreeItem::row() const { - if (mParent) - return mParent->mChilds.indexOf(const_cast(this)); - - return 0; -} - -void QJsonTreeItem::setKey(const QString &key) { mKey = key; } - -void QJsonTreeItem::setValue(const QVariant &value) { mValue = value; } - -void QJsonTreeItem::setType(const QJsonValue::Type &type) { mType = type; } - -QString QJsonTreeItem::key() const { return mKey; } - -QVariant QJsonTreeItem::value() const { return mValue; } - -QJsonValue::Type QJsonTreeItem::type() const { return mType; } - -QJsonTreeItem *QJsonTreeItem::load(const QJsonValue &value, - const QStringList &exceptions, - QJsonTreeItem *parent) { - QJsonTreeItem *rootItem = new QJsonTreeItem(parent); - rootItem->setKey("root"); - - if (value.isObject()) { - // Get all QJsonValue childs - const QStringList keys = - value.toObject().keys(); // To prevent clazy-range warning - for (const QString &key : keys) { - if (contains(exceptions, key)) { - continue; - } - QJsonValue v = value.toObject().value(key); - QJsonTreeItem *child = load(v, exceptions, rootItem); - child->setKey(key); - child->setType(v.type()); - rootItem->appendChild(child); - } - } else if (value.isArray()) { - // Get all QJsonValue childs - int index = 0; - const QJsonArray array = - value.toArray(); // To prevent clazy-range warning - for (const QJsonValue &v : array) { - QJsonTreeItem *child = load(v, exceptions, rootItem); - child->setKey(QString::number(index)); - child->setType(v.type()); - rootItem->appendChild(child); - ++index; - } - } else { - rootItem->setValue(value.toVariant()); - rootItem->setType(value.type()); - } - - return rootItem; -} - -//========================================================================= - -inline uchar hexdig(uint u) { return (u < 0xa ? '0' + u : 'a' + u - 0xa); } - -QByteArray escapedString(const QString &s) { - QByteArray ba(s.length(), Qt::Uninitialized); - uchar *cursor = - reinterpret_cast(const_cast(ba.constData())); - const uchar *ba_end = cursor + ba.length(); - const ushort *src = reinterpret_cast(s.constBegin()); - const ushort *const end = reinterpret_cast(s.constEnd()); - while (src != end) { - if (cursor >= ba_end - 6) { - // ensure we have enough space - int pos = cursor - reinterpret_cast(ba.constData()); - ba.resize(ba.size() * 2); - cursor = reinterpret_cast(ba.data()) + pos; - ba_end = - reinterpret_cast(ba.constData()) + ba.length(); - } - uint u = *src++; - if (u < 0x80) { - if (u < 0x20 || u == 0x22 || u == 0x5c) { - *cursor++ = '\\'; - switch (u) { - case 0x22: - *cursor++ = '"'; - break; - case 0x5c: - *cursor++ = '\\'; - break; - case 0x8: - *cursor++ = 'b'; - break; - case 0xc: - *cursor++ = 'f'; - break; - case 0xa: - *cursor++ = 'n'; - break; - case 0xd: - *cursor++ = 'r'; - break; - case 0x9: - *cursor++ = 't'; - break; - default: - *cursor++ = 'u'; - *cursor++ = '0'; - *cursor++ = '0'; - *cursor++ = hexdig(u >> 4); - *cursor++ = hexdig(u & 0xf); - } - } else { - *cursor++ = (uchar)u; - } - } else if (QUtf8Functions::toUtf8(u, cursor, src, - end) < 0) { - // failed to get valid utf8 use JSON escape sequence - *cursor++ = '\\'; - *cursor++ = 'u'; - *cursor++ = hexdig(u >> 12 & 0x0f); - *cursor++ = hexdig(u >> 8 & 0x0f); - *cursor++ = hexdig(u >> 4 & 0x0f); - *cursor++ = hexdig(u & 0x0f); - } - } - ba.resize(cursor - reinterpret_cast(ba.constData())); - return ba; -} - -QJsonModel::QJsonModel(QObject *parent) - : QAbstractItemModel(parent), mRootItem{new QJsonTreeItem} { - mHeaders.append(tr("key")); - mHeaders.append(tr("value")); -} - -QJsonModel::QJsonModel(const QString &fileName, QObject *parent) - : QAbstractItemModel(parent), mRootItem{new QJsonTreeItem} { - mHeaders.append(tr("key")); - mHeaders.append(tr("value")); - load(fileName); -} - -QJsonModel::QJsonModel(QIODevice *device, QObject *parent) - : QAbstractItemModel(parent), mRootItem{new QJsonTreeItem} { - mHeaders.append(tr("key")); - mHeaders.append(tr("value")); - load(device); -} - -QJsonModel::QJsonModel(const QByteArray &json, QObject *parent) - : QAbstractItemModel(parent), mRootItem{new QJsonTreeItem} { - mHeaders.append(tr("key")); - mHeaders.append(tr("value")); - loadJson(json); -} - -QJsonModel::~QJsonModel() { delete mRootItem; } - -bool QJsonModel::load(const QString &fileName) { - QFile file(fileName); - bool success = false; - if (file.open(QIODevice::ReadOnly)) { - success = load(&file); - file.close(); - } else { - success = false; - } - - return success; -} - -bool QJsonModel::load(QIODevice *device) { return loadJson(device->readAll()); } - -bool QJsonModel::loadJson(const QByteArray &json) { - QJsonParseError error; - auto const &jdoc = QJsonDocument::fromJson(json, &error); - - if (error.error != QJsonParseError::NoError) { - return false; - } - - if (!jdoc.isNull()) { - beginResetModel(); - delete mRootItem; - if (jdoc.isArray()) { - mRootItem = - QJsonTreeItem::load(QJsonValue(jdoc.array()), mExceptions); - mRootItem->setType(QJsonValue::Array); - - } else { - mRootItem = - QJsonTreeItem::load(QJsonValue(jdoc.object()), mExceptions); - mRootItem->setType(QJsonValue::Object); - } - endResetModel(); - return true; - } - - qDebug() << Q_FUNC_INFO << "cannot load json"; - return false; -} - -QVariant QJsonModel::data(const QModelIndex &index, int role) const { - if (!index.isValid()) - return {}; - - QJsonTreeItem *item = static_cast(index.internalPointer()); - - if (role == Qt::DisplayRole) { - if (index.column() == 0) - return QString("%1").arg(item->key()); - - if (index.column() == 1) - return item->value(); - } else if (Qt::EditRole == role) { - if (index.column() == 1) - return item->value(); - } - - return {}; -} - -bool QJsonModel::setData(const QModelIndex &index, const QVariant &value, - int role) { - int col = index.column(); - if (Qt::EditRole == role) { - if (col == 1) { - QJsonTreeItem *item = - static_cast(index.internalPointer()); - item->setValue(value); - emit dataChanged(index, index, {Qt::EditRole}); - return true; - } - } - - return false; -} - -QVariant QJsonModel::headerData(int section, Qt::Orientation orientation, - int role) const { - if (role != Qt::DisplayRole) - return {}; - - if (orientation == Qt::Horizontal) - return mHeaders.value(section); - else - return {}; -} - -QModelIndex QJsonModel::index(int row, int column, - const QModelIndex &parent) const { - if (!hasIndex(row, column, parent)) - return {}; - - QJsonTreeItem *parentItem; - - if (!parent.isValid()) - parentItem = mRootItem; - else - parentItem = static_cast(parent.internalPointer()); - - QJsonTreeItem *childItem = parentItem->child(row); - if (childItem) - return createIndex(row, column, childItem); - else - return {}; -} - -QModelIndex QJsonModel::parent(const QModelIndex &index) const { - if (!index.isValid()) - return {}; - - QJsonTreeItem *childItem = - static_cast(index.internalPointer()); - QJsonTreeItem *parentItem = childItem->parent(); - - if (parentItem == mRootItem) - return QModelIndex(); - - return createIndex(parentItem->row(), 0, parentItem); -} - -int QJsonModel::rowCount(const QModelIndex &parent) const { - QJsonTreeItem *parentItem; - if (parent.column() > 0) - return 0; - - if (!parent.isValid()) - parentItem = mRootItem; - else - parentItem = static_cast(parent.internalPointer()); - - return parentItem->childCount(); -} - -int QJsonModel::columnCount(const QModelIndex &parent) const { - Q_UNUSED(parent) - return 2; -} - -Qt::ItemFlags QJsonModel::flags(const QModelIndex &index) const { - int col = index.column(); - auto item = static_cast(index.internalPointer()); - - auto isArray = QJsonValue::Array == item->type(); - auto isObject = QJsonValue::Object == item->type(); - - if ((col == 1) && !(isArray || isObject)) - return Qt::ItemIsEditable | QAbstractItemModel::flags(index); - else - return QAbstractItemModel::flags(index); -} - -QByteArray QJsonModel::json(bool compact) { - auto jsonValue = genJson(mRootItem); - QByteArray json; - if (jsonValue.isNull()) - return json; - - if (jsonValue.isArray()) - arrayToJson(jsonValue.toArray(), json, 0, compact); - else - objectToJson(jsonValue.toObject(), json, 0, compact); - - return json; -} - -void QJsonModel::objectToJson(QJsonObject jsonObject, QByteArray &json, - int indent, bool compact) { - json += compact ? "{" : "{\n"; - objectContentToJson(jsonObject, json, indent + (compact ? 0 : 1), compact); - json += QByteArray(4 * indent, ' '); - json += compact ? "}" : "}\n"; -} -void QJsonModel::arrayToJson(QJsonArray jsonArray, QByteArray &json, int indent, - bool compact) { - json += compact ? "[" : "[\n"; - arrayContentToJson(jsonArray, json, indent + (compact ? 0 : 1), compact); - json += QByteArray(4 * indent, ' '); - json += compact ? "]" : "]\n"; -} - -void QJsonModel::arrayContentToJson(QJsonArray jsonArray, QByteArray &json, - int indent, bool compact) { - if (jsonArray.size() <= 0) - return; - - QByteArray indentString(4 * indent, ' '); - int i = 0; - while (1) { - json += indentString; - valueToJson(jsonArray.at(i), json, indent, compact); - if (++i == jsonArray.size()) { - if (!compact) - json += '\n'; - break; - } - json += compact ? "," : ",\n"; - } -} -void QJsonModel::objectContentToJson(QJsonObject jsonObject, QByteArray &json, - int indent, bool compact) { - if (jsonObject.size() <= 0) - return; - - QByteArray indentString(4 * indent, ' '); - int i = 0; - while (1) { - QString key = jsonObject.keys().at(i); - json += indentString; - json += '"'; - json += escapedString(key); - json += compact ? "\":" : "\": "; - valueToJson(jsonObject.value(key), json, indent, compact); - if (++i == jsonObject.size()) { - if (!compact) - json += '\n'; - break; - } - json += compact ? "," : ",\n"; - } -} - -void QJsonModel::valueToJson(QJsonValue jsonValue, QByteArray &json, int indent, - bool compact) { - QJsonValue::Type type = jsonValue.type(); - switch (type) { - case QJsonValue::Bool: - json += jsonValue.toBool() ? "true" : "false"; - break; - case QJsonValue::Double: { - const double d = jsonValue.toDouble(); - if (qIsFinite(d)) { - json += QByteArray::number(d, 'f', QLocale::FloatingPointShortest); - } else { - json += "null"; // +INF || -INF || NaN (see RFC4627#section2.4) - } - break; - } - case QJsonValue::String: - json += '"'; - json += escapedString(jsonValue.toString()); - json += '"'; - break; - case QJsonValue::Array: - json += compact ? "[" : "[\n"; - arrayContentToJson(jsonValue.toArray(), json, - indent + (compact ? 0 : 1), compact); - json += QByteArray(4 * indent, ' '); - json += ']'; - break; - case QJsonValue::Object: - json += compact ? "{" : "{\n"; - objectContentToJson(jsonValue.toObject(), json, - indent + (compact ? 0 : 1), compact); - json += QByteArray(4 * indent, ' '); - json += '}'; - break; - case QJsonValue::Null: - default: - json += "null"; - } -} - -void QJsonModel::addException(const QStringList &exceptions) { - mExceptions = exceptions; -} - -QJsonValue QJsonModel::genJson(QJsonTreeItem *item) const { - auto type = item->type(); - int nchild = item->childCount(); - - if (QJsonValue::Object == type) { - QJsonObject jo; - for (int i = 0; i < nchild; ++i) { - auto ch = item->child(i); - auto key = ch->key(); - jo.insert(key, genJson(ch)); - } - return jo; - } else if (QJsonValue::Array == type) { - QJsonArray arr; - for (int i = 0; i < nchild; ++i) { - auto ch = item->child(i); - arr.append(genJson(ch)); - } - return arr; - } else { - QJsonValue va; -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - switch (item->value().typeId()) { -#else - switch (item->value().userType()) { -#endif - case QMetaType::Bool: { - va = item->value().toBool(); - break; - } - default: - va = item->value().toString(); - break; - } - return va; - } -} diff --git a/3rdparty/QJsonModel/README.md b/3rdparty/QJsonModel/README.md deleted file mode 100644 index 2364fa5..0000000 --- a/3rdparty/QJsonModel/README.md +++ /dev/null @@ -1,56 +0,0 @@ -# QJsonModel -QJsonModel is a JSON tree model class for Qt6/C++17 based on QAbstractItemModel. - -QJsonModel was originally written by Sacha Shutz (https://github.com/dridk). - -This fork is also released under the MIT License. - - -![QJsonModel](https://gitea.beniquez.me/sdaveb/QJsonModel/raw/branch/master/screen.png) - -## Build Instructions - -### Build Tools -- CMake (version 3.21 or higher) -- C++17-compatible compiler - -### Building the Project -1. Clone the repository: - ``` - git clone - ``` - -2. Navigate to the project directory: - ``` - cd elemental-game - ``` -3. Configure your build system: - ```bash - cmake -B debug -G Unix Makefiles - # or - cmake -B debug -G Ninja # this is faster and more modern - ``` -4. Invoke your build system - ``` - cmake --build debug - ``` -### Usage - CMake - -You can add this library to your CMake projects using FetchContent() -or CPM_AddPackage(). - -Here's how to do it with CPM_AddPackage: - -``` -COMING SOON -``` - -### Usage - C++ - -#### -```cpp -QJsonModel * model = new QJsonModel; -QTreeView * view = new QTreeView; -view->setModel(model); -model->load("example.json") -``` diff --git a/3rdparty/QJsonModel/include/QJsonModel.hpp b/3rdparty/QJsonModel/include/QJsonModel.hpp deleted file mode 100644 index 6ab4605..0000000 --- a/3rdparty/QJsonModel/include/QJsonModel.hpp +++ /dev/null @@ -1,115 +0,0 @@ -/* QJsonModel.hpp - * Copyright (c) 2011 SCHUTZ Sacha - * Copyright © 2024 Saul D. Beniquez - * - * License: - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include -#include -#include -#include -#include - -#include "details/QUtf8.hpp" - -class QJsonModel; -class QJsonItem; - -class QJsonTreeItem { -public: - QJsonTreeItem(QJsonTreeItem *parent = nullptr); - ~QJsonTreeItem(); - void appendChild(QJsonTreeItem *item); - QJsonTreeItem *child(int row); - QJsonTreeItem *parent(); - int childCount() const; - int row() const; - void setKey(const QString &key); - void setValue(const QVariant &value); - void setType(const QJsonValue::Type &type); - QString key() const; - QVariant value() const; - QJsonValue::Type type() const; - - static QJsonTreeItem *load(const QJsonValue &value, - const QStringList &exceptions = {}, - QJsonTreeItem *parent = nullptr); - -protected: -private: - QString mKey; - QVariant mValue; - QJsonValue::Type mType; - QList mChilds; - QJsonTreeItem *mParent = nullptr; -}; - -//--------------------------------------------------- - -class QJsonModel : public QAbstractItemModel { - Q_OBJECT -public: - explicit QJsonModel(QObject *parent = nullptr); - QJsonModel(const QString &fileName, QObject *parent = nullptr); - QJsonModel(QIODevice *device, QObject *parent = nullptr); - QJsonModel(const QByteArray &json, QObject *parent = nullptr); - ~QJsonModel(); - bool load(const QString &fileName); - bool load(QIODevice *device); - bool loadJson(const QByteArray &json); - QVariant data(const QModelIndex &index, int role) const override; - bool setData(const QModelIndex &index, const QVariant &value, - int role = Qt::EditRole) override; - QVariant headerData(int section, Qt::Orientation orientation, - int role) const override; - QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const override; - QModelIndex parent(const QModelIndex &index) const override; - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - int columnCount(const QModelIndex &parent = QModelIndex()) const override; - Qt::ItemFlags flags(const QModelIndex &index) const override; - QByteArray json(bool compact = false); - QByteArray jsonToByte(QJsonValue jsonValue); - void objectToJson(QJsonObject jsonObject, QByteArray &json, int indent, - bool compact); - void arrayToJson(QJsonArray jsonArray, QByteArray &json, int indent, - bool compact); - void arrayContentToJson(QJsonArray jsonArray, QByteArray &json, int indent, - bool compact); - void objectContentToJson(QJsonObject jsonObject, QByteArray &json, - int indent, bool compact); - void valueToJson(QJsonValue jsonValue, QByteArray &json, int indent, - bool compact); - //! List of tags to skip during JSON parsing - void addException(const QStringList &exceptions); - -private: - QJsonValue genJson(QJsonTreeItem *) const; - QJsonTreeItem *mRootItem = nullptr; - QStringList mHeaders; - //! List of exceptions (e.g. comments). Case insensitive, compairs on - //! "contains". - QStringList mExceptions; -}; diff --git a/3rdparty/QJsonModel/include/details/QUtf8.hpp b/3rdparty/QJsonModel/include/details/QUtf8.hpp deleted file mode 100644 index a57ae72..0000000 --- a/3rdparty/QJsonModel/include/details/QUtf8.hpp +++ /dev/null @@ -1,194 +0,0 @@ -/* QUtf8.hpp - * Copyright © 2024 Saul D. Beniquez - * License: - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE - * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include - -namespace QUtf8Functions { -/// returns 0 on success; errors can only happen if \a u is a surrogate: -/// Error if \a u is a low surrogate; -/// if \a u is a high surrogate, Error if the next isn't a low one, -/// EndOfString if we run into the end of the string. -template -inline int toUtf8(ushort u, OutputPtr &dst, InputPtr &src, InputPtr end) { - if (!Traits::skipAsciiHandling && u < 0x80) { - // U+0000 to U+007F (US-ASCII) - one byte - Traits::appendByte(dst, uchar(u)); - return 0; - } else if (u < 0x0800) { - // U+0080 to U+07FF - two bytes - // first of two bytes - Traits::appendByte(dst, 0xc0 | uchar(u >> 6)); - } else { - if (!QChar::isSurrogate(u)) { - // U+0800 to U+FFFF (except U+D800-U+DFFF) - three bytes - if (!Traits::allowNonCharacters && QChar::isNonCharacter(u)) - return Traits::Error; - // first of three bytes - Traits::appendByte(dst, 0xe0 | uchar(u >> 12)); - } else { - // U+10000 to U+10FFFF - four bytes - // need to get one extra codepoint - if (Traits::availableUtf16(src, end) == 0) - return Traits::EndOfString; - ushort low = Traits::peekUtf16(src); - if (!QChar::isHighSurrogate(u)) - return Traits::Error; - if (!QChar::isLowSurrogate(low)) - return Traits::Error; - Traits::advanceUtf16(src); - uint ucs4 = QChar::surrogateToUcs4(u, low); - if (!Traits::allowNonCharacters && QChar::isNonCharacter(ucs4)) - return Traits::Error; - // first byte - Traits::appendByte(dst, 0xf0 | (uchar(ucs4 >> 18) & 0xf)); - // second of four bytes - Traits::appendByte(dst, 0x80 | (uchar(ucs4 >> 12) & 0x3f)); - // for the rest of the bytes - u = ushort(ucs4); - } - // second to last byte - Traits::appendByte(dst, 0x80 | (uchar(u >> 6) & 0x3f)); - } - // last byte - Traits::appendByte(dst, 0x80 | (u & 0x3f)); - return 0; -} -inline bool isContinuationByte(uchar b) { return (b & 0xc0) == 0x80; } -/// returns the number of characters consumed (including \a b) in case of -/// success; returns negative in case of error: Traits::Error or -/// Traits::EndOfString -template -inline int fromUtf8(uchar b, OutputPtr &dst, InputPtr &src, InputPtr end) { - int charsNeeded; - uint min_uc; - uint uc; - if (!Traits::skipAsciiHandling && b < 0x80) { - // US-ASCII - Traits::appendUtf16(dst, b); - return 1; - } - if (!Traits::isTrusted && Q_UNLIKELY(b <= 0xC1)) { - // an UTF-8 first character must be at least 0xC0 - // however, all 0xC0 and 0xC1 first bytes can only produce overlong - // sequences - return Traits::Error; - } else if (b < 0xe0) { - charsNeeded = 2; - min_uc = 0x80; - uc = b & 0x1f; - } else if (b < 0xf0) { - charsNeeded = 3; - min_uc = 0x800; - uc = b & 0x0f; - } else if (b < 0xf5) { - charsNeeded = 4; - min_uc = 0x10000; - uc = b & 0x07; - } else { - // the last Unicode character is U+10FFFF - // it's encoded in UTF-8 as "\xF4\x8F\xBF\xBF" - // therefore, a byte higher than 0xF4 is not the UTF-8 first byte - return Traits::Error; - } - int bytesAvailable = Traits::availableBytes(src, end); - if (Q_UNLIKELY(bytesAvailable < charsNeeded - 1)) { - // it's possible that we have an error instead of just unfinished bytes - if (bytesAvailable > 0 && !isContinuationByte(Traits::peekByte(src, 0))) - return Traits::Error; - if (bytesAvailable > 1 && !isContinuationByte(Traits::peekByte(src, 1))) - return Traits::Error; - return Traits::EndOfString; - } - // first continuation character - b = Traits::peekByte(src, 0); - if (!isContinuationByte(b)) - return Traits::Error; - uc <<= 6; - uc |= b & 0x3f; - if (charsNeeded > 2) { - // second continuation character - b = Traits::peekByte(src, 1); - if (!isContinuationByte(b)) - return Traits::Error; - uc <<= 6; - uc |= b & 0x3f; - if (charsNeeded > 3) { - // third continuation character - b = Traits::peekByte(src, 2); - if (!isContinuationByte(b)) - return Traits::Error; - uc <<= 6; - uc |= b & 0x3f; - } - } - // we've decoded something; safety-check it - if (!Traits::isTrusted) { - if (uc < min_uc) - return Traits::Error; - if (QChar::isSurrogate(uc) || uc > QChar::LastValidCodePoint) - return Traits::Error; - if (!Traits::allowNonCharacters && QChar::isNonCharacter(uc)) - return Traits::Error; - } - // write the UTF-16 sequence - if (!QChar::requiresSurrogates(uc)) { - // UTF-8 decoded and no surrogates are required - // detach if necessary - Traits::appendUtf16(dst, ushort(uc)); - } else { - // UTF-8 decoded to something that requires a surrogate pair - Traits::appendUcs4(dst, uc); - } - Traits::advanceByte(src, charsNeeded - 1); - return charsNeeded; -} -} // namespace QUtf8Functions - -struct QUtf8BaseTraits { - static const bool isTrusted = false; - static const bool allowNonCharacters = true; - static const bool skipAsciiHandling = false; - static const int Error = -1; - static const int EndOfString = -2; - static bool isValidCharacter(uint u) { return int(u) >= 0; } - static void appendByte(uchar *&ptr, uchar b) { *ptr++ = b; } - static uchar peekByte(const uchar *ptr, int n = 0) { return ptr[n]; } - static qptrdiff availableBytes(const uchar *ptr, const uchar *end) { - return end - ptr; - } - static void advanceByte(const uchar *&ptr, int n = 1) { ptr += n; } - static void appendUtf16(ushort *&ptr, ushort uc) { *ptr++ = uc; } - static void appendUcs4(ushort *&ptr, uint uc) { - appendUtf16(ptr, QChar::highSurrogate(uc)); - appendUtf16(ptr, QChar::lowSurrogate(uc)); - } - static ushort peekUtf16(const ushort *ptr, int n = 0) { return ptr[n]; } - static qptrdiff availableUtf16(const ushort *ptr, const ushort *end) { - return end - ptr; - } - static void advanceUtf16(const ushort *&ptr, int n = 1) { ptr += n; } - // it's possible to output to UCS-4 too - static void appendUtf16(uint *&ptr, ushort uc) { *ptr++ = uc; } - static void appendUcs4(uint *&ptr, uint uc) { *ptr++ = uc; } -}; diff --git a/3rdparty/QJsonModel/screen.png b/3rdparty/QJsonModel/screen.png deleted file mode 100644 index 6d904d3..0000000 Binary files a/3rdparty/QJsonModel/screen.png and /dev/null differ diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dd9a42..08988df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,6 @@ add_subdirectory(3rdparty/QHexView) add_subdirectory(3rdparty/WingCodeEdit) add_subdirectory(3rdparty/Qt-Advanced-Docking-System) add_subdirectory(3rdparty/AngelScript/sdk/angelscript/projects/cmake) -add_subdirectory(3rdparty/QJsonModel) set(ANGEL_SCRIPT_ADDON_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/AngelScript/sdk/add_on") @@ -272,7 +271,6 @@ set(CLASS_SRC src/class/dockcomponentsfactory.cpp src/class/diffutil.h src/class/diffutil.cpp - src/class/clickcallback.h src/class/crashhandler.h src/class/crashhandler.cpp src/class/pluginsystem.h @@ -315,8 +313,6 @@ set(MODEL_SRC src/model/metadatamodel.cpp src/model/checksummodel.h src/model/checksummodel.cpp - src/model/qjsontablemodel.h - src/model/qjsontablemodel.cpp src/model/dbgcallstackmodel.h src/model/dbgcallstackmodel.cpp src/model/dbgvarshowmodel.h @@ -380,7 +376,6 @@ endforeach() set(TRANSLATION_PATH ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/QConsoleWidget ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/QHexView - ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/QJsonModel ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/Qt-Advanced-Docking-System/src ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/QWingRibbon ${CMAKE_CURRENT_SOURCE_DIR}/src) @@ -514,7 +509,6 @@ target_link_libraries( WingPlugin QHexView WingCodeEdit - QJsonModel angelscript qtadvanceddocking-qt${QT_VERSION_MAJOR}) diff --git a/TestPlugin/CMakeLists.txt b/TestPlugin/CMakeLists.txt index 9ba9585..6f74ef3 100644 --- a/TestPlugin/CMakeLists.txt +++ b/TestPlugin/CMakeLists.txt @@ -61,8 +61,6 @@ add_library( ctltestform.h ctltestform.cpp ctltestform.ui - testtablemodel.h - testtablemodel.cpp testsettingpage.h testsettingpage.cpp testwingeditorviewwidget.h @@ -91,4 +89,5 @@ if(TEST_MODE) ${WINGHEX_PLUGIN_PATH}) endif() -target_link_libraries(TestPlugin PRIVATE Qt${QT_VERSION_MAJOR}::Widgets WingPlugin) +target_link_libraries(TestPlugin PRIVATE Qt${QT_VERSION_MAJOR}::Widgets + WingPlugin) diff --git a/TestPlugin/lang/TestPlugin_zh_CN.ts b/TestPlugin/lang/TestPlugin_zh_CN.ts index 67f2e55..d536183 100644 --- a/TestPlugin/lang/TestPlugin_zh_CN.ts +++ b/TestPlugin/lang/TestPlugin_zh_CN.ts @@ -185,12 +185,12 @@ 控制器 - + Others 其他 - + Other APIs should be Test With Script 其他 API 应该用脚本测试,不提供可视化方式 @@ -231,7 +231,6 @@ - Type 类型 @@ -266,32 +265,6 @@ Color 颜色 - - - DataVisual - 数据可视化 - - - - - UpdateTextTreeError - 更新文本树失败 - - - - UpdateTextListByModelError - 通过模型更新文本列表失败 - - - - UpdateTextTableByModelError - 通过模型更新文本表格失败 - - - - UpdateTextTreeByModelError - 通过模型更新文本树失败 - TestPlugin diff --git a/TestPlugin/testform.cpp b/TestPlugin/testform.cpp index 0716ee8..267ea27 100644 --- a/TestPlugin/testform.cpp +++ b/TestPlugin/testform.cpp @@ -24,7 +24,6 @@ #include "ctltestform.h" #include "readertestform.h" -#include "testtablemodel.h" #include #include @@ -37,8 +36,6 @@ TestForm::TestForm(WingHex::IWingPlugin *plg, QWidget *parent) : WingHex::WingPluginWidget(plg, parent), ui(new Ui::TestForm) { ui->setupUi(this); - ui->teDataVisual->setAcceptRichText(false); - ui->saReader->widget()->layout()->addWidget( new ReaderTestForm(plg, ui->tbReaderLogger, this)); ui->saCtl->widget()->layout()->addWidget( @@ -56,10 +53,6 @@ TestForm::TestForm(WingHex::IWingPlugin *plg, QWidget *parent) ui->lblauthor->setPixmap( WingHex::HOSTRESPIMG(QStringLiteral("author"), QStringLiteral(".jpg"))); - - _click = std::bind(&TestForm::onDVClicked, this, std::placeholders::_1); - _dblclick = - std::bind(&TestForm::onDVDoubleClicked, this, std::placeholders::_1); } TestForm::~TestForm() { delete ui; } @@ -153,16 +146,6 @@ QFileDialog::Options TestForm::getFileDialogOptions() const { return options; } -void TestForm::onDVClicked(const QModelIndex &index) { - logWarn(QStringLiteral("[Test - Click] ") + - index.model()->data(index).toString()); -} - -void TestForm::onDVDoubleClicked(const QModelIndex &index) { - msgWarning(this, QStringLiteral("Test - DoubleClick"), - index.model()->data(index).toString()); -} - void TestForm::on_btnSendLog_clicked() { auto txt = ui->leLogText->text(); switch (Level(ui->cbLogLevel->currentIndex())) { @@ -323,69 +306,6 @@ void TestForm::on_btnGetColor_clicked() { } } -void TestForm::on_btnText_2_clicked() { - dataVisualText(ui->teDataVisual->toPlainText(), QStringLiteral("TestForm")); -} - -void TestForm::on_btnTextList_clicked() { - auto txts = ui->teDataVisual->toPlainText().split('\n'); - dataVisualTextList(txts, QStringLiteral("TestForm"), _click, _dblclick); -} - -void TestForm::on_btnTextTree_clicked() { - auto ret = - dataVisualTextTree(ui->teDataVisual->toPlainText(), - QStringLiteral("TestForm"), _click, _dblclick); - if (!ret) { - msgCritical(this, QStringLiteral("Test"), tr("UpdateTextTreeError")); - } -} - -void TestForm::on_btnTextTable_clicked() { - auto ret = dataVisualTextTable( - ui->teDataVisual->toPlainText(), {"wingsummer", "wingsummer"}, {}, - QStringLiteral("TestForm"), _click, _dblclick); - if (!ret) { - msgCritical(this, QStringLiteral("Test"), tr("UpdateTextTreeError")); - } -} - -void TestForm::on_btnTextListByModel_clicked() { - auto model = new QStringListModel; - QStringList buffer; - for (int i = 0; i < WingHex::SDKVERSION; ++i) { - buffer.append("wingsummer" % QString::number(i)); - } - model->setStringList(buffer); - auto ret = dataVisualTextListByModel(model, QStringLiteral("TestForm"), - _click, _dblclick); - if (!ret) { - msgCritical(this, QStringLiteral("Test"), - tr("UpdateTextListByModelError")); - } -} - -void TestForm::on_btnTextTableByModel_clicked() { - auto model = new TestTableModel; - auto ret = dataVisualTextTableByModel(model, QStringLiteral("TestForm"), - _click, _dblclick); - if (!ret) { - msgCritical(this, QStringLiteral("Test"), - tr("UpdateTextTableByModelError")); - } -} - -void TestForm::on_btnTextTreeByModel_clicked() { - auto model = new QFileSystemModel; - model->setRootPath(QDir::currentPath()); - auto ret = dataVisualTextTreeByModel(model, QStringLiteral("TestForm"), - _click, _dblclick); - if (!ret) { - msgCritical(this, QStringLiteral("Test"), - tr("UpdateTextTreeByModelError")); - } -} - void TestForm::on_btnStatusVisible_clicked() { if (ui->rbLockedFile->isChecked()) { Q_UNUSED(setLockedFile(true)); diff --git a/TestPlugin/testform.h b/TestPlugin/testform.h index 27d964c..429703e 100644 --- a/TestPlugin/testform.h +++ b/TestPlugin/testform.h @@ -85,20 +85,6 @@ private slots: void on_btnGetColor_clicked(); - void on_btnText_2_clicked(); - - void on_btnTextList_clicked(); - - void on_btnTextTree_clicked(); - - void on_btnTextTable_clicked(); - - void on_btnTextListByModel_clicked(); - - void on_btnTextTableByModel_clicked(); - - void on_btnTextTreeByModel_clicked(); - void on_btnStatusVisible_clicked(); void on_btnStatusInvisible_clicked(); @@ -121,15 +107,8 @@ private: QFileDialog::Options getFileDialogOptions() const; - void onDVClicked(const QModelIndex &index); - - void onDVDoubleClicked(const QModelIndex &index); - private: Ui::TestForm *ui; - - WingHex::ClickedCallBack _click; - WingHex::ClickedCallBack _dblclick; }; #endif // TESTFORM_H diff --git a/TestPlugin/testform.ui b/TestPlugin/testform.ui index 8dfd319..5a8b0c3 100644 --- a/TestPlugin/testform.ui +++ b/TestPlugin/testform.ui @@ -1050,135 +1050,6 @@ - - - DataVisual - - - - - - - - - - 0 - 150 - - - - Type - - - - QLayout::SizeConstraint::SetMinAndMaxSize - - - - - - 0 - 0 - - - - updateTextList (LineByLine) - - - - - - - - 0 - 0 - - - - updateTextTree (Json) - - - - - - - - 0 - 0 - - - - updateTextTable (Json) - - - - - - - - 0 - 0 - - - - updateTextListByModel - - - - - - - - 0 - 0 - - - - updateText - - - - - - - - 0 - 0 - - - - updateTextTableByModel - - - - - - - - 0 - 0 - - - - updateTextTreeByModel - - - - - - - WingSummer - - - Qt::AlignmentFlag::AlignCenter - - - - - - - - Others @@ -1278,18 +1149,18 @@ - btnClearCtl + btnClearFile clicked() - tbCtlLogger + tbFileLogger clear() - 271 - 387 + 239 + 388 - 318 - 264 + 290 + 328 @@ -1310,34 +1181,34 @@ - btnClearInput + btnClearCtl clicked() - tbInputLogger + tbCtlLogger clear() - 210 - 388 + 271 + 387 - 236 - 332 + 318 + 264 - btnClearFile + btnClearText clicked() - tbFileLogger + leToastText clear() - 239 - 388 + 569 + 271 - 290 - 328 + 468 + 229 @@ -1358,18 +1229,18 @@ - btnClearText + btnClearInput clicked() - leToastText + tbInputLogger clear() - 569 - 271 + 210 + 388 - 468 - 229 + 236 + 332 diff --git a/TestPlugin/testtablemodel.cpp b/TestPlugin/testtablemodel.cpp deleted file mode 100644 index da3e3fe..0000000 --- a/TestPlugin/testtablemodel.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/*============================================================================== -** Copyright (C) 2024-2027 WingSummer -** -** Permission is hereby granted, free of charge, to any person obtaining a copy -** of this software and associated documentation files (the "Software"), to deal -** in the Software without restriction, including without limitation the rights -** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -** copies of the Software, and to permit persons to whom the Software is -** furnished to do so. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -** THE SOFTWARE. -** ============================================================================= -*/ - -#include "testtablemodel.h" -#include "WingPlugin/iwingpluginbase.h" - -TestTableModel::TestTableModel(QObject *parent) : QAbstractTableModel(parent) {} - -int TestTableModel::rowCount(const QModelIndex &parent) const { - Q_UNUSED(parent); - return WingHex::SDKVERSION; -} - -int TestTableModel::columnCount(const QModelIndex &parent) const { - Q_UNUSED(parent); - return 5; -} - -QVariant TestTableModel::data(const QModelIndex &index, int role) const { - switch (role) { - case Qt::DisplayRole: - case Qt::ToolTipRole: { - return QStringLiteral("(%1, %2)").arg(index.row()).arg(index.column()); - } - case Qt::TextAlignmentRole: - return Qt::AlignCenter; - } - return QVariant(); -} - -QVariant TestTableModel::headerData(int section, Qt::Orientation orientation, - int role) const { - Q_UNUSED(orientation); - if (role == Qt::DisplayRole) { - return section + 1; - } - return QVariant(); -} diff --git a/TestPlugin/testtablemodel.h b/TestPlugin/testtablemodel.h deleted file mode 100644 index e438987..0000000 --- a/TestPlugin/testtablemodel.h +++ /dev/null @@ -1,41 +0,0 @@ -/*============================================================================== -** Copyright (C) 2024-2027 WingSummer -** -** Permission is hereby granted, free of charge, to any person obtaining a copy -** of this software and associated documentation files (the "Software"), to deal -** in the Software without restriction, including without limitation the rights -** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -** copies of the Software, and to permit persons to whom the Software is -** furnished to do so. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -** THE SOFTWARE. -** ============================================================================= -*/ - -#ifndef TESTTABLEMODEL_H -#define TESTTABLEMODEL_H - -#include - -class TestTableModel : public QAbstractTableModel { - Q_OBJECT -public: - explicit TestTableModel(QObject *parent = nullptr); - - // QAbstractItemModel interface -public: - virtual int rowCount(const QModelIndex &parent) const override; - virtual int columnCount(const QModelIndex &parent) const override; - virtual QVariant data(const QModelIndex &index, int role) const override; - - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role) const override; -}; - -#endif // TESTTABLEMODEL_H diff --git a/WingPlugin b/WingPlugin index 95b3250..8d86c18 160000 --- a/WingPlugin +++ b/WingPlugin @@ -1 +1 @@ -Subproject commit 95b3250011d0bf76ebd77f9905dc77fd04a46ce7 +Subproject commit 8d86c185041572bd4735b272669d4117765c2176 diff --git a/lang/zh_CN/winghex_zh_CN.ts b/lang/zh_CN/winghex_zh_CN.ts index d3cbe3c..26f316b 100644 --- a/lang/zh_CN/winghex_zh_CN.ts +++ b/lang/zh_CN/winghex_zh_CN.ts @@ -871,7 +871,7 @@ - + View 视图 @@ -908,8 +908,8 @@ - - + + Plugin 插件 @@ -919,325 +919,295 @@ 设置 - - + + Log 日志 - + ExportFindResult 导出搜索结果 - + ClearFindResult 清空记录 - - + + FindResult 搜索结果 - - - - - - - + + + + Copy 复制 - - - - - - - - + + + + + CopyToClipBoard 数据已拷贝到粘贴板 - + LittleEndian 小端 - + BigEndian 大端 - + Number 数值 - - + + CheckSum 校验和 - - + + DeleteBookMark 删除书签 - - + + ClearBookMark 清空书签 - - - - + + + + BookMark 书签 - - + + DecodeText 解码字符串 - + ScriptConsole 脚本控制台 - - - DVList - 可视化列表 - - - - - DVTree - 可视化树数据 - - - - - DVTable - 可视化表格 - - - - - DVText - 可视化文本 - - - - + + Basic 基础 - + New 新建 - + OpenF 打开文件 - + OpenWorkSpace 打开工作区 - + RecentFiles 最近打开 - + Reload 重新加载 - - + + Save 保存 - + SaveAs 另存为 - + ConvertWS 转为工作区 - + Export 导出 - + SaveSel 保存选区字节 - - - - + + + + General 基本 - + Undo 撤销 - + Redo 恢复 - + Cut 剪切 - + Paste 粘贴 - + Delete 删除 - + Clone 克隆 - + Lookup 查询 - + Find 查找 - + Goto 跳转 - - + + Encoding 编码 - + FileInfo 文件信息 - - + + Hex 十六进制 - + CutHex 剪切(十六进制) - + CopyHex 复制(十六进制) - + PasteHex 粘贴(十六进制) - - + + Fill 填充 - + FillZero 填充零 - - - - - + + + + + MetaData 标注 - + DeleteMetadata 删除标注 - + ClearMetadata 清空标注 - + MetaDataEdit 编辑标注 - + DeleteMetaData 删除标注 - + ClearMetaData 清空标注 - + Display 显示 - + ViewText 文本预览 - + Scale 缩放 @@ -1317,767 +1287,736 @@ 启动完毕 - + NoExtension 无扩展 - - - - - - + + ExportResult 导出结果 - - - + NothingToSave 没有保存的数据 - - - - - ClearResult - 清空结果 - - - + OpenExt 打开 - 拓展 - + ResetScale 重置缩放 - + ShowMetafg 标注前景色 - + ShowMetabg 标注背景色 - + ShowMetaComment 批注 - + MetaShowAll 显示所有标注 - + MetaHideAll 隐藏所有标注 - + FileStatus 文件状态 - + InfoSave 是否保存 - + ReadOnly 可读写 - + SetLocked 启用/禁用锁定编辑 - + ErrUnLock 锁定编辑失败 - + SetOver 启用/禁用改变大小 - + UnsignedHex 无符号 Hex - + BgScriptOutput 后台脚本输出 - + ErrUnOver 锁定文件大小失败 - + Window 窗体 - + Editor 编辑器 - + Tools 工具 - + HexEditorLayout 编辑器布局 - + SetBaseAddr 设置基址 - + addressBase 基址 - + inputAddressBase 请输入基址 - + WarnBigBaseAddress 基址过大,你得到的地址将会不正确! - + ErrBaseAddress 非法基址输入 - + SetColInfo 显示/隐藏地址栏 - + SetHeaderInfo 显示/隐藏表头 - + SetAsciiString 显示/隐藏解码字符串 - + Layout 布局 - + Fullscreen 全屏 - + Default 默认 - - - + + + LayoutRestoring... 恢复布局中... - + RestoreLayout 恢复布局 - - + + SaveLayout 保存布局 - + ExportLog 导出日志 - + ClearLog 清空日志 - + InsepctQt 监视 Qt - + ScriptEditor 脚本编辑器 - + Scripts 脚本仓库 - + PluginFunctions 插件功能 - + ScriptSetting 脚本设置 - + PluginSettings 插件设置 - + Info 信息 - + Software 软件 - + Sponsor 赞助 - + CheckUpdate 检查更新 - + Wiki 网页 Wiki - + AboutQT 关于 QT - + SetPageIDEmptyTryUseName 设置页 ID 为空,尝试使用名称作为 ID - + SetPageDupNameIgnored 设置页重复的 ID 名称,已忽略加载 - + Plugin %1 contains a duplicate ID (%2) that is already registered by plugin %3 插件 %1 包含重复 ID (%2),该 ID 已被插件 %3 注册 - - + + ChooseFile 选择文件 - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + Error 错误 - - + + FileNotExist 文件不存在! - - - - - - - - + + + + + FilePermission 因文件权限无法继续! - + ProjectFile (*.wingpro) 项目文件 (*.wingpro) - + ReloadSuccessfully 文件重新加载成功! - + ReloadUnSuccessfully 文件重新加载失败! - - - - - - - + + + + ChooseSaveFile 请选择保存文件路径: - + NoMoreClone 克隆已到上限,无法继续操作! - + FindFininishBusy 查找任务繁忙,请勿重复查找! - + MayTooMuchFindResult 搜索数量已到达上限,结果可能不全,建议请按区段搜索。 - + SaveLayoutSuccess 保存布局成功 - + SaveLayoutError 保存布局失败 - + HasClonedView 该编辑页已被克隆编辑,如果关闭,相关联的页也会被关闭,你确认继续吗? - + SaveWorkSpace 保存工作区 - + WingHexWorkSpace (*.wingpro) 羽云十六进制工作区 (*.wingpro) - + ConfirmSave 正在关闭未保存的文件或工作区,你确定保存吗? - + [Info] 【信息】 - + [Warn] 【警告】 - + [Error] 【错误】 - - Column %1 - 列 %1 - - - + ConfirmAPPSave 你尝试关闭程序,但仍存在未保存的文件或工作区,你确定保存这些更改吗? - - - - - - + + + SaveSuccessfully 保存成功! - - + + SaveWSError 保存工作区错误! - - + + Warn 警告 - + Opening... 打开文件中... - + WorkSpaceOpening... 打开工作区中... - + Reloading... 重载文件中... - + Saving... 保存中... - + SaveNewFirst 请首先保存新建的文件 - + AlreadyWorkSpace 已经是工作区,无需转化 - + ConvWorkSpaceFailed 转化为工作区失败 - + ConvWorkSpaceSuccess 转化为工作区成功 - + SavingAs... 另存为中... - + SaveUnSuccessfully 保存失败! - + Exporting... 导出中... - + ChooseExportFile 请选择导出文件路径: - + ExportSuccessfully 导出成功! - + ExportUnSuccessfully 导出失败! - + SavingSel... 保存选中字节中... - + SaveSelSuccess 保存选区字节成功! - + SaveSelError 保存选区字节失败,因文件不具有可写权限! - - + + CutToClipBoard 数据已剪切到粘贴板! - - + + UnCutToClipBoard 由于保持大小限制,数据剪切到粘贴板失败! - - + + UnCopyToClipBoard 由于保持大小限制,数据剪切到复制板失败! - - + + Finding... 查找中... - + DeleteSuccess 删除成功 - + DeleteFailed 删除失败 - + FindFininish 查找结果完毕! - + PleaseInputFill 请输入填充字节值 - + FillInputTruncWarn 填充输入数值过大,将会被截断填充 - + FillInputError 填充字节输入错误 - - + + InputComment 请输入批注: - - + + BookmarkDelSuccess 删除书签成功 - + BookmarkDelNoItem 无书签可删除 - + BookmarkClearSuccess 书签清空完毕 - - - + + + NoSelection 没有选区,无法继续的操作! - + NoMetaData 无可编辑标记 - + PleaseClearSel 请清空选择 - + MetaDelSuccess 元数据删除成功 - + MetaDelNoItem 无元数据可删除 - + MetaClearSuccess 元数据清空完毕 - + FindResultExporting... 查找结果导出中... - - + + EmptyFindResult 没有可导出的搜索结果! - + SaveFindResult 导出搜索结果成功! - + SaveFindResultError 导出结果失败! - + TooManyBytesDecode 超出解码字节限制…… - + NoTextFileMayInvalid 该文件不是文本文件,以文本方式预览并不是一个好的方式,你确认继续吗? - + LayoutSaving... 布局保存中... - + PleaseInput 请输入 - + LogExporting... 日志导出中... - + ExportLogError 导出日志失败! - + ExportLogSuccess 导出日志成功,路径: - + ClearLogSuccess 清空日志成功! - + BadNetwork 无法与远程服务器的更新检查建立连接,请检查网络。 - + NewestVersion 当前软件为最新版本 - + OlderVersion 你使用的软件为老版本,建议到 Github 和 Gitee 的仓库发行版下载更新。 - + CheckingUpdate 检查更新中…… - + Too much opened files 打开的文件过多,无法继续操作! - + FilePermissionSure2Quit 因文件权限无法保存,你确认要退出吗? - + UnknownErrorSure2Quit 因未知错误无法保存,你确认要退出吗? - + WorkSpaceUnSavedSure2Quit 工作区文件无法保存,你确认要退出吗? - + CopyLimit 拷贝字节超出限制 - + ErrOpenFileBelow 打开文件出现错误(由于权限不足),如下为打开错误的文件: @@ -2308,155 +2247,155 @@ PluginSystem - + LoadingPlugin 加载插件中: - + InvalidPluginBrokenInfo 加载插件失败:损坏的插件数据 - + AppClosingCanceled: 程序关闭被取消: - + - PluginID: - 插件 ID: - + FoundDrvPluginCount 总计发现设备拓展插件数目: - + RegisterScriptFnUnSupportedTypes: 因脚本函数含有未支持的类型而注册失败: - - + + RegisterScriptFnInvalidSig: 因脚本函数签名非法而注册失败: - - + + RegisterScriptFnConflitSig: 因脚本函数签名冲突而注册失败: - + InvalidEnumName: 非法枚举名: - + InvalidEnumValue: 非法枚举值: - + InvalidMarcosRegister: 非法宏注册: - + ErrLoadPluginSDKVersion 插件加载失败:非法插件 SDK 版本! - + ErrLoadPluginNoName 插件加载失败:非法插件名称! - + ErrLoadInitPlugin 插件加载失败:初始化插件失败! - + PluginName : 插件名: - + PluginAuthor : 插件作者: - + PluginWidgetRegister 注册插件对象中…… - + ErrLoadExtPluginSDKVersion 设备拓展插件加载失败:非法插件 SDK 版本! - + ExtPluginAuthor : 设备拓展插件作者: - + ExtPluginWidgetRegister 设备拓展注册插件对象中…… - + ErrLoadInitExtPlugin 设备拓展插件加载失败:初始化插件失败! - + ChooseFile 选择文件 - - + + Error 错误 - + FileNotExist 文件不存在! - + FilePermission 因文件权限无法继续! - + EmptyNameDockWidget: 空的贴边组件名: - + InvalidNameDockWidget: 无效贴边组件名: - + InvalidNullDockWidget: 无效空贴边组件: - + Not allowed operation in non-UI thread 该操作在非 UI 线程非法 - + UnsafePluginDir 不安全的插件目录,请将插件目录设置为仅管理员账户可写 @@ -2466,42 +2405,42 @@ 【非法调用】 - + InvalidPluginID 加载插件失败:非法插件标识符 - + InvalidDupPlugin 加载插件失败:重复的插件标识符 - + FoundPluginCount 总计发现插件数目: - + PluginLoadingFailedSummary 有依赖插件加载失败总结 - + - Dependencies: - 依赖: - + PUID: 插件唯一标志符: - + Version: 版本: - + PluginLoadingFinished 加载插件完毕! @@ -2655,25 +2594,6 @@ 说明: - - QJsonModel - - - - - - key - - - - - - - - value - - - QMessageBox @@ -5155,28 +5075,28 @@ WingAngelAPI - + AngelScriptService AngelScript 服务 - + A internal plugin that provides AngelScript scripts with the ability to call the host API. 为 AngelScript 脚本提供调用主机 API 能力的内部插件。 - + NotSupportedQMetaType: 不支持的 QT 数据元类型: - - + + Get Exception While ScriptCall: (%1) %2 脚本调用发生异常:(%1)%2 - + InvalidRetType: need 无效返回值:需要 diff --git a/lang/zh_TW/winghex_zh_TW.ts b/lang/zh_TW/winghex_zh_TW.ts index a79ca77..a70b244 100644 --- a/lang/zh_TW/winghex_zh_TW.ts +++ b/lang/zh_TW/winghex_zh_TW.ts @@ -871,7 +871,7 @@ - + View 視圖 @@ -908,8 +908,8 @@ - - + + Plugin 插件 @@ -919,325 +919,295 @@ 設置 - - + + Log 日誌 - + ExportFindResult 導出搜索結果 - + ClearFindResult 清空記錄 - - + + FindResult 搜索結果 - - - - - - - + + + + Copy 複製 - - - - - - - - + + + + + CopyToClipBoard 數據已拷貝到粘貼板 - + LittleEndian 小端 - + BigEndian 大端 - + Number 數值 - - + + CheckSum 校驗和 - - + + DeleteBookMark 刪除書簽 - - + + ClearBookMark 清空書簽 - - - - + + + + BookMark 書簽 - - + + DecodeText 解碼字串 - + ScriptConsole 腳本控制臺 - - - DVList - 可視化列表 - - - - - DVTree - 可視化樹數據 - - - - - DVTable - 可視化表格 - - - - - DVText - 可視化文本 - - - - + + Basic 基礎 - + New 新建 - + OpenF 打開檔 - + OpenWorkSpace 打開工作區 - + RecentFiles 最近打開 - + Reload 重新加載 - - + + Save 保存 - + SaveAs 另存為 - + ConvertWS 轉為工作區 - + Export 導出 - + SaveSel 保存選區位元組 - - - - + + + + General 基本 - + Undo 撤銷 - + Redo 恢復 - + Cut 剪切 - + Paste 粘貼 - + Delete 刪除 - + Clone 克隆 - + Lookup 查詢 - + Find 查找 - + Goto 跳轉 - - + + Encoding 編碼 - + FileInfo 檔資訊 - - + + Hex 十六進制 - + CutHex 剪切(十六進制) - + CopyHex 複製(十六進制) - + PasteHex 粘貼(十六進制) - - + + Fill 填充 - + FillZero 填充零 - - - - - + + + + + MetaData 標注 - + DeleteMetadata 刪除標注 - + ClearMetadata 清空標注 - + MetaDataEdit 編輯標注 - + DeleteMetaData 刪除標注 - + ClearMetaData 清空標注 - + Display 顯示 - + ViewText 文本預覽 - + Scale 縮放 @@ -1317,767 +1287,736 @@ 啟動完畢 - + NoExtension 無擴展 - - - - - - + + ExportResult 導出結果 - - - + NothingToSave 沒有保存的數據 - - - - - ClearResult - 清空結果 - - - + OpenExt 打開 - 拓展 - + ResetScale 重置縮放 - + ShowMetafg 標注前景色 - + ShowMetabg 標注背景色 - + ShowMetaComment 批註 - + MetaShowAll 顯示所有標注 - + MetaHideAll 隱藏所有標注 - + FileStatus 檔狀態 - + InfoSave 是否保存 - + ReadOnly 可讀寫 - + SetLocked 啟用/禁用鎖定編輯 - + ErrUnLock 鎖定編輯失敗 - + SetOver 啟用/禁用改變大小 - + UnsignedHex 無符號 Hex - + BgScriptOutput 後臺腳本輸出 - + ErrUnOver 鎖定檔大小失敗 - + Window 窗體 - + Editor 編輯器 - + Tools 工具 - + HexEditorLayout 編輯器佈局 - + SetBaseAddr 設置基址 - + addressBase 基址 - + inputAddressBase 請輸入基址 - + WarnBigBaseAddress 基址過大,你得到的地址將會不正確! - + ErrBaseAddress 非法基址輸入 - + SetColInfo 顯示/隱藏地址欄 - + SetHeaderInfo 顯示/隱藏表頭 - + SetAsciiString 顯示/隱藏解碼字串 - + Layout 佈局 - + Fullscreen 全屏 - + Default 默認 - - - + + + LayoutRestoring... 恢復佈局中... - + RestoreLayout 恢復佈局 - - + + SaveLayout 保存佈局 - + ExportLog 導出日誌 - + ClearLog 清空日誌 - + InsepctQt 監視 Qt - + ScriptEditor 腳本編輯器 - + Scripts 腳本倉庫 - + PluginFunctions 插件功能 - + ScriptSetting 腳本設置 - + PluginSettings 插件設置 - + Info 資訊 - + Software 軟體 - + Sponsor 贊助 - + CheckUpdate 檢查更新 - + Wiki 網頁 Wiki - + AboutQT 關於 QT - + SetPageIDEmptyTryUseName 設置頁 ID 為空,嘗試使用名稱作為 ID - + SetPageDupNameIgnored 設置頁重複的 ID 名稱,已忽略加載 - + Plugin %1 contains a duplicate ID (%2) that is already registered by plugin %3 插件 %1 包含重複 ID (%2),該 ID 已被插件 %3 註冊 - - + + ChooseFile 選擇檔 - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + Error 錯誤 - - + + FileNotExist 檔不存在! - - - - - - - - + + + + + FilePermission 因檔許可權無法繼續! - + ProjectFile (*.wingpro) 專案檔 (*.wingpro) - + ReloadSuccessfully 檔重新加載成功! - + ReloadUnSuccessfully 檔重新加載失敗! - - - - - - - + + + + ChooseSaveFile 請選擇保存檔路徑: - + NoMoreClone 克隆已到上限,無法繼續操作! - + FindFininishBusy 查找任務繁忙,請勿重複查找! - + MayTooMuchFindResult 搜索數量已到達上限,結果可能不全,建議請按區段搜索。 - + SaveLayoutSuccess 保存佈局成功 - + SaveLayoutError 保存佈局失敗 - + HasClonedView 該編輯頁已被克隆編輯,如果關閉,相關聯的頁也會被關閉,你確認繼續嗎? - + SaveWorkSpace 保存工作區 - + WingHexWorkSpace (*.wingpro) 羽雲十六進制工作區 (*.wingpro) - + ConfirmSave 正在關閉未保存的檔或工作區,你確定保存嗎? - + [Info] 【資訊】 - + [Warn] 【警告】 - + [Error] 【錯誤】 - - Column %1 - 列 %1 - - - + ConfirmAPPSave 你嘗試關閉程式,但仍存在未保存的檔或工作區,你確定保存這些更改嗎? - - - - - - + + + SaveSuccessfully 保存成功! - - + + SaveWSError 保存工作區錯誤! - - + + Warn 警告 - + Opening... 打開檔中... - + WorkSpaceOpening... 打開工作區中... - + Reloading... 重載檔中... - + Saving... 保存中... - + SaveNewFirst 請首先保存新建的檔 - + AlreadyWorkSpace 已經是工作區,無需轉化 - + ConvWorkSpaceFailed 轉化為工作區失敗 - + ConvWorkSpaceSuccess 轉化為工作區成功 - + SavingAs... 另存為中... - + SaveUnSuccessfully 保存失敗! - + Exporting... 導出中... - + ChooseExportFile 請選擇導出檔路徑: - + ExportSuccessfully 導出成功! - + ExportUnSuccessfully 導出失敗! - + SavingSel... 保存選中位元組中... - + SaveSelSuccess 保存選區位元組成功! - + SaveSelError 保存選區位元組失敗,因檔不具有可寫許可權! - - + + CutToClipBoard 數據已剪切到粘貼板! - - + + UnCutToClipBoard 由於保持大小限制,數據剪切到粘貼板失敗! - - + + UnCopyToClipBoard 由於保持大小限制,數據剪切到複製板失敗! - - + + Finding... 查找中... - + DeleteSuccess 刪除成功 - + DeleteFailed 刪除失敗 - + FindFininish 查找結果完畢! - + PleaseInputFill 請輸入填充位元組值 - + FillInputTruncWarn 填充輸入數值過大,將會被截斷填充 - + FillInputError 填充位元組輸入錯誤 - - + + InputComment 請輸入批註: - - + + BookmarkDelSuccess 刪除書簽成功 - + BookmarkDelNoItem 無書簽可刪除 - + BookmarkClearSuccess 書簽清空完畢 - - - + + + NoSelection 沒有選區,無法繼續的操作! - + NoMetaData 無可編輯標記 - + PleaseClearSel 請清空選擇 - + MetaDelSuccess 元數據刪除成功 - + MetaDelNoItem 無元數據可刪除 - + MetaClearSuccess 元數據清空完畢 - + FindResultExporting... 查找結果導出中... - - + + EmptyFindResult 沒有可導出的搜索結果! - + SaveFindResult 導出搜索結果成功! - + SaveFindResultError 導出結果失敗! - + TooManyBytesDecode 超出解碼位元組限制…… - + NoTextFileMayInvalid 該檔不是文本檔,以文本方式預覽並不是一個好的方式,你確認繼續嗎? - + LayoutSaving... 佈局保存中... - + PleaseInput 請輸入 - + LogExporting... 日誌導出中... - + ExportLogError 導出日誌失敗! - + ExportLogSuccess 導出日誌成功,路徑: - + ClearLogSuccess 清空日誌成功! - + BadNetwork 無法與遠程伺服器的更新檢查建立連接,請檢查網路。 - + NewestVersion 當前軟體為最新版本 - + OlderVersion 你使用的軟體為老版本,建議到 Github 和 Gitee 的倉庫發行版下載更新。 - + CheckingUpdate 檢查更新中…… - + Too much opened files 打開的檔過多,無法繼續操作! - + FilePermissionSure2Quit 因檔許可權無法保存,你確認要退出嗎? - + UnknownErrorSure2Quit 因未知錯誤無法保存,你確認要退出嗎? - + WorkSpaceUnSavedSure2Quit 工作區檔無法保存,你確認要退出嗎? - + CopyLimit 拷貝位元組超出限制 - + ErrOpenFileBelow 打開檔出現錯誤(由於許可權不足),如下為打開錯誤的檔: @@ -2308,155 +2247,155 @@ PluginSystem - + LoadingPlugin 加載插件中: - + InvalidPluginBrokenInfo 加載插件失敗:損壞的插件數據 - + AppClosingCanceled: 程式關閉被取消: - + - PluginID: - 插件 ID: - + FoundDrvPluginCount 總計發現設備拓展插件數目: - + RegisterScriptFnUnSupportedTypes: 因腳本函數含有未支持的類型而註冊失敗: - - + + RegisterScriptFnInvalidSig: 因腳本函數簽名非法而註冊失敗: - - + + RegisterScriptFnConflitSig: 因腳本函數簽名衝突而註冊失敗: - + InvalidEnumName: 非法枚舉名: - + InvalidEnumValue: 非法枚舉值: - + InvalidMarcosRegister: 非法宏註冊: - + ErrLoadPluginSDKVersion 插件加載失敗:非法插件 SDK 版本! - + ErrLoadPluginNoName 插件加載失敗:非法插件名稱! - + ErrLoadInitPlugin 插件加載失敗:初始化插件失敗! - + PluginName : 插件名: - + PluginAuthor : 插件作者: - + PluginWidgetRegister 註冊插件對象中…… - + ErrLoadExtPluginSDKVersion 設備拓展插件加載失敗:非法插件 SDK 版本! - + ExtPluginAuthor : 設備拓展插件作者: - + ExtPluginWidgetRegister 設備拓展註冊插件對象中…… - + ErrLoadInitExtPlugin 設備拓展插件加載失敗:初始化插件失敗! - + ChooseFile 選擇檔 - - + + Error 錯誤 - + FileNotExist 檔不存在! - + FilePermission 因檔許可權無法繼續! - + EmptyNameDockWidget: 空的貼邊組件名: - + InvalidNameDockWidget: 無效貼邊組件名: - + InvalidNullDockWidget: 無效空貼邊組件: - + Not allowed operation in non-UI thread 該操作在非 UI 線程非法 - + UnsafePluginDir 不安全的插件目錄,請將插件目錄設置為僅管理員帳戶可寫 @@ -2466,42 +2405,42 @@ 【非法調用】 - + InvalidPluginID 加載插件失敗:非法插件識別字 - + InvalidDupPlugin 加載插件失敗:重複的插件識別字 - + FoundPluginCount 總計發現插件數目: - + PluginLoadingFailedSummary 有依賴插件加載失敗總結 - + - Dependencies: - 依賴: - + PUID: 插件唯一標誌符: - + Version: 版本: - + PluginLoadingFinished 加載插件完畢! @@ -2655,25 +2594,6 @@ 說明: - - QJsonModel - - - - - - key - - - - - - - - value - - - QMessageBox @@ -5155,28 +5075,28 @@ WingAngelAPI - + AngelScriptService AngelScript 服務 - + A internal plugin that provides AngelScript scripts with the ability to call the host API. 為 AngelScript 腳本提供調用主機 API 能力的內部插件。 - + NotSupportedQMetaType: 不支持的 QT 數據元類型: - - + + Get Exception While ScriptCall: (%1) %2 腳本調用發生異常:(%1)%2 - + InvalidRetType: need 無效返回值:需要 diff --git a/src/class/clickcallback.h b/src/class/clickcallback.h deleted file mode 100644 index e6b4939..0000000 --- a/src/class/clickcallback.h +++ /dev/null @@ -1,84 +0,0 @@ -/*============================================================================== -** Copyright (C) 2024-2027 WingSummer -** -** This program is free software: you can redistribute it and/or modify it under -** the terms of the GNU Affero General Public License as published by the Free -** Software Foundation, version 3. -** -** This program is distributed in the hope that it will be useful, but WITHOUT -** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -** FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -** details. -** -** You should have received a copy of the GNU Affero General Public License -** along with this program. If not, see . -** ============================================================================= -*/ - -#ifndef CLICKCALLBACK_H -#define CLICKCALLBACK_H - -#include "WingPlugin/iwingplugin.h" -#include "angelscript.h" - -class ClickCallBack { -public: - ClickCallBack() {} - - ClickCallBack(const WingHex::ClickedCallBack &b) : _call(b) {} - - explicit ClickCallBack(asIScriptEngine *engine, asIScriptFunction *func) - : _engine(engine), _func(func) { - if (_engine && _func) { - _func->AddRef(); - } - } - - ~ClickCallBack() { - if (_func) { - _func->Release(); - } - } - -public: - ClickCallBack &operator=(const WingHex::ClickedCallBack &_Right) { - *this = ClickCallBack(_Right); - return *this; - } - - ClickCallBack &operator=(WingHex::ClickedCallBack &&_Right) { - *this = ClickCallBack(_Right); - return *this; - } - -public: - explicit operator bool() const noexcept { - return _call || (_engine && _func); - } - - void operator()(const QModelIndex &index) { - if (_call) { - _call(index); - } else { - if (_engine && _func) { - auto ctx = _engine->CreateContext(); - if (ctx) { - auto r = ctx->Prepare(_func); - if (r >= 0) { - auto idx = index; - ctx->SetArgObject(0, &idx); - ctx->Execute(); - } - ctx->Release(); - } - } - } - } - -private: - WingHex::ClickedCallBack _call; - asIScriptEngine *_engine = nullptr; - asIScriptFunction *_func = nullptr; -}; - -#endif // CLICKCALLBACK_H diff --git a/src/class/pluginsystem.cpp b/src/class/pluginsystem.cpp index bca36f2..f5a8e63 100644 --- a/src/class/pluginsystem.cpp +++ b/src/class/pluginsystem.cpp @@ -17,7 +17,6 @@ #include "pluginsystem.h" #include "AngelScript/sdk/angelscript/source/as_builder.h" -#include "QJsonModel/include/QJsonModel.hpp" #include "Qt-Advanced-Docking-System/src/DockAreaWidget.h" #include "class/languagemanager.h" #include "class/logger.h" @@ -33,10 +32,11 @@ #include "dialog/colorpickerdialog.h" #include "dialog/framelessdialogbase.h" #include "dialog/mainwindow.h" -#include "model/qjsontablemodel.h" #include #include +#include +#include #include #include #include @@ -1787,99 +1787,6 @@ bool PluginSystem::closeAllFiles(QObject *sender) { return true; } -bool PluginSystem::dataVisualText(QObject *sender, const QString &data, - const QString &title) { - auto plg = checkPluginAndReport(sender, __func__); - if (plg == nullptr || !checkThreadAff()) { - return false; - } - _win->m_infotxt->setProperty("__TITLE__", title); - _win->m_infotxt->setText(data); - return true; -} - -bool PluginSystem::dataVisualTextList(QObject *sender, const QStringList &data, - const QString &title, - ClickedCallBack clicked, - ClickedCallBack dblClicked) { - auto plg = checkPluginAndReport(sender, __func__); - if (plg == nullptr || !checkThreadAff()) { - return false; - } - return updateTextList_API(data, title, clicked, dblClicked); -} - -bool PluginSystem::dataVisualTextTree(QObject *sender, const QString &json, - const QString &title, - ClickedCallBack clicked, - ClickedCallBack dblClicked) { - auto plg = checkPluginAndReport(sender, __func__); - if (plg == nullptr || !checkThreadAff()) { - return false; - } - return updateTextTree_API(json, title, clicked, dblClicked); -} - -bool PluginSystem::dataVisualTextTable(QObject *sender, const QString &json, - const QStringList &headers, - const QStringList &headerNames, - const QString &title, - ClickedCallBack clicked, - ClickedCallBack dblClicked) { - auto plg = checkPluginAndReport(sender, __func__); - if (plg == nullptr || !checkThreadAff()) { - return false; - } - return updateTextTable_API(json, headers, headerNames, title, clicked, - dblClicked); -} - -bool PluginSystem::dataVisualTextListByModel(QObject *sender, - QAbstractItemModel *model, - const QString &title, - ClickedCallBack clicked, - ClickedCallBack dblClicked) { - auto plg = checkPluginAndReport(sender, __func__); - if (plg == nullptr || !checkThreadAff()) { - return false; - } - if (model) { - auto oldmodel = _win->m_infolist->model(); - if (oldmodel) { - oldmodel->deleteLater(); - } - _win->m_infolist->setProperty("__TITLE__", title); - _win->m_infolist->setModel(model); - _win->m_infoclickfn = clicked; - _win->m_infodblclickfn = dblClicked; - return true; - } - return false; -} - -bool PluginSystem::dataVisualTextTreeByModel(QObject *sender, - QAbstractItemModel *model, - const QString &title, - ClickedCallBack clicked, - ClickedCallBack dblClicked) { - auto plg = checkPluginAndReport(sender, __func__); - if (plg == nullptr || !checkThreadAff()) { - return false; - } - if (model) { - auto oldmodel = _win->m_infotree->model(); - if (oldmodel) { - oldmodel->deleteLater(); - } - _win->m_infotree->setProperty("__TITLE__", title); - _win->m_infotree->setModel(model); - _win->m_infotreeclickfn = clicked; - _win->m_infotreedblclickfn = dblClicked; - return true; - } - return false; -} - bool PluginSystem::checkErrAllAllowAndReport(QObject *sender, const char *func) { auto p = qobject_cast(sender); @@ -1904,29 +1811,6 @@ IWingPlugin *PluginSystem::checkPluginAndReport(QObject *sender, return p; } -bool PluginSystem::dataVisualTextTableByModel(QObject *sender, - QAbstractItemModel *model, - const QString &title, - ClickedCallBack clicked, - ClickedCallBack dblClicked) { - auto plg = checkPluginAndReport(sender, __func__); - if (plg == nullptr || !checkThreadAff()) { - return false; - } - if (model) { - auto oldmodel = _win->m_infotable->model(); - if (oldmodel) { - oldmodel->deleteLater(); - } - _win->m_infotable->setProperty("__TITLE__", title); - _win->m_infotable->setModel(model); - _win->m_infotableclickfn = clicked; - _win->m_infotabledblclickfn = dblClicked; - return true; - } - return false; -} - ErrFile PluginSystem::saveAsCurrent(QObject *sender, const QString &savename) { auto plg = checkPluginAndReport(sender, __func__); if (plg == nullptr) { @@ -3716,77 +3600,6 @@ void PluginSystem::registerMarcoDevice(IWingDevice *plg) { _scriptMarcos.append(sep + id + sep); } -bool PluginSystem::updateTextList_API(const QStringList &data, - const QString &title, - const ClickCallBack &click, - const ClickCallBack &dblclick) { - auto oldmodel = _win->m_infolist->model(); - if (oldmodel) { - oldmodel->deleteLater(); - } - _win->m_infolist->setProperty("__TITLE__", title); - auto model = new QStringListModel(data); - _win->m_infolist->setModel(model); - _win->m_infoclickfn = click; - _win->m_infodblclickfn = dblclick; - return true; -} - -bool PluginSystem::updateTextTree_API(const QString &json, const QString &title, - const ClickCallBack &click, - const ClickCallBack &dblclick) { - auto oldmodel = _win->m_infotree->model(); - if (oldmodel) { - oldmodel->deleteLater(); - } - _win->m_infotree->setProperty("__TITLE__", title); - auto model = new QJsonModel; - if (model->loadJson(json.toUtf8())) { - _win->m_infotree->setModel(model); - _win->m_infotreeclickfn = click; - _win->m_infotreedblclickfn = dblclick; - return true; - } - return false; -} - -bool PluginSystem::updateTextTable_API(const QString &json, - const QStringList &headers, - const QStringList &headerNames, - const QString &title, - const ClickCallBack &click, - const ClickCallBack &dblclick) { - auto oldmodel = _win->m_infotable->model(); - if (oldmodel) { - oldmodel->deleteLater(); - } - - QJsonTableModel::Header header; - if (headers.size() > headerNames.size()) { - for (auto &name : headers) { - QJsonTableModel::Heading heading; - heading["index"] = name; - heading["title"] = name; - header.append(heading); - } - } else { - auto np = headerNames.cbegin(); - for (auto p = headers.cbegin(); p != headers.cend(); ++p, ++np) { - QJsonTableModel::Heading heading; - heading["index"] = *p; - heading["title"] = *np; - header.append(heading); - } - } - _win->m_infotable->setProperty("__TITLE__", title); - auto model = new QJsonTableModel(header); - model->setJson(QJsonDocument::fromJson(json.toUtf8())); - _win->m_infotable->setModel(model); - _win->m_infotableclickfn = click; - _win->m_infotabledblclickfn = dblclick; - return true; -} - bool PluginSystem::checkThreadAff() { if (QThread::currentThread() != qApp->thread()) { Logger::warning(tr("Not allowed operation in non-UI thread")); diff --git a/src/class/pluginsystem.h b/src/class/pluginsystem.h index 363b722..93a337e 100644 --- a/src/class/pluginsystem.h +++ b/src/class/pluginsystem.h @@ -32,7 +32,6 @@ #include #include "WingPlugin/iwingdevice.h" -#include "class/clickcallback.h" #include "class/wingangelapi.h" #include "control/editorview.h" @@ -258,18 +257,6 @@ private: void registerPluginDockWidgets(IWingPluginBase *p); void registerPluginPages(IWingPluginBase *p); -public: - bool updateTextList_API(const QStringList &data, const QString &title, - const ClickCallBack &click, - const ClickCallBack &dblclick); - bool updateTextTree_API(const QString &json, const QString &title, - const ClickCallBack &click, - const ClickCallBack &dblclick); - bool updateTextTable_API(const QString &json, const QStringList &headers, - const QStringList &headerNames, - const QString &title, const ClickCallBack &click, - const ClickCallBack &dblclick); - public: // fpr crash checking QString currentLoadingPlugin() const; @@ -735,41 +722,6 @@ public: // extension WING_SERVICE bool closeAllFiles(QObject *sender); -public: - WING_SERVICE bool dataVisualText(QObject *sender, const QString &data, - const QString &title); - - WING_SERVICE bool dataVisualTextList(QObject *sender, - const QStringList &data, - const QString &title, - WingHex::ClickedCallBack clicked, - WingHex::ClickedCallBack dblClicked); - - WING_SERVICE bool dataVisualTextTree(QObject *sender, const QString &json, - const QString &title, - WingHex::ClickedCallBack clicked, - WingHex::ClickedCallBack dblClicked); - - WING_SERVICE bool dataVisualTextTable(QObject *sender, const QString &json, - const QStringList &headers, - const QStringList &headerNames, - const QString &title, - WingHex::ClickedCallBack clicked, - WingHex::ClickedCallBack dblClicked); - - // API for Qt Plugin Only - WING_SERVICE bool dataVisualTextListByModel( - QObject *sender, QAbstractItemModel *model, const QString &title, - WingHex::ClickedCallBack clicked, WingHex::ClickedCallBack dblClicked); - - WING_SERVICE bool dataVisualTextTableByModel( - QObject *sender, QAbstractItemModel *model, const QString &title, - WingHex::ClickedCallBack clicked, WingHex::ClickedCallBack dblClicked); - - WING_SERVICE bool dataVisualTextTreeByModel( - QObject *sender, QAbstractItemModel *model, const QString &title, - WingHex::ClickedCallBack clicked, WingHex::ClickedCallBack dblClicked); - private: WingHex::IWingPlugin *checkPluginAndReport(QObject *sender, const char *func); diff --git a/src/class/wingangelapi.cpp b/src/class/wingangelapi.cpp index bb500ed..56b5254 100644 --- a/src/class/wingangelapi.cpp +++ b/src/class/wingangelapi.cpp @@ -40,11 +40,9 @@ WingAngelAPI::WingAngelAPI() { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) qRegisterMetaType>(); #endif - - _fnbuffer.reserve(PluginSystem::instance().pluginAPICount()); } -WingAngelAPI::~WingAngelAPI() { _fnbuffer.clear(); } +WingAngelAPI::~WingAngelAPI() {} int WingAngelAPI::sdkVersion() const { return WingHex::SDKVERSION; } @@ -151,7 +149,6 @@ void WingAngelAPI::installAPI(ScriptMachine *machine) { installHexReaderAPI(engine); installHexControllerAPI(engine); - installDataVisualAPI(engine); installScriptEnums(engine); installScriptFns(engine); @@ -253,11 +250,6 @@ void WingAngelAPI::installBasicTypes(asIScriptEngine *engine) { Q_ASSERT(r >= 0); Q_UNUSED(r); - r = engine->RegisterFuncdef( - "void ClickCallBack(const ModelIndex &in index)"); - Q_ASSERT(r >= 0); - Q_UNUSED(r); - installHexBaseType(engine); } @@ -266,35 +258,35 @@ void WingAngelAPI::installLogAPI(asIScriptEngine *engine) { Q_ASSERT(r >= 0); Q_UNUSED(r); - registerAPI( - engine, std::bind(&WingAngelAPI::logInfo, this, std::placeholders::_1), - "void info(const string &in message)"); + registerAPI(engine, + asMETHODPR(WingAngelAPI, logInfo, (const QString &), void), + "void info(const string &in message)"); - registerAPI( - engine, std::bind(&WingAngelAPI::logTrace, this, std::placeholders::_1), - "void trace(const string &in message)"); + registerAPI(engine, + asMETHODPR(WingAngelAPI, logTrace, (const QString &), void), + "void trace(const string &in message)"); - registerAPI( - engine, std::bind(&WingAngelAPI::logDebug, this, std::placeholders::_1), - "void debug(const string &in message)"); + registerAPI(engine, + asMETHODPR(WingAngelAPI, logDebug, (const QString &), void), + "void debug(const string &in message)"); - registerAPI( - engine, std::bind(&WingAngelAPI::logWarn, this, std::placeholders::_1), - "void warn(const string &in message)"); + registerAPI(engine, + asMETHODPR(WingAngelAPI, logWarn, (const QString &), void), + "void warn(const string &in message)"); - registerAPI( - engine, std::bind(&WingAngelAPI::logError, this, std::placeholders::_1), - "void error(const string &in message)"); + registerAPI(engine, + asMETHODPR(WingAngelAPI, logError, (const QString &), void), + "void error(const string &in message)"); engine->SetDefaultNamespace(""); } void WingAngelAPI::installExtAPI(asIScriptEngine *engine) { // toast(message, iconPath) - registerAPI( + registerAPI( engine, - std::bind(&WingAngelAPI::toast, this, std::placeholders::_2, - std::placeholders::_1), + asMETHODPR(WingAngelAPI, _UI_Toast, (const QString &, const QString &), + void), "void toast(const string &in message, const string &in icon =\"\")"); } @@ -303,75 +295,66 @@ void WingAngelAPI::installMsgboxAPI(asIScriptEngine *engine) { Q_ASSERT(r >= 0); Q_UNUSED(r); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::msgAboutQt, this, nullptr, - std::placeholders::_1), - "void aboutQt(const string &in title =\"\")"); + registerAPI(engine, + asMETHODPR(WingAngelAPI, _MSG_AboutQt, (const QString &), void), + "void aboutQt(const string &in title =\"\")"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::msgInformation, this, nullptr, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4), + asMETHODPR(WingAngelAPI, _MSG_Information, + (const QString &, const QString &, + QMessageBox::StandardButtons, QMessageBox::StandardButton), + QMessageBox::StandardButton), "void information(const string &in title, const string &in text, " "msgbox::buttons buttons = msgbox::buttons::Ok, " "msgbox::buttons defaultButton = msgbox::buttons::NoButton)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::msgQuestion, this, nullptr, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4), + asMETHODPR(WingAngelAPI, _MSG_Question, + (const QString &, const QString &, + QMessageBox::StandardButtons, QMessageBox::StandardButton), + QMessageBox::StandardButton), "void question(const string &in title, const string &in text, " "msgbox::buttons buttons = msgbox::buttons::Yes | " "msgbox::buttons::No, " "msgbox::buttons defaultButton = msgbox::buttons::NoButton)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::msgWarning, this, nullptr, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4), + asMETHODPR(WingAngelAPI, _MSG_Warning, + (const QString &, const QString &, + QMessageBox::StandardButtons, QMessageBox::StandardButton), + QMessageBox::StandardButton), "void warning(const string &in title, const string &in text, " "msgbox::buttons buttons = msgbox::buttons::Ok, " "msgbox::buttons defaultButton = msgbox::buttons::NoButton)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::msgCritical, this, nullptr, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4), + asMETHODPR(WingAngelAPI, _MSG_Critical, + (const QString &, const QString &, + QMessageBox::StandardButtons, QMessageBox::StandardButton), + QMessageBox::StandardButton), "void critical(const string &in title, const string &in text, " "msgbox::buttons buttons = msgbox::buttons::Ok, " "msgbox::buttons defaultButton = msgbox::buttons::NoButton)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::msgbox, this, nullptr, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4, - std::placeholders::_5), + asMETHODPR(WingAngelAPI, _MSG_msgbox, + (QMessageBox::Icon, const QString &, const QString &, + QMessageBox::StandardButtons, QMessageBox::StandardButton), + QMessageBox::StandardButton), "void msgbox(msgbox::icon icon, const string &in title, " "const string &in text, " "msgbox::buttons buttons = msgbox::buttons::NoButton, " "msgbox::buttons defaultButton = msgbox::buttons::NoButton)"); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::msgAbout, this, nullptr, - std::placeholders::_1, std::placeholders::_2), - "void about(const string &in title, const string &in text)"); + registerAPI(engine, + asMETHODPR(WingAngelAPI, _MSG_About, + (const QString &, const QString &), void), + "void about(const string &in title, const string &in text)"); engine->SetDefaultNamespace(""); } @@ -381,64 +364,55 @@ void WingAngelAPI::installInputboxAPI(asIScriptEngine *engine) { Q_ASSERT(r >= 0); Q_UNUSED(r); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::dlgGetText, this, nullptr, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4, - std::placeholders::_5, std::placeholders::_6), + asMETHODPR(WingAngelAPI, _InputBox_GetText, + (const QString &, const QString &, QLineEdit::EchoMode, + const QString &, bool *, Qt::InputMethodHints), + QString), "string getText(const string &in title, const string &in label, " "inputbox::EchoMode echo = inputbox::Normal, " "const string &in text = \"\", bool &out ok = false, " "inputbox::InputMethodHints inputMethodHints = inputbox::ImhNone)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::dlgGetMultiLineText, this, nullptr, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4, - std::placeholders::_5), + asMETHODPR(WingAngelAPI, _InputBox_GetMultiLineText, + (const QString &, const QString &, const QString &, bool *, + Qt::InputMethodHints inputMethodHints), + QString), "string getMultiLineText(const string &in title, " "const string &in label, " "const string &in text = \"\", bool &out ok = false, " "inputbox::InputMethodHints inputMethodHints = inputbox::ImhNone)"); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::dlgGetInt, this, nullptr, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4, - std::placeholders::_5, std::placeholders::_6, - std::placeholders::_7), - "int getInt(const string &in title, const string &in label, " - "int &in value = 0, int &in minValue = -2147483647, " - "int &in maxValue = 2147483647, " - "int &in step = 1, bool &out ok = false)"); + registerAPI(engine, + asMETHODPR(WingAngelAPI, _InputBox_GetInt, + (const QString &, const QString &, int, int, int, + int, bool *), + int), + "int getInt(const string &in title, const string &in label, " + "int &in value = 0, int &in minValue = -2147483647, " + "int &in maxValue = 2147483647, " + "int &in step = 1, bool &out ok = false)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::dlgGetDouble, this, nullptr, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4, - std::placeholders::_5, std::placeholders::_6, - std::placeholders::_7, std::placeholders::_8), + asMETHODPR(WingAngelAPI, _InputBox_GetDouble, + (const QString &, const QString &, double, double, double, + int, bool *, double), + double), "double getDouble(const string &in title, const string &in label, " "double &in value = 0, double &in minValue = -2147483647, " "double &in maxValue = 2147483647, int &in decimals = 1, " "bool &out ok = false, double &in step = 1)"); - registerAPI( + registerAPI( engine, - std::bind(&WingAngelAPI::_InputBox_getItem, this, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3, - std::placeholders::_4, std::placeholders::_5, - std::placeholders::_6, std::placeholders::_7), + asMETHODPR(WingAngelAPI, _InputBox_getItem, + (const QString &, const QString &, const CScriptArray &, int, + bool, bool *, Qt::InputMethodHints), + QString), "string getItem(const string &in title, const string &in label, " "const string[] &in items, int current = 0, " "bool editable = true, bool &out ok = false, " @@ -452,46 +426,41 @@ void WingAngelAPI::installFileDialogAPI(asIScriptEngine *engine) { Q_ASSERT(r >= 0); Q_UNUSED(r); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::dlgGetExistingDirectory, this, nullptr, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3), + asMETHODPR(WingAngelAPI, _FileDialog_GetExistingDirectory, + (const QString &, const QString &, QFileDialog::Options), + QString), "string getExistingDirectory(const string &in caption = \"\", " "const string &in dir = \"\", " "filedlg::options &in options = filedlg::options::ShowDirsOnly)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::dlgGetOpenFileName, this, nullptr, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4, - std::placeholders::_5), + asMETHODPR(WingAngelAPI, _FileDialog_GetOpenFileName, + (const QString &, const QString &, const QString &, + QString *, QFileDialog::Options), + QString), "string getOpenFileName(const string &in caption = \"\", " "const string &in dir = \"\", const string &in filter = \"\", " "string &out selectedFilter = \"\", filedlg::options &in options = 0)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::dlgGetSaveFileName, this, nullptr, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4, - std::placeholders::_5), + asMETHODPR(WingAngelAPI, _FileDialog_GetSaveFileName, + (const QString &, const QString &, const QString &, + QString *, QFileDialog::Options), + QString), "string getSaveFileName(const string &in caption = \"\", " "const string &in dir = \"\", const string &in filter = \"\", " "string &out selectedFilter = \"\", filedlg::options &in options = 0)"); - registerAPI( + registerAPI( engine, - std::bind(&WingAngelAPI::_FileDialog_getOpenFileNames, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4, - std::placeholders::_5), + asMETHODPR(WingAngelAPI, _FileDialog_getOpenFileNames, + (const QString &, const QString &, const QString &, + QString *, QFileDialog::Options), + CScriptArray *), "string[]@ getOpenFileNames(const string &in caption = \"\", " "const string &in dir = \"\", const string &in filter = \"\", " "string &out selectedFilter = \"\", filedlg::options &in options = 0)"); @@ -504,11 +473,9 @@ void WingAngelAPI::installColorDialogAPI(asIScriptEngine *engine) { Q_ASSERT(r >= 0); Q_UNUSED(r); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::dlgGetColor, this, - std::placeholders::_1, nullptr), - "color getColor(const string &in caption)"); + registerAPI(engine, + asMETHODPR(WingAngelAPI, _Color_get, (const QString &), QColor), + "color getColor(const string &in caption)"); engine->SetDefaultNamespace(""); } @@ -577,191 +544,168 @@ void WingAngelAPI::installHexReaderAPI(asIScriptEngine *engine) { Q_ASSERT(r >= 0); Q_UNUSED(r); - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::isCurrentDocEditing, this), + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, isCurrentDocEditing, (void), bool), "bool isCurrentDocEditing()"); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::currentDocFilename, this), + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, currentDocFilename, (void), QString), "string currentDocFilename()"); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::isInsertionMode, this), - "bool isInsertionMode()"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::isReadOnly, this), - "bool isReadOnly()"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::isKeepSize, this), - "bool isKeepSize()"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::isLocked, this), - "bool isLocked()"); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::currentPos, this), - "HexPosition currentPos()"); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::stringVisible, this), - "bool stringVisible()"); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::addressVisible, this), - "bool addressVisible()"); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::headerVisible, this), - "bool headerVisible()"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::isModified, this), - "bool isModified()"); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::documentLines, this), + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, isInsertionMode, (void), bool), + "bool isInsertionMode()"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, isReadOnly, (void), bool), + "bool isReadOnly()"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, isKeepSize, (void), bool), + "bool isKeepSize()"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, isLocked, (void), bool), + "bool isLocked()"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, currentPos, (void), + WingHex::HexPosition), + "HexPosition currentPos()"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, stringVisible, (void), bool), + "bool stringVisible()"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, addressVisible, (void), bool), + "bool addressVisible()"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, headerVisible, (void), bool), + "bool headerVisible()"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, isModified, (void), bool), + "bool isModified()"); + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, documentLines, (void), qsizetype), QSIZETYPE_WRAP("documentLines()")); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::documentBytes, this), + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, documentBytes, (void), qsizetype), QSIZETYPE_WRAP("documentBytes()")); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::currentRow, this), - QSIZETYPE_WRAP("currentRow()")); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::currentColumn, this), + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, currentRow, (void), qsizetype), + QSIZETYPE_WRAP("currentRow()")); + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, currentColumn, (void), qsizetype), QSIZETYPE_WRAP("currentColumn()")); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::currentOffset, this), + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, currentOffset, (void), qsizetype), QSIZETYPE_WRAP("currentOffset()")); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::selectedLength, this), + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, selectedLength, (void), qsizetype), QSIZETYPE_WRAP("selectedLength()")); - registerAPI( + registerAPI(engine, + asMETHODPR(WingAngelAPI, _HexReader_selectedBytes, (qsizetype), + CScriptArray *), + "byte[]@ selectedBytes(" QSIZETYPE " index)"); + registerAPI(engine, + asMETHODPR(WingAngelAPI, _HexReader_selectionBytes, (void), + CScriptArray *), + "byte[][]@ selectionBytes()"); + + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, selectionStart, (qsizetype), + WingHex::HexPosition), + "HexPosition selectionStart(" QSIZETYPE " index)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, selectionEnd, (qsizetype), + WingHex::HexPosition), + "HexPosition selectionEnd(" QSIZETYPE " index)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, selectionLength, (qsizetype), + qsizetype), + QSIZETYPE_WRAP("selectionLength(" QSIZETYPE " index)")); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, selectionCount, (), qsizetype), + QSIZETYPE_WRAP("selectionCount()")); + + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, addressBase, (void), quintptr), + QPTR_WRAP("addressBase()")); + + registerAPI(engine, + asMETHODPR(WingAngelAPI, _HexReader_readBytes, + (qsizetype, qsizetype), CScriptArray *), + "byte[]@ readBytes(" QSIZETYPE " offset," QSIZETYPE " len)"); + + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, readInt8, (qsizetype), qint8), + "int8 readInt8(" QSIZETYPE " offset)"); + registerAPI( engine, - std::bind(&WingAngelAPI::_HexReader_selectedBytes, this, - std::placeholders::_1), - "byte[]@ selectedBytes(" QSIZETYPE " index)"); + asMETHODPR(WingHex::IWingPlugin, readUInt8, (qsizetype), quint8), + "uint8 readUInt8(" QSIZETYPE " offset)"); - registerAPI( - engine, std::bind(&WingAngelAPI::_HexReader_selectionBytes, this), - "byte[][]@ selectionBytes()"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::selectionStart, this, - std::placeholders::_1), - "HexPosition selectionStart(" QSIZETYPE " index)"); - registerAPI( + asMETHODPR(WingHex::IWingPlugin, readInt16, (qsizetype), qint16), + "int16 readInt16(" QSIZETYPE " offset)"); + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::selectionEnd, this, - std::placeholders::_1), - "HexPosition selectionEnd(" QSIZETYPE " index)"); - registerAPI( + asMETHODPR(WingHex::IWingPlugin, readUInt16, (qsizetype), quint16), + "uint16 readUInt16(" QSIZETYPE " offset)"); + + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::selectionLength, this, - std::placeholders::_1), - QSIZETYPE_WRAP("selectionLength(" QSIZETYPE " index)")); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::selectionCount, this), - QSIZETYPE_WRAP("selectionCount()")); - - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::addressBase, this), - QPTR_WRAP("addressBase()")); - - registerAPI( + asMETHODPR(WingHex::IWingPlugin, readInt32, (qsizetype), qint32), + "int readInt32(" QSIZETYPE " offset)"); + registerAPI( engine, - std::bind(&WingAngelAPI::_HexReader_readBytes, this, - std::placeholders::_1, std::placeholders::_2), - "byte[]@ readBytes(" QSIZETYPE " offset," QSIZETYPE " len)"); + asMETHODPR(WingHex::IWingPlugin, readUInt32, (qsizetype), quint32), + "uint readUInt32(" QSIZETYPE " offset)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::readInt8, this, std::placeholders::_1), - "int8 readInt8(" QSIZETYPE " offset)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::readUInt8, - this, std::placeholders::_1), - "uint8 readUInt8(" QSIZETYPE " offset)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::readInt16, - this, std::placeholders::_1), - "int16 readInt16(" QSIZETYPE " offset)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::readUInt16, - this, std::placeholders::_1), - "uint16 readUInt16(" QSIZETYPE " offset)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::readInt32, - this, std::placeholders::_1), - "int readInt32(" QSIZETYPE " offset)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::readUInt32, - this, std::placeholders::_1), - "uint readUInt32(" QSIZETYPE " offset)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::readInt64, - this, std::placeholders::_1), - "int64 readInt64(" QSIZETYPE " offset)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::readUInt64, - this, std::placeholders::_1), - "uint64 readUInt64(" QSIZETYPE " offset)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::readFloat, - this, std::placeholders::_1), - "float readFloat(" QSIZETYPE " offset)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::readDouble, - this, std::placeholders::_1), - "double readDouble(" QSIZETYPE " offset)"); - - registerAPI( + asMETHODPR(WingHex::IWingPlugin, readInt64, (qsizetype), qint64), + "int64 readInt64(" QSIZETYPE " offset)"); + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::readString, this, - std::placeholders::_1, std::placeholders::_2), - "string readInt64(" QSIZETYPE " offset, string &in encoding = \"\")"); + asMETHODPR(WingHex::IWingPlugin, readUInt64, (qsizetype), quint64), + "uint64 readUInt64(" QSIZETYPE " offset)"); - registerAPI( + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, readFloat, (qsizetype), float), + "float readFloat(" QSIZETYPE " offset)"); + registerAPI( engine, - std::bind(&WingAngelAPI::_HexReader_findNext, this, - std::placeholders::_1, std::placeholders::_2), - QSIZETYPE_WRAP("findNext(" QSIZETYPE " begin, byte[] &in ba)")); + asMETHODPR(WingHex::IWingPlugin, readDouble, (qsizetype), double), + "double readDouble(" QSIZETYPE " offset)"); - registerAPI( + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, readString, + (qsizetype, const QString &), QString), + "string readString(" QSIZETYPE + " offset, string &in encoding = \"\")"); + + registerAPI(engine, + asMETHODPR(WingAngelAPI, _HexReader_findNext, + (qsizetype, const CScriptArray &), qsizetype), + QSIZETYPE_WRAP("findNext(" QSIZETYPE " begin, byte[] &in ba)")); + registerAPI( engine, - std::bind(&WingAngelAPI::_HexReader_findPrevious, this, - std::placeholders::_1, std::placeholders::_2), + asMETHODPR(WingAngelAPI, _HexReader_findPrevious, + (qsizetype, const CScriptArray &), qsizetype), QSIZETYPE_WRAP("findPrevious(" QSIZETYPE " begin, byte[] &in ba)")); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::bookMarkComment, this, - std::placeholders::_1), + asMETHODPR(WingHex::IWingPlugin, bookMarkComment, (qsizetype), QString), "string bookMarkComment(" QSIZETYPE " pos)"); - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::existBookMark, - this, std::placeholders::_1), - "bool existBookMark(" QSIZETYPE " pos)"); + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, existBookMark, (qsizetype), bool), + "bool existBookMark(" QSIZETYPE " pos)"); engine->SetDefaultNamespace(""); } @@ -771,505 +715,353 @@ void WingAngelAPI::installHexControllerAPI(asIScriptEngine *engine) { Q_ASSERT(r >= 0); Q_UNUSED(r); - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::switchDocument, - this, std::placeholders::_1), - "bool switchDocument(int handle)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, switchDocument, (int), bool), + "bool switchDocument(int handle)"); - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::setLockedFile, - this, std::placeholders::_1), - "bool setLockedFile(bool b)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::setKeepSize, this, - std::placeholders::_1), - "bool setKeepSize(bool b)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::setStringVisible, - this, std::placeholders::_1), - "bool setStringVisible(bool b)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::setAddressVisible, - this, std::placeholders::_1), - "bool setAddressVisible(bool b)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::setHeaderVisible, - this, std::placeholders::_1), - "bool setHeaderVisible(bool b)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::setAddressBase, - this, std::placeholders::_1), - "bool setAddressBase(" QPTR " base)"); - - registerAPI( + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, setLockedFile, (bool), bool), + "bool setLockedFile(bool b)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, setKeepSize, (bool), bool), + "bool setKeepSize(bool b)"); + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::beginMarco, this, - std::placeholders::_1), + asMETHODPR(WingHex::IWingPlugin, setStringVisible, (bool), bool), + "bool setStringVisible(bool b)"); + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, setAddressVisible, (bool), bool), + "bool setAddressVisible(bool b)"); + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, setHeaderVisible, (bool), bool), + "bool setHeaderVisible(bool b)"); + + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, setAddressBase, (quintptr), bool), + "bool setAddressBase(" QPTR " base)"); + + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, beginMarco, (const QString &), bool), "bool beginMarco(string &in name = \"\")"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, endMarco, (void), bool), + "bool endMarco()"); - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::endMarco, this), - "bool endMarco()"); - - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::writeInt8, this, std::placeholders::_1, - std::placeholders::_2), + asMETHODPR(WingHex::IWingPlugin, writeInt8, (qsizetype, qint8), bool), "bool writeInt8(" QSIZETYPE " offset, int8 value)"); - - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::writeUInt8, this, - std::placeholders::_1, std::placeholders::_2), + asMETHODPR(WingHex::IWingPlugin, writeUInt8, (qsizetype, quint8), bool), "bool writeUInt8(" QSIZETYPE " offset, uint8 value)"); - - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::writeInt16, this, - std::placeholders::_1, std::placeholders::_2), + asMETHODPR(WingHex::IWingPlugin, writeInt16, (qsizetype, qint16), bool), "bool writeInt16(" QSIZETYPE " offset, int16 value)"); - - registerAPI( + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, writeUInt16, + (qsizetype, quint16), bool), + "bool writeUInt16(" QSIZETYPE " offset, uint16 value)"); + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::writeUInt16, this, - std::placeholders::_1, std::placeholders::_2), - "bool writeUInt16(" QSIZETYPE " offset, uint16 value)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::writeInt32, this, - std::placeholders::_1, std::placeholders::_2), + asMETHODPR(WingHex::IWingPlugin, writeInt32, (qsizetype, qint32), bool), "bool writeInt32(" QSIZETYPE " offset, int value)"); - - registerAPI( + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, writeUInt32, + (qsizetype, quint32), bool), + "bool writeUInt32(" QSIZETYPE " offset, uint value)"); + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::writeUInt32, this, - std::placeholders::_1, std::placeholders::_2), - "bool writeUInt32(" QSIZETYPE " offset, uint value)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::writeInt64, this, - std::placeholders::_1, std::placeholders::_2), + asMETHODPR(WingHex::IWingPlugin, writeInt64, (qsizetype, qint64), bool), "bool writeInt64(" QSIZETYPE " offset, int64 value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, writeUInt64, + (qsizetype, quint64), bool), + "bool writeUInt64(" QSIZETYPE " offset, uint64 value)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::writeUInt64, this, - std::placeholders::_1, std::placeholders::_2), - "bool writeUInt64(" QSIZETYPE " offset, uint64 value)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::writeFloat, this, - std::placeholders::_1, std::placeholders::_2), + asMETHODPR(WingHex::IWingPlugin, writeFloat, (qsizetype, float), bool), "bool writeFloat(" QSIZETYPE " offset, float value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, writeDouble, + (qsizetype, double), bool), + "bool writeDouble(" QSIZETYPE " offset, double value)"); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::writeDouble, this, - std::placeholders::_1, std::placeholders::_2), - "bool writeDouble(" QSIZETYPE " offset, double value)"); + registerAPI(engine, + asMETHODPR(WingAngelAPI, _HexController_writeBytes, + (qsizetype, const CScriptArray &), bool), + "bool writeBytes(" QSIZETYPE " offset, byte[] &in data)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, writeString, + (qsizetype, const QString &, const QString &), bool), + "bool writeString(" QSIZETYPE " offset, string &in value, " + "string &in encoding = \"\")"); - registerAPI( + registerAPI( engine, - std::bind(&WingAngelAPI::_HexController_writeBytes, this, - std::placeholders::_1, std::placeholders::_2), - "bool writeBytes(" QSIZETYPE " offset, byte[] &in data)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::writeString, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3), - "bool writeString(" QSIZETYPE " offset, string &in value, " - "string &in encoding = \"\")"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::insertInt8, this, - std::placeholders::_1, std::placeholders::_2), + asMETHODPR(WingHex::IWingPlugin, insertInt8, (qsizetype, qint8), bool), "bool insertInt8(" QSIZETYPE " offset, int8 value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, insertUInt8, + (qsizetype, quint8), bool), + "bool insertUInt8(" QSIZETYPE " offset, uint8 value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, insertInt16, + (qsizetype, qint16), bool), + "bool insertInt16(" QSIZETYPE " offset, int16 value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, insertUInt16, + (qsizetype, quint16), bool), + "bool insertUInt16(" QSIZETYPE " offset, uint16 value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, insertInt32, + (qsizetype, qint32), bool), + "bool insertInt32(" QSIZETYPE " offset, int value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, insertUInt32, + (qsizetype, quint32), bool), + "bool insertUInt32(" QSIZETYPE " offset, uint value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, insertInt64, + (qsizetype, qint64), bool), + "bool insertInt64(" QSIZETYPE " offset, int64 value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, insertUInt64, + (qsizetype, quint64), bool), + "bool insertUInt64(" QSIZETYPE " offset, uint64 value)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::insertUInt8, this, - std::placeholders::_1, std::placeholders::_2), - "bool insertUInt8(" QSIZETYPE " offset, uint8 value)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::insertInt16, this, - std::placeholders::_1, std::placeholders::_2), - "bool insertInt16(" QSIZETYPE " offset, int16 value)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::insertUInt16, this, - std::placeholders::_1, std::placeholders::_2), - "bool insertUInt16(" QSIZETYPE " offset, uint16 value)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::insertInt32, this, - std::placeholders::_1, std::placeholders::_2), - "bool insertInt32(" QSIZETYPE " offset, int value)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::insertUInt32, this, - std::placeholders::_1, std::placeholders::_2), - "bool insertUInt32(" QSIZETYPE " offset, uint value)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::insertInt64, this, - std::placeholders::_1, std::placeholders::_2), - "bool insertInt64(" QSIZETYPE " offset, int64 value)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::insertUInt64, this, - std::placeholders::_1, std::placeholders::_2), - "bool insertUInt64(" QSIZETYPE " offset, uint64 value)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::insertFloat, this, - std::placeholders::_1, std::placeholders::_2), + asMETHODPR(WingHex::IWingPlugin, insertFloat, (qsizetype, float), bool), "bool insertFloat(" QSIZETYPE " offset, float value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, insertDouble, + (qsizetype, double), bool), + "bool insertDouble(" QSIZETYPE " offset, double value)"); - registerAPI( + registerAPI(engine, + asMETHODPR(WingAngelAPI, _HexController_insertBytes, + (qsizetype, const CScriptArray &), bool), + "bool insertBytes(" QSIZETYPE " offset, byte[] &in data)"); + + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, insertString, + (qsizetype, const QString &, const QString &), bool), + "bool insertString(" QSIZETYPE " offset, string &in value, " + "string &in encoding = \"\")"); + + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, appendInt8, (qint8), bool), + "bool appendInt8(int8 value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, appendUInt8, (quint8), bool), + "bool appendUInt8(uint8 value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, appendInt16, (qint16), bool), + "bool appendInt16(int16 value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, appendUInt16, (quint16), bool), + "bool appendUInt16(uint16 value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, appendInt32, (qint32), bool), + "bool appendInt32(int value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, appendUInt32, (quint32), bool), + "bool appendUInt32(uint value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, appendInt64, (qint64), bool), + "bool appendInt64(int64 value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, appendUInt64, (quint64), bool), + "bool appendUInt64(uint value)"); + + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, appendFloat, (float), bool), + "bool appendFloat(float value)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, appendDouble, (double), bool), + "bool appendDouble(double value)"); + + registerAPI(engine, + asMETHODPR(WingAngelAPI, _HexController_appendBytes, + (const CScriptArray &), bool), + "bool appendBytes(byte[] &in data)"); + + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::insertDouble, this, - std::placeholders::_1, std::placeholders::_2), - "bool insertDouble(" QSIZETYPE " offset, double value)"); - - registerAPI( - engine, - std::bind(&WingAngelAPI::_HexController_insertBytes, this, - std::placeholders::_1, std::placeholders::_2), - "bool insertBytes(" QSIZETYPE " offset, byte[] &in data)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::insertString, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3), - "bool insertString(" QSIZETYPE " offset, string &in value, " - "string &in encoding = \"\")"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::appendInt8, this, - std::placeholders::_1), - "bool appendInt8(int8 value)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::appendUInt8, - this, std::placeholders::_1), - "bool appendUInt8(uint8 value)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::appendInt16, - this, std::placeholders::_1), - "bool appendInt16(int16 value)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::appendUInt16, - this, std::placeholders::_1), - "bool appendUInt16(uint16 value)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::appendInt32, - this, std::placeholders::_1), - "bool appendInt32(int value)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::appendUInt32, - this, std::placeholders::_1), - "bool appendUInt32(uint value)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::appendInt64, - this, std::placeholders::_1), - "bool appendInt64(int64 value)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::appendUInt64, - this, std::placeholders::_1), - "bool appendUInt64(uint64 value)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::appendFloat, this, - std::placeholders::_1), - "bool appendFloat(float value)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::appendDouble, - this, std::placeholders::_1), - "bool appendDouble(double value)"); - - registerAPI( - engine, - std::bind(&WingAngelAPI::_HexController_appendBytes, this, - std::placeholders::_1), - "bool appendBytes(byte[] &in data)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::appendString, this, - std::placeholders::_1, std::placeholders::_2), + asMETHODPR(WingHex::IWingPlugin, appendString, + (const QString &, const QString &), bool), "bool appendString(string &in value, string &in encoding = \"\")"); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::removeBytes, this, - std::placeholders::_1, std::placeholders::_2), - "bool removeBytes(" QSIZETYPE " offset, " QSIZETYPE " len)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, removeBytes, + (qsizetype, qsizetype), bool), + "bool removeBytes(" QSIZETYPE " offset, " QSIZETYPE " len)"); - registerAPI( + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, moveTo, + (qsizetype, qsizetype, int, bool), bool), + "bool moveTo(" QSIZETYPE " line, " QSIZETYPE + " column, int nibbleindex = -1, bool clearSelection = true)"); + registerAPI( engine, - std::bind(QOverload::of( - &WingHex::IWingPlugin::moveTo), - this, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4), - "bool moveTo(" QSIZETYPE " line, " QSIZETYPE - " column, int nibbleindex = -1, bool clearSelection = true)"); - - registerAPI( - engine, - std::bind(QOverload::of(&WingHex::IWingPlugin::moveTo), - this, std::placeholders::_1, std::placeholders::_2), + asMETHODPR(WingHex::IWingPlugin, moveTo, (qsizetype, bool), bool), "bool moveTo(" QSIZETYPE " offset, bool clearSelection = true)"); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::select, this, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3), - "bool select(" QSIZETYPE " offset, " QSIZETYPE - " len, SelectionMode mode = SelectionMode::Add)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, select, + (qsizetype, qsizetype, WingHex::SelectionMode), + bool), + "bool select(" QSIZETYPE " offset, " QSIZETYPE + " len, SelectionMode mode = SelectionMode::Add)"); - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::setInsertionMode, - this, std::placeholders::_1), - "bool setInsertionMode(bool b)"); - - registerAPI( + registerAPI( engine, - std::bind( - QOverload::of(&WingHex::IWingPlugin::metadata), - this, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4, - std::placeholders::_5), + asMETHODPR(WingHex::IWingPlugin, setInsertionMode, (bool), bool), + "bool setInsertionMode(bool b)"); + + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, metadata, + (qsizetype, qsizetype, const QColor &, const QColor &, + const QString &), + bool), "bool metadata(" QSIZETYPE " begin, " QSIZETYPE " length, color &in fgcolor, color &in bgcolor, string &in comment)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::removeMetadata, this, - std::placeholders::_1), + asMETHODPR(WingHex::IWingPlugin, removeMetadata, (qsizetype), bool), "bool removeMetadata(" QSIZETYPE " offset)"); - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::clearMetadata, this), - "bool clearMetadata()"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, clearMetadata, (), bool), + "bool clearMetadata()"); - registerAPI( + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, foreground, + (qsizetype, qsizetype, const QColor &), bool), + "bool foreground(" QSIZETYPE " begin, " QSIZETYPE + " length, color &in fgcolor)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, background, + (qsizetype, qsizetype, const QColor &), bool), + "bool background(" QSIZETYPE " begin, " QSIZETYPE + " length, color &in bgcolor)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, comment, + (qsizetype, qsizetype, const QString &), bool), + "bool comment(" QSIZETYPE " begin, " QSIZETYPE + " length, string &in comment)"); + + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, setMetaVisible, (bool), bool), + "bool setMetaVisible(bool b)"); + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::foreground, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3), - "bool foreground(" QSIZETYPE " begin, " QSIZETYPE - " length, color &in fgcolor)"); - - registerAPI( + asMETHODPR(WingHex::IWingPlugin, setMetafgVisible, (bool), bool), + "bool setMetafgVisible(bool b)"); + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::background, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3), - "bool background(" QSIZETYPE " begin, " QSIZETYPE - " length, color &in bgcolor)"); - - registerAPI( + asMETHODPR(WingHex::IWingPlugin, setMetabgVisible, (bool), bool), + "bool setMetabgVisible(bool b)"); + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::comment, this, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3), - "bool comment(" QSIZETYPE " begin, " QSIZETYPE - " length, string &in comment)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::setMetaVisible, - this, std::placeholders::_1), - "bool setMetaVisible(bool b)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::setMetafgVisible, - this, std::placeholders::_1), - "bool setMetafgVisible(bool b)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::setMetabgVisible, - this, std::placeholders::_1), - "bool setMetabgVisible(bool b)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::setMetaCommentVisible, this, - std::placeholders::_1), + asMETHODPR(WingHex::IWingPlugin, setMetaCommentVisible, (bool), bool), "bool setMetaCommentVisible(bool b)"); - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::newFile, this), - "ErrFile newFile()"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, newFile, (), WingHex::ErrFile), + "ErrFile newFile()"); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::openFile, this, std::placeholders::_1), - "ErrFile openFile(string &in filename)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, openFile, (const QString &), + WingHex::ErrFile), + "ErrFile openFile(string &in filename)"); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::openExtFile, this, - std::placeholders::_1, std::placeholders::_2), - "ErrFile openExtFile(string &in ext, string &in file)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, openExtFile, + (const QString &, const QString &), + WingHex::ErrFile), + "ErrFile openExtFile(string &in ext, string &in file)"); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::closeFile, this, std::placeholders::_1, - std::placeholders::_2), - "ErrFile closeFile(int handle, bool force = false)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, closeFile, (int, bool), + WingHex::ErrFile), + "ErrFile closeFile(int handle, bool force = false)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::closeHandle, this, - std::placeholders::_1), + asMETHODPR(WingHex::IWingPlugin, closeHandle, (int), WingHex::ErrFile), "ErrFile closeHandle(int handle)"); - registerAPI( + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::saveFile, this, std::placeholders::_1), + asMETHODPR(WingHex::IWingPlugin, saveFile, (int), WingHex::ErrFile), "ErrFile saveFile(int handle)"); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::exportFile, this, - std::placeholders::_1, std::placeholders::_2), - "ErrFile exportFile(int handle, string &in savename)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, exportFile, + (int, const QString &), WingHex::ErrFile), + "ErrFile exportFile(int handle, string &in savename)"); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::saveAsFile, this, - std::placeholders::_1, std::placeholders::_2), - "ErrFile saveAsFile(int handle, string &in savename)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, saveAsFile, + (int, const QString &), WingHex::ErrFile), + "ErrFile saveAsFile(int handle, string &in savename)"); - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::openCurrent, this), + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, openCurrent, (), WingHex::ErrFile), "ErrFile openCurrent()"); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::closeCurrent, this, - std::placeholders::_1), - "ErrFile closeCurrent(bool force = false)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, closeCurrent, (bool), + WingHex::ErrFile), + "ErrFile closeCurrent(bool force = false)"); - registerAPI( - engine, std::bind(&WingHex::IWingPlugin::saveCurrent, this), + registerAPI( + engine, + asMETHODPR(WingHex::IWingPlugin, saveCurrent, (), WingHex::ErrFile), "ErrFile saveCurrent()"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, saveAsCurrent, + (const QString &), WingHex::ErrFile), + "ErrFile saveAsCurrent(string &in savename)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, exportCurrent, + (const QString &), WingHex::ErrFile), + "ErrFile exportCurrent(string &in savename)"); - registerAPI( + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, addBookMark, + (qsizetype, const QString &), bool), + "bool addBookMark(" QSIZETYPE " pos, string &in comment)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, modBookMark, + (qsizetype, const QString &), bool), + "bool modBookMark(" QSIZETYPE " pos, string &in comment)"); + registerAPI( engine, - std::bind(&WingHex::IWingPlugin::saveAsCurrent, this, - std::placeholders::_1), - "ErrFile saveAsCurrent(string &in savename)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::exportCurrent, this, - std::placeholders::_1), - "ErrFile exportCurrent(string &in savename)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::addBookMark, this, - std::placeholders::_1, std::placeholders::_2), - "bool addBookMark(" QSIZETYPE " pos, string &in comment)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::modBookMark, this, - std::placeholders::_1, std::placeholders::_2), - "bool modBookMark(" QSIZETYPE " pos, string &in comment)"); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::removeBookMark, this, - std::placeholders::_1), + asMETHODPR(WingHex::IWingPlugin, removeBookMark, (qsizetype), bool), "bool removeBookMark(" QSIZETYPE " pos)"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, clearBookMark, (), bool), + "bool clearBookMark()"); - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::clearBookMark, this), - "bool clearBookMark()"); + registerAPI(engine, + asMETHODPR(WingHex::IWingPlugin, openWorkSpace, + (const QString &), WingHex::ErrFile), + "ErrFile openWorkSpace(string &in filename)"); - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::openWorkSpace, this, - std::placeholders::_1), - "ErrFile openWorkSpace(string &in filename)"); - - registerAPI(engine, - std::bind(&WingHex::IWingPlugin::closeAllFiles, this), - "bool closeAll()"); - - engine->SetDefaultNamespace(""); -} - -void WingAngelAPI::installDataVisualAPI(asIScriptEngine *engine) { - int r = engine->SetDefaultNamespace("visual"); - Q_ASSERT(r >= 0); - Q_UNUSED(r); - - registerAPI( - engine, - std::bind(&WingHex::IWingPlugin::dataVisualText, this, - std::placeholders::_1, std::placeholders::_2), - "bool updateText(string &in data, string &in title=\"\")"); - - registerAPI( - engine, - std::bind(&WingAngelAPI::_DataVisual_updateTextList, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4), - "bool updateTextList(string[] &in data, string &in title=\"\", " - "ClickCallBack @clickfn = null, ClickCallBack @dblclick = null)"); - - registerAPI( - engine, - std::bind(&WingAngelAPI::_DataVisual_updateTextTree, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4), - "bool updateTextTree(string &in json, string &in title=\"\", " - "ClickCallBack @clickfn = null, ClickCallBack @dblclick = null)"); - - registerAPI( - engine, - std::bind(&WingAngelAPI::_DataVisual_updateTextTable, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4, - std::placeholders::_5, std::placeholders::_6), - "bool updateTextTable(string &in json, string[] &in headers, " - "string[] &in headerNames = {}, string &in title=\"\", " - "ClickCallBack @clickfn = null, ClickCallBack @dblclick = null)"); + registerAPI(engine, asMETHOD(WingHex::IWingPlugin, closeAllFiles), + "bool closeAll()"); engine->SetDefaultNamespace(""); } @@ -1357,6 +1149,14 @@ void WingAngelAPI::installScriptEnums(asIScriptEngine *engine) { } } +void WingAngelAPI::registerAPI(asIScriptEngine *engine, const asSFuncPtr &fn, + const char *sig) { + auto r = + engine->RegisterGlobalFunction(sig, fn, asCALL_THISCALL_ASGLOBAL, this); + Q_ASSERT(r >= 0); + Q_UNUSED(r); +} + QStringList WingAngelAPI::cArray2QStringList(const CScriptArray &array, int stringID, bool *ok) { bool b = array.GetElementTypeId() == stringID; @@ -2247,42 +2047,6 @@ void WingAngelAPI::cleanUpHandles(const QVector &handles) { _handles = handles; } -QString WingAngelAPI::_InputBox_getItem(const QString &title, - const QString &label, - const CScriptArray &items, int current, - bool editable, bool *ok, - Qt::InputMethodHints inputMethodHints) { - asIScriptContext *ctx = asGetActiveContext(); - if (ctx) { - auto engine = ctx->GetEngine(); - Q_ASSERT(engine); - auto stringID = engine->GetTypeIdByDecl("string"); - Q_ASSERT(stringID >= 0); - - bool o = false; - auto ret = cArray2QStringList(items, stringID, &o); - if (o) { - return WingInputDialog::getItem(nullptr, title, label, ret, current, - editable, ok, inputMethodHints); - } else { - *ok = false; - return {}; - } - } - return {}; -} - -CScriptArray *WingAngelAPI::_FileDialog_getOpenFileNames( - const QString &caption, const QString &dir, const QString &filter, - QString *selectedFilter, QFileDialog::Options options) { - return retarrayWrapperFunction( - [&]() -> QStringList { - return WingFileDialog::getOpenFileNames( - nullptr, caption, dir, filter, selectedFilter, options); - }, - "array"); -} - CScriptArray *WingAngelAPI::_HexReader_selectedBytes(qsizetype index) { return byteArrayWrapperFunction( [this, index]() -> QByteArray { return selectedBytes(index); }); @@ -2422,10 +2186,78 @@ bool WingAngelAPI::_HexController_appendBytes(const CScriptArray &ba) { return false; } -bool WingAngelAPI::_DataVisual_updateTextList(const CScriptArray &data, - const QString &title, - asIScriptFunction *click, - asIScriptFunction *dblclick) { +void WingAngelAPI::_UI_Toast(const QString &message, const QString &icon) { + toast(QPixmap(icon), message); +} + +QColor WingAngelAPI::_Color_get(const QString &caption) { + return dlgGetColor(caption); +} + +void WingAngelAPI::_MSG_AboutQt(const QString &title) { + msgAboutQt(nullptr, title); +} + +QMessageBox::StandardButton +WingAngelAPI::_MSG_Information(const QString &title, const QString &text, + QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton) { + return msgInformation(nullptr, title, text, buttons, defaultButton); +} + +QMessageBox::StandardButton +WingAngelAPI::_MSG_Question(const QString &title, const QString &text, + QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton) { + return msgQuestion(nullptr, title, text, buttons, defaultButton); +} + +QMessageBox::StandardButton +WingAngelAPI::_MSG_Warning(const QString &title, const QString &text, + QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton) { + return msgWarning(nullptr, title, text, buttons, defaultButton); +} + +QMessageBox::StandardButton +WingAngelAPI::_MSG_Critical(const QString &title, const QString &text, + QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton) { + return msgCritical(nullptr, title, text, buttons, defaultButton); +} + +void WingAngelAPI::_MSG_About(const QString &title, const QString &text) { + return msgAbout(nullptr, title, text); +} + +QMessageBox::StandardButton +WingAngelAPI::_MSG_msgbox(QMessageBox::Icon icon, const QString &title, + const QString &text, + QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton) { + return msgbox(nullptr, icon, title, text, buttons, defaultButton); +} + +QString WingAngelAPI::_InputBox_GetText(const QString &title, + const QString &label, + QLineEdit::EchoMode echo, + const QString &text, bool *ok, + Qt::InputMethodHints inputMethodHints) { + return dlgGetText(nullptr, title, label, echo, text, ok, inputMethodHints); +} + +QString WingAngelAPI::_InputBox_GetMultiLineText( + const QString &title, const QString &label, const QString &text, bool *ok, + Qt::InputMethodHints inputMethodHints) { + return dlgGetMultiLineText(nullptr, title, label, text, ok, + inputMethodHints); +} + +QString WingAngelAPI::_InputBox_getItem(const QString &title, + const QString &label, + const CScriptArray &items, int current, + bool editable, bool *ok, + Qt::InputMethodHints inputMethodHints) { asIScriptContext *ctx = asGetActiveContext(); if (ctx) { auto engine = ctx->GetEngine(); @@ -2433,65 +2265,60 @@ bool WingAngelAPI::_DataVisual_updateTextList(const CScriptArray &data, auto stringID = engine->GetTypeIdByDecl("string"); Q_ASSERT(stringID >= 0); - // we dont call visual.updateTextList bool o = false; - auto ret = cArray2QStringList(data, stringID, &o); + auto ret = cArray2QStringList(items, stringID, &o); if (o) { - ClickCallBack c(engine, click); - ClickCallBack dblc(engine, dblclick); - - return PluginSystem::instance().updateTextList_API(ret, title, c, - dblc); + return WingInputDialog::getItem(nullptr, title, label, ret, current, + editable, ok, inputMethodHints); + } else { + *ok = false; + return {}; } } - return false; + return {}; } -bool WingAngelAPI::_DataVisual_updateTextTree(const QString &json, - const QString &title, - asIScriptFunction *click, - asIScriptFunction *dblclick) { - asIScriptContext *ctx = asGetActiveContext(); - if (ctx) { - auto engine = ctx->GetEngine(); - Q_ASSERT(engine); - - // we dont call visual.updateTextTree - ClickCallBack c(engine, click); - ClickCallBack dblc(engine, dblclick); - - return PluginSystem::instance().updateTextTree_API(json, title, c, - dblc); - } - return false; +int WingAngelAPI::_InputBox_GetInt(const QString &title, const QString &label, + int value, int minValue, int maxValue, + int step, bool *ok) { + return dlgGetInt(nullptr, title, label, value, minValue, maxValue, step, + ok); } -bool WingAngelAPI::_DataVisual_updateTextTable(const QString &json, - const CScriptArray &headers, - const CScriptArray &headerNames, - const QString &title, - asIScriptFunction *click, - asIScriptFunction *dblclick) { - asIScriptContext *ctx = asGetActiveContext(); - if (ctx) { - auto engine = ctx->GetEngine(); - Q_ASSERT(engine); - auto stringID = engine->GetTypeIdByDecl("string"); - Q_ASSERT(stringID >= 0); - - // we dont call visual.updateTextTable - bool o = false; - auto h = cArray2QStringList(headers, stringID, &o); - if (o) { - auto hn = cArray2QStringList(headerNames, stringID, &o); - if (o) { - ClickCallBack c(engine, click); - ClickCallBack dblc(engine, dblclick); - - return PluginSystem::instance().updateTextTable_API( - json, h, hn, title, c, dblc); - } - } - } - return false; +double WingAngelAPI::_InputBox_GetDouble(const QString &title, + const QString &label, double value, + double minValue, double maxValue, + int decimals, bool *ok, double step) { + return dlgGetDouble(nullptr, title, label, value, minValue, maxValue, + decimals, ok, step); +} + +QString WingAngelAPI::_FileDialog_GetExistingDirectory( + const QString &caption, const QString &dir, QFileDialog::Options options) { + return dlgGetExistingDirectory(nullptr, caption, dir, options); +} + +QString WingAngelAPI::_FileDialog_GetOpenFileName( + const QString &caption, const QString &dir, const QString &filter, + QString *selectedFilter, QFileDialog::Options options) { + return dlgGetOpenFileName(nullptr, caption, dir, filter, selectedFilter, + options); +} + +CScriptArray *WingAngelAPI::_FileDialog_getOpenFileNames( + const QString &caption, const QString &dir, const QString &filter, + QString *selectedFilter, QFileDialog::Options options) { + return retarrayWrapperFunction( + [&]() -> QStringList { + return WingFileDialog::getOpenFileNames( + nullptr, caption, dir, filter, selectedFilter, options); + }, + "array"); +} + +QString WingAngelAPI::_FileDialog_GetSaveFileName( + const QString &caption, const QString &dir, const QString &filter, + QString *selectedFilter, QFileDialog::Options options) { + return dlgGetSaveFileName(nullptr, caption, dir, filter, selectedFilter, + options); } diff --git a/src/class/wingangelapi.h b/src/class/wingangelapi.h index 2a55fb0..3e49fac 100644 --- a/src/class/wingangelapi.h +++ b/src/class/wingangelapi.h @@ -23,9 +23,7 @@ #include -#include #include -#include class asIScriptEngine; class ScriptMachine; @@ -97,25 +95,13 @@ private: void installHexBaseType(asIScriptEngine *engine); void installHexReaderAPI(asIScriptEngine *engine); void installHexControllerAPI(asIScriptEngine *engine); - void installDataVisualAPI(asIScriptEngine *engine); void installScriptFns(asIScriptEngine *engine); void installScriptUnSafeFns(asIScriptEngine *engine); void installScriptEnums(asIScriptEngine *engine); private: - template - void registerAPI(asIScriptEngine *engine, const std::function &fn, - const char *sig) { - _fnbuffer.push_back(fn); - auto r = engine->RegisterGlobalFunction( - sig, asMETHOD(std::function, operator()), - asCALL_THISCALL_ASGLOBAL, - std::any_cast>(&_fnbuffer.back())); - Q_ASSERT(r >= 0); - Q_UNUSED(r); - } - - using WrapperFn = std::function; + void registerAPI(asIScriptEngine *engine, const asSFuncPtr &fn, + const char *sig); private: QStringList cArray2QStringList(const CScriptArray &array, int stringID, @@ -203,17 +189,6 @@ private: void cleanUpHandles(const QVector &handles); private: - QString _InputBox_getItem(const QString &title, const QString &label, - const CScriptArray &items, int current, - bool editable, bool *ok, - Qt::InputMethodHints inputMethodHints); - - CScriptArray *_FileDialog_getOpenFileNames(const QString &caption, - const QString &dir, - const QString &filter, - QString *selectedFilter, - QFileDialog::Options options); - CScriptArray *_HexReader_selectedBytes(qsizetype index); CScriptArray *_HexReader_selectionBytes(); @@ -230,26 +205,86 @@ private: bool _HexController_appendBytes(const CScriptArray &ba); -private: - bool _DataVisual_updateTextList(const CScriptArray &data, - const QString &title, - asIScriptFunction *click, - asIScriptFunction *dblclick); + void _UI_Toast(const QString &message, const QString &icon); - bool _DataVisual_updateTextTree(const QString &json, const QString &title, - asIScriptFunction *click, - asIScriptFunction *dblclick); - - bool _DataVisual_updateTextTable(const QString &json, - const CScriptArray &headers, - const CScriptArray &headerNames, - const QString &title, - asIScriptFunction *click, - asIScriptFunction *dblclick); + QColor _Color_get(const QString &caption); private: - std::vector _fnbuffer; + void _MSG_AboutQt(const QString &title); + QMessageBox::StandardButton + _MSG_Information(const QString &title, const QString &text, + QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton); + + QMessageBox::StandardButton + _MSG_Question(const QString &title, const QString &text, + QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton); + + QMessageBox::StandardButton + _MSG_Warning(const QString &title, const QString &text, + QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton); + + QMessageBox::StandardButton + _MSG_Critical(const QString &title, const QString &text, + QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton); + + void _MSG_About(const QString &title, const QString &text); + + QMessageBox::StandardButton + _MSG_msgbox(QMessageBox::Icon icon, const QString &title, + const QString &text, QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton); + +private: + QString _InputBox_GetText(const QString &title, const QString &label, + QLineEdit::EchoMode echo, const QString &text, + bool *ok, Qt::InputMethodHints inputMethodHints); + + QString _InputBox_GetMultiLineText(const QString &title, + const QString &label, + const QString &text, bool *ok, + Qt::InputMethodHints inputMethodHints); + + QString _InputBox_getItem(const QString &title, const QString &label, + const CScriptArray &items, int current, + bool editable, bool *ok, + Qt::InputMethodHints inputMethodHints); + + int _InputBox_GetInt(const QString &title, const QString &label, int value, + int minValue, int maxValue, int step, bool *ok); + + double _InputBox_GetDouble(const QString &title, const QString &label, + double value, double minValue, double maxValue, + int decimals, bool *ok, double step); + +private: + QString _FileDialog_GetExistingDirectory(const QString &caption, + const QString &dir, + QFileDialog::Options options); + + QString _FileDialog_GetOpenFileName(const QString &caption, + const QString &dir, + const QString &filter, + QString *selectedFilter, + QFileDialog::Options options); + + CScriptArray *_FileDialog_getOpenFileNames(const QString &caption, + const QString &dir, + const QString &filter, + QString *selectedFilter, + QFileDialog::Options options); + + QString _FileDialog_GetSaveFileName(const QString &caption, + const QString &dir, + const QString &filter, + QString *selectedFilter, + QFileDialog::Options options); + +private: QVector _sfns; QHash> _rfns; diff --git a/src/components.md b/src/components.md index aee5214..b955e62 100644 --- a/src/components.md +++ b/src/components.md @@ -13,5 +13,4 @@ The following components are all third-party components used by the software. Th * [cpptrace](https://github.com/jeremy-rifkin/cpptrace) (MIT) * [QConsoleWidget](https://github.com/gapost/qconsolewidget) (MIT, **FORK** -> AGPL-3.0) * [QColorPicker](https://github.com/arsdever/qcolorpicker) (MIT) -* [QtJsonModel](https://github.com/dridk/QJsonmodel) (MIT) * [Qt](https://www.qt.io/) (LGPL) diff --git a/src/dialog/mainwindow.cpp b/src/dialog/mainwindow.cpp index 07950fc..136334d 100644 --- a/src/dialog/mainwindow.cpp +++ b/src/dialog/mainwindow.cpp @@ -565,7 +565,6 @@ void MainWindow::buildUpDockSystem(QWidget *container) { qApp->processEvents(); } - buildUpVisualDataDock(m_dock, ads::CenterDockWidgetArea, bottomLeftArea); qApp->processEvents(); m_bottomViewArea = bottomRightArea; @@ -1029,265 +1028,6 @@ MainWindow::buildUpScriptBgOutputDock(ads::CDockManager *dock, return dock->addDockWidget(area, dw, areaw); } -ads::CDockAreaWidget * -MainWindow::buildUpVisualDataDock(ads::CDockManager *dock, - ads::DockWidgetArea area, - ads::CDockAreaWidget *areaw) { - using namespace ads; - - auto efilter = new EventFilter(QEvent::DynamicPropertyChange, this); - connect(efilter, &EventFilter::eventTriggered, this, - [](QObject *obj, QEvent *event) { - auto e = static_cast(event); - constexpr auto ppname = "__TITLE__"; - if (e->propertyName() == QByteArray(ppname)) { - auto title = obj->property(ppname).toString(); - auto display = obj->property("__DISPLAY__").toString(); - auto dock = reinterpret_cast( - obj->property("__DOCK__").value()); - if (dock) { - if (!title.isEmpty()) { - display += QStringLiteral("(") + title + - QStringLiteral(")"); - } - dock->setWindowTitle(display); - } - } - }); - - constexpr auto dpname = "__DISPLAY__"; - constexpr auto dockpname = "__DOCK__"; - - m_infolist = new QListView(this); - m_infolist->setEditTriggers(QListView::EditTrigger::NoEditTriggers); - connect(m_infolist, &QListView::clicked, this, - [this](const QModelIndex &index) { - if (m_infoclickfn) { - m_infoclickfn(index); - } - }); - connect(m_infolist, &QListView::doubleClicked, this, - [this](const QModelIndex &index) { - if (m_infodblclickfn) { - m_infodblclickfn(index); - } - }); - auto dw = buildDockWidget(dock, QStringLiteral("DVList"), tr("DVList"), - m_infolist); - m_infolist->setProperty(dpname, tr("DVList")); - m_infolist->setProperty(dockpname, quintptr(dw)); - m_infolist->installEventFilter(efilter); - m_infolist->setContextMenuPolicy(Qt::ActionsContextMenu); - m_infolist->addAction( - newAction(QStringLiteral("copy"), tr("Copy"), [this]() { - auto idx = m_infolist->currentIndex(); - if (idx.isValid()) { - qApp->clipboard()->setText( - m_infolist->model()->data(idx).toString()); - Toast::toast(this, NAMEICONRES(QStringLiteral("copy")), - tr("CopyToClipBoard")); - } - })); - m_infolist->addAction( - newAction(QStringLiteral("export"), tr("ExportResult"), [this]() { - auto model = m_infotable->model(); - if (!model) { - Toast::toast(this, NAMEICONRES(QStringLiteral("save")), - tr("NothingToSave")); - return; - } - - auto filename = WingFileDialog::getSaveFileName( - this, tr("ChooseSaveFile"), m_lastusedpath, - QStringLiteral("TXT (*.txt)")); - if (filename.isEmpty()) { - return; - } - QFile f(filename); - if (!f.open(QFile::WriteOnly | QFile::Text)) { - WingMessageBox::critical(this, tr("Error"), - tr("FilePermission")); - return; - } - - auto total = model->rowCount(); - for (int i = 0; i < total; ++i) { - f.write(model->data(model->index(i, 0)).toString().toUtf8()); - f.write("\n"); - } - f.close(); - Toast::toast(this, NAMEICONRES(QStringLiteral("save")), - tr("SaveSuccessfully")); - })); - m_infolist->addAction( - newAction(QStringLiteral("del"), tr("ClearResult"), [this]() { - auto model = m_infolist->model(); - model->removeRows(0, model->rowCount()); - m_infolist->setProperty("__TITLE__", {}); - })); - auto ar = dock->addDockWidget(area, dw, areaw); - - m_infotree = new QTreeView(this); - m_infotree->setEditTriggers(QTreeView::EditTrigger::NoEditTriggers); - connect(m_infotree, &QTreeView::clicked, this, - [this](const QModelIndex &index) { - if (m_infotreeclickfn) { - m_infotreeclickfn(index); - } - }); - connect(m_infotree, &QTreeView::doubleClicked, this, - [this](const QModelIndex &index) { - if (m_infotreedblclickfn) { - m_infotreedblclickfn(index); - } - }); - dw = buildDockWidget(dock, QStringLiteral("DVTree"), tr("DVTree"), - m_infotree); - m_infotree->setProperty(dpname, tr("DVTree")); - m_infotree->setProperty(dockpname, quintptr(dw)); - m_infotree->installEventFilter(efilter); - m_infotree->setContextMenuPolicy(Qt::ActionsContextMenu); - m_infotree->addAction( - newAction(QStringLiteral("copy"), tr("Copy"), [this]() { - auto idx = m_infotree->currentIndex(); - if (idx.isValid()) { - qApp->clipboard()->setText( - m_infotree->model()->data(idx).toString()); - Toast::toast(this, NAMEICONRES(QStringLiteral("copy")), - tr("CopyToClipBoard")); - } - })); - m_infotree->addAction( - newAction(QStringLiteral("export"), tr("ExportResult"), [this]() { - auto model = m_infotable->model(); - if (!model) { - Toast::toast(this, NAMEICONRES(QStringLiteral("save")), - tr("NothingToSave")); - return; - } - - auto filename = WingFileDialog::getSaveFileName( - this, tr("ChooseSaveFile"), m_lastusedpath, - QStringLiteral("Json (*.json)")); - if (filename.isEmpty()) { - return; - } - - QJsonArray rootArray; - for (int row = 0; row < model->rowCount(); ++row) { - QModelIndex index = model->index(row, 0); - rootArray.append(extractModelData(model, index)); - } - - QJsonDocument jsonDocument(rootArray); - QFile file(filename); - if (!file.open(QFile::WriteOnly | QFile::Text)) { - WingMessageBox::critical(this, tr("Error"), - tr("FilePermission")); - return; - } - - file.write(jsonDocument.toJson(QJsonDocument::Indented)); - file.close(); - Toast::toast(this, NAMEICONRES(QStringLiteral("save")), - tr("SaveSuccessfully")); - })); - m_infotree->addAction( - newAction(QStringLiteral("del"), tr("ClearResult"), [this]() { - auto model = m_infotree->model(); - model->removeRows(0, model->rowCount()); - m_infotree->setProperty("__TITLE__", {}); - })); - dock->addDockWidget(CenterDockWidgetArea, dw, ar); - - m_infotable = new QTableView(this); - m_infotable->setEditTriggers(QTableView::EditTrigger::NoEditTriggers); - connect(m_infotable, &QTableView::clicked, this, - [this](const QModelIndex &index) { - if (m_infotableclickfn) { - m_infotableclickfn(index); - } - }); - connect(m_infotable, &QTableView::doubleClicked, this, - [this](const QModelIndex &index) { - if (m_infotabledblclickfn) { - m_infotabledblclickfn(index); - } - }); - dw = buildDockWidget(dock, QStringLiteral("DVTable"), tr("DVTable"), - m_infotable); - m_infotable->setProperty(dpname, tr("DVTable")); - m_infotable->setProperty(dockpname, quintptr(dw)); - m_infotable->installEventFilter(efilter); - m_infotable->setContextMenuPolicy(Qt::ActionsContextMenu); - m_infotable->addAction( - newAction(QStringLiteral("copy"), tr("Copy"), [this]() { - auto idx = m_infotable->currentIndex(); - if (idx.isValid()) { - qApp->clipboard()->setText( - m_infotable->model()->data(idx).toString()); - Toast::toast(this, NAMEICONRES(QStringLiteral("copy")), - tr("CopyToClipBoard")); - } - })); - m_infotable->addAction( - newAction(QStringLiteral("export"), tr("ExportResult"), [this]() { - auto model = m_infotable->model(); - saveTableContent(model); - })); - m_infotable->addAction( - newAction(QStringLiteral("del"), tr("ClearResult"), [this]() { - auto model = m_infotable->model(); - model->removeRows(0, model->rowCount()); - m_infotable->setProperty("__TITLE__", {}); - })); - dock->addDockWidget(CenterDockWidgetArea, dw, ar); - - m_infotxt = new QTextBrowser(this); - dw = buildDockWidget(dock, QStringLiteral("DVText"), tr("DVText"), - m_infotxt); - m_infotxt->setProperty(dpname, tr("DVText")); - m_infotxt->setProperty(dockpname, quintptr(dw)); - m_infotxt->installEventFilter(efilter); - m_infotxt->setContextMenuPolicy(Qt::CustomContextMenu); - auto menu = m_infotxt->createStandardContextMenu(); - menu->addSeparator(); - menu->addAction( - newAction(QStringLiteral("export"), tr("ExportResult"), [this]() { - auto filename = WingFileDialog::getSaveFileName( - this, tr("ChooseSaveFile"), m_lastusedpath, - QStringLiteral("TXT (*.txt)")); - if (filename.isEmpty()) { - return; - } - - QFile file(filename); - if (!file.open(QFile::WriteOnly | QFile::Text)) { - WingMessageBox::critical(this, tr("Error"), - tr("FilePermission")); - return; - } - - file.write(m_infotxt->toPlainText().toUtf8()); - - Toast::toast(this, NAMEICONRES(QStringLiteral("save")), - tr("SaveSuccessfully")); - })); - menu->addAction( - newAction(QStringLiteral("del"), tr("ClearResult"), [this]() { - m_infotxt->clear(); - m_infotxt->setProperty("__TITLE__", {}); - })); - connect(m_infotxt, &QTextBrowser::customContextMenuRequested, this, - [=](const QPoint &pos) { - menu->popup(m_infotxt->viewport()->mapToGlobal(pos)); - }); - - dock->addDockWidget(CenterDockWidgetArea, dw, ar); - - return ar; -} - RibbonTabContent *MainWindow::buildFilePage(RibbonTabContent *tab) { auto shortcuts = QKeySequences::instance(); { @@ -4035,32 +3775,6 @@ void MainWindow::onOutputBgScriptOutput( lastInfo.second = qMakePair(message.row, message.col); } -QJsonObject MainWindow::extractModelData(const QAbstractItemModel *model, - const QModelIndex &parent) { - QJsonObject jsonObject; - - // Add data for the current row - for (int col = 0; col < model->columnCount(parent); ++col) { - QVariant data = - model->data(model->index(parent.row(), col, parent.parent())); - QString header = model->headerData(col, Qt::Horizontal).toString(); - jsonObject[header.isEmpty() ? tr("Column %1").arg(col) : header] = - data.toString(); - } - - // Recursively add child rows - QJsonArray children; - for (int row = 0; row < model->rowCount(parent); ++row) { - QModelIndex childIndex = model->index(row, 0, parent); - children.append(extractModelData(model, childIndex)); - } - - if (!children.isEmpty()) - jsonObject["children"] = children; - - return jsonObject; -} - void MainWindow::closeEvent(QCloseEvent *event) { // plugin first checking diff --git a/src/dialog/mainwindow.h b/src/dialog/mainwindow.h index 04c5a64..a900c2e 100644 --- a/src/dialog/mainwindow.h +++ b/src/dialog/mainwindow.h @@ -43,7 +43,6 @@ #include "Qt-Advanced-Docking-System/src/DockManager.h" #include "Qt-Advanced-Docking-System/src/DockWidget.h" #include "WingPlugin/iwingplugin.h" -#include "class/clickcallback.h" #include "class/recentfilemanager.h" #include "class/scriptmanager.h" #include "control/editorview.h" @@ -64,9 +63,6 @@ class MainWindow : public FramelessMainWindow { friend class PluginSystem; - using ClickedCallBack = ClickCallBack; - using DblClickedCallBack = ClickCallBack; - public: explicit MainWindow(SplashDialog *splash); virtual ~MainWindow() override; @@ -125,9 +121,6 @@ private: ads::CDockAreaWidget * buildUpScriptBgOutputDock(ads::CDockManager *dock, ads::DockWidgetArea area, ads::CDockAreaWidget *areaw = nullptr); - ads::CDockAreaWidget * - buildUpVisualDataDock(ads::CDockManager *dock, ads::DockWidgetArea area, - ads::CDockAreaWidget *areaw = nullptr); RibbonTabContent *buildFilePage(RibbonTabContent *tab); RibbonTabContent *buildEditPage(RibbonTabContent *tab); @@ -268,10 +261,6 @@ private: void onOutputBgScriptOutput(const ScriptMachine::MessageInfo &message); -private: - QJsonObject extractModelData(const QAbstractItemModel *model, - const QModelIndex &parent = QModelIndex()); - protected: virtual void closeEvent(QCloseEvent *event) override; @@ -507,20 +496,6 @@ private: QTableViewExt *m_metadatas = nullptr; MetaDataModel *_metadataEmpty = nullptr; - // data visualization widgets - QListView *m_infolist = nullptr; - ClickedCallBack m_infoclickfn; - DblClickedCallBack m_infodblclickfn; - - QTreeView *m_infotree = nullptr; - ClickedCallBack m_infotreeclickfn; - DblClickedCallBack m_infotreedblclickfn; - - QTableView *m_infotable = nullptr; - QTextBrowser *m_infotxt = nullptr; - ClickedCallBack m_infotableclickfn; - DblClickedCallBack m_infotabledblclickfn; - QMap m_toolBtneditors; QAction *m_aDelBookMark = nullptr; diff --git a/src/model/qjsontablemodel.cpp b/src/model/qjsontablemodel.cpp deleted file mode 100644 index d74a0e3..0000000 --- a/src/model/qjsontablemodel.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/*============================================================================== -** Copyright (C) 2024-2027 WingSummer -** -** This program is free software: you can redistribute it and/or modify it under -** the terms of the GNU Affero General Public License as published by the Free -** Software Foundation, version 3. -** -** This program is distributed in the hope that it will be useful, but WITHOUT -** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -** FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -** details. -** -** You should have received a copy of the GNU Affero General Public License -** along with this program. If not, see . -** ============================================================================= -*/ - -#include "qjsontablemodel.h" -#include - -QJsonTableModel::QJsonTableModel(const QJsonTableModel::Header &header, - QObject *parent) - : QAbstractTableModel(parent), m_header(header) {} - -bool QJsonTableModel::setJson(const QJsonDocument &json) { - return setJson(json.array()); -} - -bool QJsonTableModel::setJson(const QJsonArray &array) { - beginResetModel(); - m_json = array; - endResetModel(); - return true; -} - -QVariant QJsonTableModel::headerData(int section, Qt::Orientation orientation, - int role) const { - if (role != Qt::DisplayRole) { - return QVariant(); - } - - switch (orientation) { - case Qt::Horizontal: - return m_header[section]["title"]; - case Qt::Vertical: - // return section + 1; - return QVariant(); - default: - return QVariant(); - } -} - -int QJsonTableModel::rowCount(const QModelIndex &parent) const { - Q_UNUSED(parent); - return m_json.size(); -} - -int QJsonTableModel::columnCount(const QModelIndex &parent) const { - Q_UNUSED(parent); - return m_header.size(); -} - -QJsonObject QJsonTableModel::getJsonObject(const QModelIndex &index) const { - const QJsonValue &value = m_json[index.row()]; - return value.toObject(); -} - -QVariant QJsonTableModel::data(const QModelIndex &index, int role) const { - switch (role) { - case Qt::DisplayRole: { - QJsonObject obj = getJsonObject(index); - const QString &key = m_header[index.column()]["index"]; - if (obj.contains(key)) { - QJsonValue v = obj[key]; - - if (v.isString()) { - return v.toString(); - } else if (v.isDouble()) { - return QString::number(v.toDouble()); - } else { - return QVariant(); - } - } else { - return QVariant(); - } - } - case Qt::ToolTipRole: - return QVariant(); - default: - return QVariant(); - } -} diff --git a/src/model/qjsontablemodel.h b/src/model/qjsontablemodel.h deleted file mode 100644 index ead3e9a..0000000 --- a/src/model/qjsontablemodel.h +++ /dev/null @@ -1,51 +0,0 @@ -/*============================================================================== -** Copyright (C) 2024-2027 WingSummer -** -** This program is free software: you can redistribute it and/or modify it under -** the terms of the GNU Affero General Public License as published by the Free -** Software Foundation, version 3. -** -** This program is distributed in the hope that it will be useful, but WITHOUT -** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -** FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -** details. -** -** You should have received a copy of the GNU Affero General Public License -** along with this program. If not, see . -** ============================================================================= -*/ - -#ifndef QJSONTABLEMODEL_H -#define QJSONTABLEMODEL_H - -#include -#include -#include -#include -#include -#include - -class QJsonTableModel : public QAbstractTableModel { -public: - typedef QHash Heading; - typedef QVector Header; - QJsonTableModel(const Header &header, QObject *parent = 0); - - bool setJson(const QJsonDocument &json); - bool setJson(const QJsonArray &array); - - virtual QJsonObject getJsonObject(const QModelIndex &index) const; - - virtual QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - virtual QVariant data(const QModelIndex &index, - int role = Qt::DisplayRole) const; - -private: - Header m_header; - QJsonArray m_json; -}; - -#endif // QJSONTABLEMODEL_H