Licensing: re-import GPLv3 version of QJsonItem
- include full license headers, - copied from - repo: https://github.com/dridk/QJsonmodel - rev: fbd4fb3b1c1311f69cd8ada9bbb7a89fd6fe171e
This commit is contained in:
parent
13807ceabf
commit
e5c0854e66
18
LICENSES/GPLv3+-QJsonModel
Normal file
18
LICENSES/GPLv3+-QJsonModel
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/***********************************************
|
||||||
|
Copyright (C) 2014 Schutz Sacha
|
||||||
|
This file is part of QJsonModel (https://github.com/dridk/QJsonmodel).
|
||||||
|
|
||||||
|
QJsonModel is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
QJsonModel 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with QJsonModel. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
**********************************************/
|
@ -1,27 +1,25 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/***********************************************
|
||||||
*
|
Copyright (C) 2014 Schutz Sacha
|
||||||
* Originally from QJsonModel <https://github.com/dridk/QJsonmodel>
|
This file is part of QJsonModel (https://github.com/dridk/QJsonmodel).
|
||||||
* Copyright 2015, Sacha Schutz <sacha@labsquare.org>
|
|
||||||
*
|
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Calamares 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 General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
QJsonModel is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
QJsonModel 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with QJsonModel. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
**********************************************/
|
||||||
|
|
||||||
#include "qjsonitem.h"
|
#include "qjsonitem.h"
|
||||||
|
|
||||||
QJsonTreeItem::QJsonTreeItem(QJsonTreeItem *parent)
|
QJsonTreeItem::QJsonTreeItem(QJsonTreeItem *parent)
|
||||||
: mType( QJsonValue::Null )
|
|
||||||
{
|
{
|
||||||
|
|
||||||
mParent = parent;
|
mParent = parent;
|
||||||
@ -104,8 +102,7 @@ QJsonTreeItem* QJsonTreeItem::load(const QJsonValue& value, QJsonTreeItem* paren
|
|||||||
{
|
{
|
||||||
|
|
||||||
//Get all QJsonValue childs
|
//Get all QJsonValue childs
|
||||||
const auto keys = value.toObject().keys();
|
foreach (QString key , value.toObject().keys()){
|
||||||
for (const QString &key : keys){
|
|
||||||
QJsonValue v = value.toObject().value(key);
|
QJsonValue v = value.toObject().value(key);
|
||||||
QJsonTreeItem * child = load(v,rootItem);
|
QJsonTreeItem * child = load(v,rootItem);
|
||||||
child->setKey(key);
|
child->setKey(key);
|
||||||
@ -120,8 +117,7 @@ QJsonTreeItem* QJsonTreeItem::load(const QJsonValue& value, QJsonTreeItem* paren
|
|||||||
{
|
{
|
||||||
//Get all QJsonValue childs
|
//Get all QJsonValue childs
|
||||||
int index = 0;
|
int index = 0;
|
||||||
const auto valueArray = value.toArray();
|
foreach (QJsonValue v , value.toArray()){
|
||||||
for (const QJsonValue &v : valueArray) {
|
|
||||||
|
|
||||||
QJsonTreeItem * child = load(v,rootItem);
|
QJsonTreeItem * child = load(v,rootItem);
|
||||||
child->setKey(QString::number(index));
|
child->setKey(QString::number(index));
|
||||||
|
@ -1,22 +1,3 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
||||||
*
|
|
||||||
* Originally from QJsonModel <https://github.com/dridk/QJsonmodel>
|
|
||||||
* Copyright 2015, Sacha Schutz <sacha@labsquare.org>
|
|
||||||
*
|
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Calamares 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 General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef JSONITEM_H
|
#ifndef JSONITEM_H
|
||||||
#define JSONITEM_H
|
#define JSONITEM_H
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
@ -26,8 +7,8 @@
|
|||||||
class QJsonTreeItem
|
class QJsonTreeItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QJsonTreeItem(QJsonTreeItem * parent = nullptr);
|
QJsonTreeItem(QJsonTreeItem * parent = 0);
|
||||||
virtual ~QJsonTreeItem();
|
~QJsonTreeItem();
|
||||||
void appendChild(QJsonTreeItem * item);
|
void appendChild(QJsonTreeItem * item);
|
||||||
QJsonTreeItem *child(int row);
|
QJsonTreeItem *child(int row);
|
||||||
QJsonTreeItem *parent();
|
QJsonTreeItem *parent();
|
||||||
@ -41,7 +22,7 @@ public:
|
|||||||
QJsonValue::Type type() const;
|
QJsonValue::Type type() const;
|
||||||
|
|
||||||
|
|
||||||
static QJsonTreeItem* load(const QJsonValue& value, QJsonTreeItem * parent = nullptr);
|
static QJsonTreeItem* load(const QJsonValue& value, QJsonTreeItem * parent = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/***********************************************
|
||||||
*
|
Copyright (C) 2014 Schutz Sacha
|
||||||
* Originally from QJsonModel <https://github.com/dridk/QJsonmodel>
|
This file is part of QJsonModel (https://github.com/dridk/QJsonmodel).
|
||||||
* Copyright 2015, Sacha Schutz <sacha@labsquare.org>
|
|
||||||
*
|
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Calamares 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 General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
QJsonModel is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
QJsonModel 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with QJsonModel. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
**********************************************/
|
||||||
|
|
||||||
#include "qjsonmodel.h"
|
#include "qjsonmodel.h"
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@ -36,13 +35,6 @@ QJsonModel::QJsonModel(QObject *parent) :
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QJsonModel::~QJsonModel()
|
|
||||||
{
|
|
||||||
delete mRootItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool QJsonModel::load(const QString &fileName)
|
bool QJsonModel::load(const QString &fileName)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
@ -68,7 +60,11 @@ bool QJsonModel::loadJson(const QByteArray &json)
|
|||||||
if (!mDocument.isNull())
|
if (!mDocument.isNull())
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
mRootItem = QJsonTreeItem::load(QJsonValue(mDocument.object()));
|
if (mDocument.isArray()) {
|
||||||
|
mRootItem = QJsonTreeItem::load(QJsonValue(mDocument.array()));
|
||||||
|
} else {
|
||||||
|
mRootItem = QJsonTreeItem::load(QJsonValue(mDocument.object()));
|
||||||
|
}
|
||||||
endResetModel();
|
endResetModel();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,3 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
||||||
*
|
|
||||||
* Originally from QJsonModel <https://github.com/dridk/QJsonmodel>
|
|
||||||
* Copyright 2015, Sacha Schutz <sacha@labsquare.org>
|
|
||||||
*
|
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Calamares 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 General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef QJSONMODEL_H
|
#ifndef QJSONMODEL_H
|
||||||
#define QJSONMODEL_H
|
#define QJSONMODEL_H
|
||||||
|
|
||||||
@ -30,8 +10,7 @@ class QJsonModel : public QAbstractItemModel
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit QJsonModel(QObject *parent = nullptr);
|
explicit QJsonModel(QObject *parent = 0);
|
||||||
virtual ~QJsonModel();
|
|
||||||
bool load(const QString& fileName);
|
bool load(const QString& fileName);
|
||||||
bool load(QIODevice * device);
|
bool load(QIODevice * device);
|
||||||
bool loadJson(const QByteArray& json);
|
bool loadJson(const QByteArray& json);
|
||||||
|
Loading…
Reference in New Issue
Block a user