diff options
author | David Schulz <david.schulz@qt.io> | 2019-02-11 13:24:39 +0100 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2019-02-12 05:51:42 +0000 |
commit | 643a814ba1c0b1887ffbbd74cbd85df81dc59eba (patch) | |
tree | 5805df0125b1b9932566e76111a18607bd4b90ec /src/libs/utils/jsontreeitem.h | |
parent | ffa043fb9983462ebeb143afb946c109e9369e7f (diff) |
Utils: Add a JsonTreeItem
JsonTreeItem is used to visualize json values in tree views. It
will automatically generate new child items if the value contains an
object or array.
Change-Id: I316ea9f626050c21c05cbfc0628d0a5e20ad5a49
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/libs/utils/jsontreeitem.h')
-rw-r--r-- | src/libs/utils/jsontreeitem.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/libs/utils/jsontreeitem.h b/src/libs/utils/jsontreeitem.h new file mode 100644 index 0000000000..57eea36536 --- /dev/null +++ b/src/libs/utils/jsontreeitem.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include "treemodel.h" + +#include "utils_global.h" + +#include <QJsonValue> +#include <QCoreApplication> + +namespace Utils { + +class QTCREATOR_UTILS_EXPORT JsonTreeItem : public TypedTreeItem<JsonTreeItem> +{ + Q_DECLARE_TR_FUNCTIONS(JsonTreeModelItem) +public: + JsonTreeItem() = default; + JsonTreeItem(const QString &displayName, const QJsonValue &value); + + QVariant data(int column, int role) const override; + bool canFetchMore() const override; + void fetchMore() override; + +private: + bool canFetchObjectChildren() const; + bool canFetchArrayChildren() const; + + QString m_name; + QJsonValue m_value; +}; + +} // namespace Utils |