Skip to content

Commit

Permalink
Merge pull request #241 from naivisoftware/napkin_inspector_state
Browse files Browse the repository at this point in the history
Napkin Inspector State & General Improvements
  • Loading branch information
cklosters committed Oct 7, 2022
2 parents 647322d + 88d17e4 commit 1a5a12c
Show file tree
Hide file tree
Showing 35 changed files with 928 additions and 460 deletions.
20 changes: 12 additions & 8 deletions modules/napscene/src/instanceproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
// External Includes

namespace nap
{
// Helper macro to register RTTI for instance properties for POD types
#define RTTI_DEFINE_INSTANCE_PROPERTY_VALUE(InstancePropertyValueType) \
RTTI_BEGIN_CLASS(InstancePropertyValueType) \
RTTI_PROPERTY("Value", &InstancePropertyValueType::mValue, nap::rtti::EPropertyMetaData::Required) \
RTTI_END_CLASS

{
namespace rtti
{
namespace instanceproperty
{
inline constexpr const char* value = "Value";
}
class ResolvedPath;
}

Expand Down Expand Up @@ -175,4 +173,10 @@ namespace nap
using IVec3InstancePropertyValue = TypedInstancePropertyValue<glm::ivec3>;
using QuatInstancePropertyValue = TypedInstancePropertyValue<glm::quat>;
using StringInstancePropertyValue = TypedInstancePropertyValue<std::string>;
}
}

// Helper macro to register RTTI for instance properties for POD types
#define RTTI_DEFINE_INSTANCE_PROPERTY_VALUE(InstancePropertyValueType) \
RTTI_BEGIN_CLASS(InstancePropertyValueType) \
RTTI_PROPERTY(nap::rtti::instanceproperty::value, &InstancePropertyValueType::mValue, nap::rtti::EPropertyMetaData::Required) \
RTTI_END_CLASS
4 changes: 4 additions & 0 deletions qt/src/napqt/filterpopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ void FilterPopup::computeSize()
auto rect = tree.visualRectFor(selection);
height += rect.height();
}
else
{
height *= 2;
}

setFixedSize(300, qMin(height, 500));
adjustSize();
Expand Down
7 changes: 2 additions & 5 deletions qt/src/napqt/filtertreeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,11 @@ FilterTreeView::FilterTreeView(QTreeView* treeview)
mLineEditFilter.setClearButtonEnabled(true);
connect(&mLineEditFilter, &QLineEdit::textChanged, this, &FilterTreeView::onFilterChanged);
mLayout.addWidget(&mLineEditFilter);

mTreeView->setModel(&mProxyModel);

mLayout.addWidget(mTreeView);

setContextMenuPolicy(Qt::CustomContextMenu);

connect(this, &QWidget::customContextMenuRequested, this, &FilterTreeView::onCustomContextMenuRequested);

connect(mTreeView, &QTreeView::doubleClicked, this, &FilterTreeView::doubleClicked);
}

Expand All @@ -66,7 +62,7 @@ QStandardItemModel* FilterTreeView::getModel() const
return qobject_cast<QStandardItemModel*>(mProxyModel.sourceModel());
}

void FilterTreeView::selectAndReveal(const QStandardItem* item)
void FilterTreeView::select(const QStandardItem* item, bool expand)
{
if (item == nullptr)
return;
Expand All @@ -84,6 +80,7 @@ void FilterTreeView::selectAndReveal(const QStandardItem* item)
// We are going to select an entire row
auto botRight = getProxyModel().index(idx.row(), getProxyModel().columnCount(idx.parent()) - 1, idx.parent());
getTreeView().selectionModel()->select(QItemSelection(idx, botRight), QItemSelectionModel::ClearAndSelect);
if (expand) { getTreeView().expand(idx); }
getTreeView().scrollTo(idx);
}

Expand Down
5 changes: 3 additions & 2 deletions qt/src/napqt/filtertreeview.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ namespace nap

/**
* Select and item and make sure it's visible on screen by scrolling if needed.
* @param item
* @param item item to select
* @param expand if the item should be expanded
*/
void selectAndReveal(const QStandardItem* item);
void select(const QStandardItem* item, bool expand);

/**
* Expand the given item
Expand Down
Binary file added tools/napkin/resources/icons/array.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/napkin/resources/icons/help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/napkin/resources/icons/info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/napkin/resources/icons/property.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/napkin/resources/icons/url.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion tools/napkin/resources/napkin-resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<file>icons/remove.png</file>
<file>icons/edit.png</file>
<file>icons/change.png</file>
<file>icons/info.png</file>
<file>icons/help.png</file>
<file>icons/url.png</file>
<file>icons/property.png</file>
<file>icons/array.png</file>
</qresource>
</RCC>

12 changes: 12 additions & 0 deletions tools/napkin/src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <QMessageBox>
#include <QHBoxLayout>
#include <QDesktopServices>
#include <rtti/rttiutilities.h>
#include <rtti/jsonwriter.h>
#include <utility/errorstate.h>
Expand Down Expand Up @@ -927,3 +928,14 @@ void napkin::SetAsDefaultServiceConfigAction::perform()
// Set as default in project
ctx.getServiceConfig()->makeProjectDefault();
}


napkin::OpenURLAction::OpenURLAction(const char* text, const QUrl& address) :
Action(text, QRC_ICONS_URL), mAddress(address)
{ }


void napkin::OpenURLAction::perform()
{
QDesktopServices::openUrl(mAddress);
}
14 changes: 14 additions & 0 deletions tools/napkin/src/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <QSet>
#include <QStandardItem>
#include <QString>
#include <QUrl>
#include <QUndoCommand>
#include <entity.h>
#include <nap/logger.h>
Expand Down Expand Up @@ -419,4 +420,17 @@ namespace napkin
void perform() override;
QString mTheme; // The theme to set
};


/**
* Open URL in browser
*/
class OpenURLAction : public Action
{
public:
explicit OpenURLAction(const char* text, const QUrl& address);
private:
void perform() override;
QUrl mAddress;
};
}
2 changes: 2 additions & 0 deletions tools/napkin/src/appcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ void AppContext::connectDocumentSignals(bool enable)
connect(doc, &Document::objectRemoved, this, &AppContext::objectRemoved);
connect(doc, &Document::objectReparenting, this, &AppContext::objectReparenting);
connect(doc, &Document::objectReparented, this, &AppContext::objectReparented);
connect(doc, &Document::objectRenamed, this, &AppContext::objectRenamed);
connect(doc, &Document::propertyValueChanged, this, &AppContext::propertyValueChanged);
connect(doc, &Document::propertyChildInserted, this, &AppContext::propertyChildInserted);
connect(doc, &Document::propertyChildRemoved, this, &AppContext::propertyChildRemoved);
Expand All @@ -348,6 +349,7 @@ void AppContext::connectDocumentSignals(bool enable)
disconnect(doc, &Document::objectRemoved, this, &AppContext::objectRemoved);
disconnect(doc, &Document::objectReparenting, this, &AppContext::objectReparenting);
disconnect(doc, &Document::objectReparented, this, &AppContext::objectReparented);
disconnect(doc, &Document::objectRenamed, this, &AppContext::objectRenamed);
disconnect(doc, &Document::propertyValueChanged, this, &AppContext::propertyValueChanged);
disconnect(doc, &Document::propertyChildInserted, this, &AppContext::propertyChildInserted);
disconnect(doc, &Document::propertyChildRemoved, this, &AppContext::propertyChildRemoved);
Expand Down
9 changes: 9 additions & 0 deletions tools/napkin/src/appcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,15 @@ namespace napkin
*/
void objectReparenting(nap::rtti::Object& object, PropertyPath oldParent, PropertyPath newParent);

/**
* Qt Signal
* Invoked after an object has been renamed
* @param object the object that has been renamed
* @param oldName the old (now invalid) object property name
* @param newName the new (now valid) object property name
*/
void objectRenamed(nap::rtti::Object& object, const std::string& oldName, const std::string& newName);

/**
* Qt Signal
* Invoked just after a property's value has changed
Expand Down
11 changes: 6 additions & 5 deletions tools/napkin/src/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,23 +455,24 @@ void RemoveComponentCommand::undo()

ReplaceEmbeddedPointerCommand::ReplaceEmbeddedPointerCommand(const PropertyPath& path, rttr::type objectType)
: mPath(path), mType(objectType)
{
{ }

}

void ReplaceEmbeddedPointerCommand::redo()
{
// Remove current pointee
auto pointee = mPath.getPointee();
auto doc = mPath.getDocument();
if (pointee) // TODO: Serialize and store for undo
if (pointee)
doc->removeObject(*pointee);

auto obj = doc->addObject(mType, nullptr);
mCreatedObject = {*obj, *doc};
// Create and point to new object
auto obj = doc->addObject(mType, mPath.getObject());
mPath.setPointee(obj);
doc->propertyValueChanged(mPath);
}


void ReplaceEmbeddedPointerCommand::undo()
{
nap::Logger::fatal("Not supported");
Expand Down
2 changes: 0 additions & 2 deletions tools/napkin/src/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,6 @@ namespace napkin
void undo() override;
private:
PropertyPath mPath;
PropertyPath mCreatedObject;
rttr::type mType;
};

};
26 changes: 14 additions & 12 deletions tools/napkin/src/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,25 @@ const std::string& Document::setObjectName(nap::rtti::Object& object, const std:
if (name.empty())
return object.mID;

auto newName = getUniqueName(name, object, false);
if (newName == object.mID)
auto new_name = getUniqueName(name, object, false);
if (new_name == object.mID)
return object.mID;

auto oldName = object.mID;
object.mID = newName;
// Set name and update all pointers (in data model) that point to this object
auto old_name = object.mID;

// Update pointers to this object
// Update all pointers (in data model) to this object
object.mID = new_name;
for (auto propPath : getPointersTo(object, false, false, false))
propPath.setPointee(&object);

// Notify listeners
PropertyPath path(object, Path::fromString(nap::rtti::sIDPropertyName), *this);
assert(path.isValid());
propertyValueChanged(path);
objectRenamed(object, old_name, new_name);

// New name
return object.mID;
}

Expand Down Expand Up @@ -684,13 +688,15 @@ void Document::removeEntityFromScene(nap::Scene& scene, nap::Entity& entity)
}
}


void Document::removeEntityFromScene(nap::Scene& scene, size_t index)
{
removeInstanceProperties(scene, *scene.mEntities[index].mEntity);
scene.mEntities.erase(scene.mEntities.begin() + index);
objectChanged(&scene);
}


int Document::arrayAddValue(const PropertyPath& path)
{
ResolvedPath resolved_path = path.resolve();
Expand All @@ -699,6 +705,7 @@ int Document::arrayAddValue(const PropertyPath& path)
Variant array = resolved_path.getValue();
assert(array.is_array());
VariantArray array_view = array.create_array_view();
assert(array_view.is_dynamic());

const TypeInfo element_type = array_view.get_rank_type(1);
const TypeInfo wrapped_type = element_type.is_wrapper() ? element_type.get_wrapped_type() : element_type;
Expand All @@ -711,21 +718,16 @@ int Document::arrayAddValue(const PropertyPath& path)
// HACK: In the case of a vector<string>, rttr::type::create() gives us a shared_ptr to a string,
// hence, rttr::variant_array_view::insert_value will fail because it expects just a string.
Variant new_value;
if (wrapped_type == RTTI_OF(std::string))
new_value = std::string();
else
new_value = wrapped_type.create();

new_value = wrapped_type == RTTI_OF(std::string) ? std::string() : wrapped_type.create();
assert(new_value.is_valid());
assert(array_view.is_dynamic());

size_t index = array_view.get_size();
bool inserted = array_view.insert_value(index, new_value);
assert(inserted);
resolved_path.setValue(array);

propertyChildInserted(path, index);
propertyValueChanged(path);
propertyChildInserted(path, index);

return index;
}
Expand Down
9 changes: 9 additions & 0 deletions tools/napkin/src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,15 @@ namespace napkin
*/
void objectReparenting(nap::rtti::Object& object, PropertyPath oldParent, PropertyPath newParent);

/**
* Qt Signal
* Invoked after an object has been renamed.
* @param object the object that has been renamed
* @param oldName old (now invalid) object property name
* @param newName new (now valid) object property name
*/
void objectRenamed(nap::rtti::Object& object, const std::string& oldName, const std::string& newName);

/**
* Qt Signal
* Invoked just after a property's value has changed
Expand Down
9 changes: 9 additions & 0 deletions tools/napkin/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ void MainWindow::addMenu()
}
menuBar()->insertMenu(getWindowMenu()->menuAction(), config_menu);
menuBar()->insertMenu(getWindowMenu()->menuAction(), &mThemeMenu);

// Help
auto help_menu = new QMenu("Help", menuBar());
{
auto open_url_action = new OpenURLAction("NAP Documentation", QUrl("https://docs.nap.tech"));
addAction(open_url_action);
help_menu->addAction(open_url_action);
}
menuBar()->insertMenu(getWindowMenu()->menuAction(), help_menu);
}


Expand Down
5 changes: 5 additions & 0 deletions tools/napkin/src/napkin-resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ namespace napkin
inline constexpr const char* QRC_ICONS_REMOVE = ":/icons/remove.png";
inline constexpr const char* QRC_ICONS_EDIT = ":/icons/edit.png";
inline constexpr const char* QRC_ICONS_CHANGE = ":/icons/change.png";
inline constexpr const char* QRC_ICONS_INFO = ":/icons/info.png";
inline constexpr const char* QRC_ICONS_HELP = ":/icons/help.png";
inline constexpr const char* QRC_ICONS_URL = ":/icons/url.png";
inline constexpr const char* QRC_ICONS_PROPERTY = ":/icons/property.png";
inline constexpr const char* QRC_ICONS_ARRAY = ":/icons/array.png";
}
Loading

0 comments on commit 1a5a12c

Please sign in to comment.