Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 50417559 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

UI: Add the PropertyDocumentView to view properties as a document tab

parent c55bdde7
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!6Add document views
......@@ -7,6 +7,7 @@
#include "../Lib/Utils.hh"
#include <QWidget>
#include <QString>
namespace Vivy
{
......@@ -26,6 +27,8 @@ public:
explicit DocumentView(QWidget *parent = nullptr) noexcept;
virtual ~DocumentView() noexcept = default;
virtual QString getDocumentTabName() const noexcept = 0;
virtual QString getDocumentTabToolTip() const noexcept = 0;
virtual Type getType() const noexcept = 0;
};
}
......
#include "PropertyDocumentView.hh"
using namespace Vivy;
PropertyDocumentView::PropertyDocumentView(std::shared_ptr<PropertyModel> doc,
QWidget *parent) noexcept
: DocumentView(parent)
, model(doc)
{
if (!doc)
qCritical() << "Passing a null document to the view constructor";
}
DocumentView::Type
PropertyDocumentView::getType() const noexcept
{
return DocumentView::Type::Property;
}
QString
PropertyDocumentView::getDocumentTabName() const noexcept
{
return model->getName();
}
QString
PropertyDocumentView::getDocumentTabToolTip() const noexcept
{
return model->getName();
}
#ifndef VIVY_PROPERTY_DOCUMENT_VIEW_H
#define VIVY_PROPERTY_DOCUMENT_VIEW_H
#ifndef __cplusplus
#error "This is a C++ header"
#endif
#include "../Lib/Utils.hh"
#include "DocumentView.hh"
#include "PropertyView.hh"
#include <QWidget>
#include <QString>
#include <memory>
namespace Vivy
{
class PropertyDocumentView final : public DocumentView {
Q_OBJECT
VIVY_UNMOVABLE_OBJECT(PropertyDocumentView)
public:
explicit PropertyDocumentView(std::shared_ptr<PropertyModel> doc,
QWidget *parent = nullptr) noexcept;
virtual ~PropertyDocumentView() noexcept = default;
QString getDocumentTabName() const noexcept override;
QString getDocumentTabToolTip() const noexcept override;
Type getType() const noexcept override;
private:
std::shared_ptr<PropertyModel> model;
};
}
#endif // VIVY_PROPERTY_DOCUMENT_VIEW_H
......@@ -259,9 +259,9 @@ Qt::ItemFlags
PropertyModel::flags(const QModelIndex &index) const noexcept
{
int col = index.column();
auto item = static_cast<PropertyItem *>(index.internalPointer());
auto isArray = QJsonValue::Array == item->getType();
auto isObject = QJsonValue::Object == item->getType();
PropertyItem *item = static_cast<PropertyItem *>(index.internalPointer());
bool isArray = QJsonValue::Array == item->getType();
bool isObject = QJsonValue::Object == item->getType();
if ((col == 1) && !(isArray || isObject))
return Qt::ItemIsEditable | QAbstractItemModel::flags(index);
......@@ -282,14 +282,14 @@ PropertyModel::getJson() const noexcept
QJsonValue
PropertyModel::genJson(PropertyItem *item) const noexcept
{
auto type = item->getType();
QJsonValue::Type type = item->getType();
int nchild = item->getChildCount();
if (QJsonValue::Object == type) {
QJsonObject jo;
for (int i = 0; i < nchild; ++i) {
auto ch = item->getChild(i);
auto key = ch->getKey();
PropertyItem *ch = item->getChild(i);
QString key = ch->getKey();
jo.insert(key, genJson(ch));
}
return jo;
......@@ -297,10 +297,8 @@ PropertyModel::genJson(PropertyItem *item) const noexcept
else if (QJsonValue::Array == type) {
QJsonArray arr;
for (int i = 0; i < nchild; ++i) {
auto ch = item->getChild(i);
arr.append(genJson(ch));
}
for (int i = 0; i < nchild; ++i)
arr.append(genJson(item->getChild(i)));
return arr;
}
......@@ -309,3 +307,12 @@ PropertyModel::genJson(PropertyItem *item) const noexcept
return va;
}
}
QString
PropertyModel::getName() const noexcept
{
if (root)
return "Property for " + root->getKey();
else
return "Property view";
}
......@@ -78,6 +78,8 @@ public:
Qt::ItemFlags flags(const QModelIndex &) const noexcept override;
QJsonDocument getJson() const noexcept;
QString getName() const noexcept;
private:
QJsonValue genJson(PropertyItem *) const noexcept;
std::unique_ptr<PropertyItem> root{ nullptr };
......
......@@ -22,9 +22,9 @@ public:
~VivyDocumentView() noexcept;
std::shared_ptr<VivyDocument> getDocument() const noexcept;
QString getDocumentTabName() const noexcept;
QString getDocumentTabToolTip() const noexcept;
QString getDocumentTabName() const noexcept override;
QString getDocumentTabToolTip() const noexcept override;
Type getType() const noexcept override;
private:
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter