diff --git a/data/pics/CMakeLists.txt b/data/pics/CMakeLists.txt index 3090d3937..c81e74567 100644 --- a/data/pics/CMakeLists.txt +++ b/data/pics/CMakeLists.txt @@ -1,52 +1,54 @@ ecm_install_icons( ICONS sc-apps-labplot-1x-zoom.svg sc-apps-labplot-2x-zoom.svg sc-apps-labplot-3x-zoom.svg sc-apps-labplot-4x-zoom.svg sc-apps-labplot-5x-zoom.svg sc-apps-labplot-auto-scale-all.svg sc-apps-labplot-auto-scale-x.svg sc-apps-labplot-auto-scale-y.svg sc-apps-labplot-axis-horizontal.svg sc-apps-labplot-axis-vertical.svg sc-apps-labplot-cursor-arrow.svg sc-apps-labplot-editbreaklayout.svg sc-apps-labplot-editgrid.svg sc-apps-labplot-edithlayout.svg sc-apps-labplot-editvlayout.svg sc-apps-labplot-format-text-symbol.svg +sc-apps-labplot-json-array.svg +sc-apps-labplot-json-object.svg sc-apps-labplot-matrix-new.svg sc-apps-labplot-matrix.svg sc-apps-labplot-plot-axis-points.svg sc-apps-labplot-shift-down-y.svg sc-apps-labplot-shift-left-x.svg sc-apps-labplot-shift-right-x.svg sc-apps-labplot-shift-up-y.svg sc-apps-labplot-spreadsheet-new.svg sc-apps-labplot-spreadsheet.svg sc-apps-labplot-TeX-logo.svg sc-apps-labplot-transform-move.svg sc-apps-labplot-workbook-new.svg sc-apps-labplot-workbook.svg sc-apps-labplot-worksheet-new.svg sc-apps-labplot-worksheet.svg sc-apps-labplot-xy-curve-points.svg sc-apps-labplot-xy-curve-segments.svg sc-apps-labplot-xy-curve.svg sc-apps-labplot-xy-equation-curve.svg sc-apps-labplot-xy-fit-curve.svg sc-apps-labplot-xy-plot-four-axes.svg sc-apps-labplot-xy-plot-two-axes-centered-origin.svg sc-apps-labplot-xy-plot-two-axes-centered.svg sc-apps-labplot-xy-plot-two-axes.svg sc-apps-labplot-zoom-in-x.svg sc-apps-labplot-zoom-in-y.svg sc-apps-labplot-zoom-out-x.svg sc-apps-labplot-zoom-out-y.svg sc-apps-labplot-zoom-select.svg sc-apps-labplot-zoom-select-x.svg sc-apps-labplot-zoom-select-y.svg sc-apps-labplot-zoom.svg DESTINATION ${KDE_INSTALL_ICONDIR}/ THEME hicolor) diff --git a/data/pics/sc-apps-labplot-json-array.svg b/data/pics/sc-apps-labplot-json-array.svg new file mode 100644 index 000000000..1cd22fc56 --- /dev/null +++ b/data/pics/sc-apps-labplot-json-array.svg @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/data/pics/sc-apps-labplot-json-object.svg b/data/pics/sc-apps-labplot-json-object.svg new file mode 100644 index 000000000..8d382a9c8 --- /dev/null +++ b/data/pics/sc-apps-labplot-json-object.svg @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/src/backend/datasources/filters/QJsonModel.cpp b/src/backend/datasources/filters/QJsonModel.cpp index 994ac6ec4..2e98f570f 100644 --- a/src/backend/datasources/filters/QJsonModel.cpp +++ b/src/backend/datasources/filters/QJsonModel.cpp @@ -1,398 +1,398 @@ /* * The MIT License (MIT) * * Copyright (c) 2011 SCHUTZ Sacha * * 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 "backend/lib/macros.h" #include "QJsonModel.h" #include #include #include 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 QString &value) { mValue = value; } void QJsonTreeItem::setType(const QJsonValue::Type &type) { mType = type; } QString QJsonTreeItem::key() const { return mKey; } QString QJsonTreeItem::value() const { return mValue; } QJsonValue::Type QJsonTreeItem::type() const { return mType; } QJsonTreeItem* QJsonTreeItem::load(const QJsonValue& value, QJsonTreeItem* parent) { QJsonTreeItem * rootItem = new QJsonTreeItem(parent); rootItem->setKey("root"); if ( value.isObject()) { //Get all QJsonValue childs for (QString key : value.toObject().keys()){ QJsonValue v = value.toObject().value(key); QJsonTreeItem * child = load(v,rootItem); child->setKey(key); child->setType(v.type()); rootItem->appendChild(child); } } else if ( value.isArray()) { //Get all QJsonValue childs int index = 0; for (QJsonValue v : value.toArray()){ QJsonTreeItem * child = load(v,rootItem); child->setKey(QString::number(index)); child->setType(v.type()); rootItem->appendChild(child); ++index; } } else { rootItem->setValue(value.toVariant().toString()); rootItem->setType(value.type()); } return rootItem; } //========================================================================= QJsonModel::QJsonModel(QObject *parent) : QAbstractItemModel(parent) { mHeadItem = new QJsonTreeItem; mRootItem = new QJsonTreeItem(mHeadItem); mHeadItem->appendChild(mRootItem); mHeaders.append("key"); mHeaders.append("value"); } QJsonModel::~QJsonModel() { //delete mRootItem; delete mHeadItem; } void QJsonModel::clear() { beginResetModel(); delete mHeadItem; mHeadItem = new QJsonTreeItem; mRootItem = new QJsonTreeItem(mHeadItem); mHeadItem->appendChild(mRootItem); endResetModel(); } 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) { auto const& jdoc = QJsonDocument::fromJson(json); return loadJson(jdoc); } bool QJsonModel::loadJson(const QJsonDocument &jdoc) { if (!jdoc.isNull()) { beginResetModel(); delete mHeadItem; mHeadItem = new QJsonTreeItem; if (jdoc.isArray()) { mRootItem = QJsonTreeItem::load(QJsonValue(jdoc.array()), mHeadItem); mRootItem->setType(QJsonValue::Array); } else { mRootItem = QJsonTreeItem::load(QJsonValue(jdoc.object()), mHeadItem); mRootItem->setType(QJsonValue::Object); } mHeadItem->appendChild(mRootItem); endResetModel(); return true; } qDebug()<(index.internalPointer()); if (role == Qt::DisplayRole) { if (index.column() == 0) return QString("%1").arg(item->key()); if (index.column() == 1) return QString("%1").arg(item->value()); } else if (Qt::EditRole == role) { if (index.column() == 1) { return QString("%1").arg(item->value()); } } else if (role == Qt::DecorationRole) { //TODO: add icons for array and object if (item->type() == QJsonValue::Array) - return QIcon(); + return QIcon::fromTheme("labplot-json-array"); else if (item->type() == QJsonValue::Object) - return QIcon(); + return QIcon::fromTheme("labplot-json-object"); else return QIcon(); } return QVariant(); } 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.toString()); 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 QVariant(); if (orientation == Qt::Horizontal) { return mHeaders.value(section); } else return QVariant(); } QModelIndex QJsonModel::index(int row, int column, const QModelIndex &parent) const { if (!hasIndex(row, column, parent)) return QModelIndex(); QJsonTreeItem *parentItem; if (!parent.isValid()) parentItem = mHeadItem; else parentItem = static_cast(parent.internalPointer()); QJsonTreeItem *childItem = parentItem->child(row); if (childItem) return createIndex(row, column, childItem); else return QModelIndex(); } QModelIndex QJsonModel::parent(const QModelIndex &index) const { if (!index.isValid()) return QModelIndex(); QJsonTreeItem *childItem = static_cast(index.internalPointer()); QJsonTreeItem *parentItem = childItem->parent(); if (parentItem == mHeadItem) 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 = mHeadItem; 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(); if (col == 1) { return Qt::ItemIsEditable | QAbstractItemModel::flags(index); } else { return QAbstractItemModel::flags(index); } } QJsonDocument QJsonModel::json() const { auto v = genJson(mRootItem); QJsonDocument doc; if (v.isObject()) { doc = QJsonDocument(v.toObject()); } else { doc = QJsonDocument(v.toArray()); } return doc; } 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(item->value()); return va; } } QJsonDocument QJsonModel::genJsonByIndex(const QModelIndex &index) const { if (!index.isValid()) return QJsonDocument(); QJsonTreeItem *item = static_cast(index.internalPointer()); return QJsonDocument::fromVariant(genJson(item).toVariant()); } diff --git a/src/kdefrontend/ui/datasources/importfilewidget.ui b/src/kdefrontend/ui/datasources/importfilewidget.ui index 9bfac3d50..ecf68bf06 100644 --- a/src/kdefrontend/ui/datasources/importfilewidget.ui +++ b/src/kdefrontend/ui/datasources/importfilewidget.ui @@ -1,757 +1,763 @@ ImportFileWidget 0 0 679 - 847 + 1045 0 0 0 0 0 0 0 0 Data source File or named pipe Network TCP socket Network UDP socket Local socket Serial port Source false Save the current filter settings false 0 0 false 0 0 Manage filters Host false Type 0 0 Select the file to import Name Port Specify the name of the file to import. true Filter Qt::Vertical QSizePolicy::Fixed 20 10 false 0 0 Show file info Qt::Vertical QSizePolicy::Fixed 20 13 Port Baud rate QAbstractItemView::NoEditTriggers false + + + 32 + 0 + + Field false 0 0 Format Options 0 0 0 0 0 0 0 Data format 0 0 0 0 0 0 0 0 Preview 0 0 Number of rows to preview: 1 10000 100 Qt::Horizontal 23 20 Refresh true QTextEdit::NoWrap true 0 0 Data portion to read Start row: Specify the end row to import; -1 stands for the last row -1 2147483647 -1 Start column: Specify the start column for import 1 2147483647 Qt::Horizontal QSizePolicy::Fixed 40 20 Specify the start row for import 1 2147483647 1 Qt::Horizontal 108 20 Qt::Horizontal QSizePolicy::Fixed 40 20 End column: Specify the end column to import; -1 stands for the last column -1 2147483647 -1 Qt::Horizontal 108 20 End row: Qt::Vertical 20 10 Update Options 0 0 Periodically On new data If this option is checked, only the link to the file is stored in the project file but not it's content. Link the file true Read Keep last N values Update Sample rate 1 10000 5 Continuously fixed From end Till the end Update interval 0 0 5 60000 1000 ms KComboBox QComboBox
kcombobox.h