feat: properties pane
This commit is contained in:
parent
ce1e4d4f39
commit
9968266839
|
@ -30,6 +30,8 @@ find_package(ReactPhysics3D REQUIRED)
|
||||||
|
|
||||||
file(MAKE_DIRECTORY bin)
|
file(MAKE_DIRECTORY bin)
|
||||||
|
|
||||||
|
include_directories("include")
|
||||||
|
|
||||||
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.h")
|
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.h")
|
||||||
add_library(openblocks ${SOURCES})
|
add_library(openblocks ${SOURCES})
|
||||||
set_target_properties(openblocks PROPERTIES OUTPUT_NAME "openblocks")
|
set_target_properties(openblocks PROPERTIES OUTPUT_NAME "openblocks")
|
||||||
|
|
|
@ -29,6 +29,10 @@ set(PROJECT_SOURCES
|
||||||
panes/explorerview.cpp
|
panes/explorerview.cpp
|
||||||
panes/explorermodel.h
|
panes/explorermodel.h
|
||||||
panes/explorermodel.cpp
|
panes/explorermodel.cpp
|
||||||
|
panes/propertiesview.h
|
||||||
|
panes/propertiesview.cpp
|
||||||
|
panes/propertiesmodel.h
|
||||||
|
panes/propertiesmodel.cpp
|
||||||
${TS_FILES}
|
${TS_FILES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,12 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
#include <QAbstractItemView>
|
#include <QAbstractItemView>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "physics/simulation.h"
|
#include "physics/simulation.h"
|
||||||
#include "objects/part.h"
|
#include "objects/part.h"
|
||||||
|
#include "qitemselectionmodel.h"
|
||||||
#include "qobject.h"
|
#include "qobject.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
|
@ -24,6 +26,15 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
timer.start(33, this);
|
timer.start(33, this);
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
|
|
||||||
|
connect(ui->explorerView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [&](const QItemSelection &selected, const QItemSelection &deselected) {
|
||||||
|
if (selected.count() == 0) return;
|
||||||
|
|
||||||
|
std::optional<InstanceRef> inst = selected.count() == 0 ? std::nullopt
|
||||||
|
: std::make_optional(((Instance*)selected.indexes()[0].internalPointer())->shared_from_this());
|
||||||
|
|
||||||
|
ui->propertiesView->setSelected(inst);
|
||||||
|
});
|
||||||
|
|
||||||
// ui->explorerView->Init(ui);
|
// ui->explorerView->Init(ui);
|
||||||
|
|
||||||
simulationInit();
|
simulationInit();
|
||||||
|
|
|
@ -66,13 +66,28 @@
|
||||||
<number>2</number>
|
<number>2</number>
|
||||||
</attribute>
|
</attribute>
|
||||||
<widget class="QWidget" name="dockWidgetContents">
|
<widget class="QWidget" name="dockWidgetContents">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
<widget class="ExplorerView" name="explorerView"/>
|
<widget class="ExplorerView" name="explorerView"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QDockWidget" name="propertiesWidget">
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Properties</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="dockWidgetArea">
|
||||||
|
<number>2</number>
|
||||||
|
</attribute>
|
||||||
|
<widget class="QWidget" name="dockWidgetContents_2">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="PropertiesView" name="propertiesView"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
@ -85,6 +100,11 @@
|
||||||
<extends>QTreeView</extends>
|
<extends>QTreeView</extends>
|
||||||
<header>panes/explorerview.h</header>
|
<header>panes/explorerview.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>PropertiesView</class>
|
||||||
|
<extends>QTreeView</extends>
|
||||||
|
<header>panes/propertiesview.h</header>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
|
@ -112,6 +112,7 @@ QVariant ExplorerModel::data(const QModelIndex &index, int role) const {
|
||||||
Instance *item = static_cast<Instance*>(index.internalPointer());
|
Instance *item = static_cast<Instance*>(index.internalPointer());
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
|
case Qt::EditRole:
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return QString::fromStdString(item->name);
|
return QString::fromStdString(item->name);
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
|
|
76
editor/panes/propertiesmodel.cpp
Normal file
76
editor/panes/propertiesmodel.cpp
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
#include "propertiesmodel.h"
|
||||||
|
#include "qnamespace.h"
|
||||||
|
|
||||||
|
PropertiesModel::PropertiesModel(InstanceRef selectedItem, QWidget *parent)
|
||||||
|
: QAbstractItemModel(parent)
|
||||||
|
, selectedItem(selectedItem) {
|
||||||
|
this->propertiesList = selectedItem->GetProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertiesModel::~PropertiesModel() = default;
|
||||||
|
|
||||||
|
|
||||||
|
QVariant PropertiesModel::data(const QModelIndex &index, int role) const {
|
||||||
|
if (!index.isValid())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
std::string propertyName = propertiesList[index.row()];
|
||||||
|
|
||||||
|
switch (role) {
|
||||||
|
case Qt::EditRole:
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
if (index.column() == 0)
|
||||||
|
return QString::fromStdString(propertyName);
|
||||||
|
else if (index.column() == 1)
|
||||||
|
return QString::fromStdString(selectedItem->GetPropertyValue(propertyName).value());
|
||||||
|
// case Qt::DecorationRole:
|
||||||
|
// return iconOf(item->GetClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PropertiesModel::setData(const QModelIndex &index, const QVariant &value, int role) {
|
||||||
|
if (index.column() != 1 && role != Qt::EditRole) return false;
|
||||||
|
|
||||||
|
selectedItem->SetPropertyValue(propertiesList[index.row()], value.toString().toStdString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags PropertiesModel::flags(const QModelIndex &index) const {
|
||||||
|
if (!index.isValid())
|
||||||
|
return Qt::NoItemFlags;
|
||||||
|
|
||||||
|
if (index.column() == 0)
|
||||||
|
return Qt::ItemIsEnabled;
|
||||||
|
|
||||||
|
if (index.column() == 1)
|
||||||
|
return Qt::ItemIsEnabled | Qt::ItemIsEditable;
|
||||||
|
|
||||||
|
return Qt::NoItemFlags;
|
||||||
|
};
|
||||||
|
|
||||||
|
QVariant PropertiesModel::headerData(int section, Qt::Orientation orientation,
|
||||||
|
int role) const {
|
||||||
|
return QString("");
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex PropertiesModel::index(int row, int column,
|
||||||
|
const QModelIndex &parent) const {
|
||||||
|
if (!hasIndex(row, column, parent))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
return createIndex(row, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex PropertiesModel::parent(const QModelIndex &index) const {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
int PropertiesModel::rowCount(const QModelIndex &parent) const {
|
||||||
|
return !parent.isValid() ? selectedItem->GetProperties().size() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PropertiesModel::columnCount(const QModelIndex &parent) const {
|
||||||
|
return 2;
|
||||||
|
}
|
36
editor/panes/propertiesmodel.h
Normal file
36
editor/panes/propertiesmodel.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "objects/base/instance.h"
|
||||||
|
#include "objects/part.h"
|
||||||
|
#include "qabstractitemmodel.h"
|
||||||
|
#include "qevent.h"
|
||||||
|
#include "qmenu.h"
|
||||||
|
#include "qnamespace.h"
|
||||||
|
#include "qtreeview.h"
|
||||||
|
#include <QOpenGLWidget>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class PropertiesModel : public QAbstractItemModel {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
Q_DISABLE_COPY_MOVE(PropertiesModel)
|
||||||
|
|
||||||
|
explicit PropertiesModel(InstanceRef selectedItem, QWidget *parent = nullptr);
|
||||||
|
~PropertiesModel() override;
|
||||||
|
|
||||||
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||||
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation,
|
||||||
|
int role = Qt::DisplayRole) const override;
|
||||||
|
QModelIndex index(int row, int column,
|
||||||
|
const QModelIndex &parent = {}) const override;
|
||||||
|
QModelIndex parent(const QModelIndex &index) const override;
|
||||||
|
int rowCount(const QModelIndex &parent = {}) const override;
|
||||||
|
int columnCount(const QModelIndex &parent = {}) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
InstanceRef selectedItem;
|
||||||
|
std::vector<std::string> propertiesList;
|
||||||
|
};
|
20
editor/panes/propertiesview.cpp
Normal file
20
editor/panes/propertiesview.cpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include "propertiesview.h"
|
||||||
|
#include "propertiesmodel.h"
|
||||||
|
#include "qaction.h"
|
||||||
|
|
||||||
|
PropertiesView::PropertiesView(QWidget* parent):
|
||||||
|
QTreeView(parent) {
|
||||||
|
this->setStyleSheet(QString("QTreeView::branch { border: none; }"));
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertiesView::~PropertiesView() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void PropertiesView::setSelected(std::optional<InstanceRef> instance) {
|
||||||
|
if (instance.has_value()) {
|
||||||
|
this->setModel(new PropertiesModel(instance.value()));
|
||||||
|
} else {
|
||||||
|
if (this->model()) delete this->model();
|
||||||
|
this->setModel(nullptr);
|
||||||
|
}
|
||||||
|
}
|
22
editor/panes/propertiesview.h
Normal file
22
editor/panes/propertiesview.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "objects/base/instance.h"
|
||||||
|
#include "objects/part.h"
|
||||||
|
#include "qevent.h"
|
||||||
|
#include "qmenu.h"
|
||||||
|
#include "qnamespace.h"
|
||||||
|
#include "qtreeview.h"
|
||||||
|
#include <QOpenGLWidget>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <memory>
|
||||||
|
#include "explorermodel.h"
|
||||||
|
|
||||||
|
class Ui_MainWindow;
|
||||||
|
|
||||||
|
class PropertiesView : public QTreeView {
|
||||||
|
public:
|
||||||
|
PropertiesView(QWidget* parent = nullptr);
|
||||||
|
~PropertiesView() override;
|
||||||
|
|
||||||
|
void setSelected(std::optional<InstanceRef> instance);
|
||||||
|
};
|
|
@ -1,6 +1,5 @@
|
||||||
#include "instance.h"
|
#include "instance.h"
|
||||||
#include "../../common.h"
|
#include "../../common.h"
|
||||||
#include "objects/base/member.h"
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <../include/expected.hpp>
|
#include <../include/expected.hpp>
|
||||||
|
|
||||||
#include "objects/base/member.h"
|
#include "member.h"
|
||||||
|
|
||||||
class Instance;
|
class Instance;
|
||||||
typedef std::shared_ptr<Instance>(*InstanceConstructor)();
|
typedef std::shared_ptr<Instance>(*InstanceConstructor)();
|
||||||
|
|
Loading…
Reference in a new issue