Working on loading scripts.

This commit is contained in:
Andrzej Kapolka 2014-02-04 14:06:17 -08:00
parent a043278f03
commit fd31cc02ad
6 changed files with 97 additions and 3 deletions

View file

@ -8,6 +8,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cm
set(TARGET_NAME metavoxels)
find_package(Qt5Network REQUIRED)
find_package(Qt5Widgets REQUIRED)
include(${MACRO_DIR}/SetupHifiLibrary.cmake)
@ -16,7 +17,7 @@ setup_hifi_library(${TARGET_NAME})
include(${MACRO_DIR}/AutoMTC.cmake)
auto_mtc(${TARGET_NAME} ${ROOT_DIR})
qt5_use_modules(${TARGET_NAME} Widgets Script)
qt5_use_modules(${TARGET_NAME} Network Script Widgets)
include(${MACRO_DIR}/IncludeGLM.cmake)
include_glm(${TARGET_NAME} ${ROOT_DIR})

View file

@ -11,6 +11,7 @@
#include <QDataStream>
#include <QMetaProperty>
#include <QMetaType>
#include <QUrl>
#include <QtDebug>
#include <RegisteredMetaTypes.h>
@ -23,7 +24,9 @@ REGISTER_SIMPLE_TYPE_STREAMER(int)
REGISTER_SIMPLE_TYPE_STREAMER(float)
REGISTER_SIMPLE_TYPE_STREAMER(QByteArray)
REGISTER_SIMPLE_TYPE_STREAMER(QString)
REGISTER_SIMPLE_TYPE_STREAMER(QUrl)
REGISTER_SIMPLE_TYPE_STREAMER(QVariantList)
REGISTER_SIMPLE_TYPE_STREAMER(QVariantHash)
// some types don't quite work with our macro
static int vec3Streamer = Bitstream::registerTypeStreamer(qMetaTypeId<glm::vec3>(), new SimpleTypeStreamer<glm::vec3>());
@ -235,6 +238,17 @@ Bitstream& Bitstream::operator>>(QString& string) {
return read(string.data(), size * sizeof(QChar) * BITS_IN_BYTE);
}
Bitstream& Bitstream::operator<<(const QUrl& url) {
return *this << url.toString();
}
Bitstream& Bitstream::operator>>(QUrl& url) {
QString string;
*this >> string;
url = string;
return *this;
}
Bitstream& Bitstream::operator<<(const QVariant& value) {
const TypeStreamer* streamer = getTypeStreamers().value(value.userType());
if (streamer) {

View file

@ -21,6 +21,7 @@ class QByteArray;
class QDataStream;
struct QMetaObject;
class QObject;
class QUrl;
class Attribute;
class AttributeValue;
@ -238,6 +239,9 @@ public:
Bitstream& operator<<(const QString& string);
Bitstream& operator>>(QString& string);
Bitstream& operator<<(const QUrl& url);
Bitstream& operator>>(QUrl& url);
Bitstream& operator<<(const QVariant& value);
Bitstream& operator>>(QVariant& value);
@ -247,6 +251,9 @@ public:
template<class T> Bitstream& operator<<(const QList<T>& list);
template<class T> Bitstream& operator>>(QList<T>& list);
template<class K, class V> Bitstream& operator<<(const QHash<K, V>& hash);
template<class K, class V> Bitstream& operator>>(QHash<K, V>& hash);
Bitstream& operator<<(const QObject* object);
Bitstream& operator>>(QObject*& object);
@ -295,6 +302,30 @@ template<class T> inline Bitstream& Bitstream::operator>>(QList<T>& list) {
return *this;
}
template<class K, class V> inline Bitstream& Bitstream::operator<<(const QHash<K, V>& hash) {
*this << hash.size();
for (typename QHash<K, V>::const_iterator it = hash.constBegin(); it != hash.constEnd(); it++) {
*this << it.key();
*this << it.value();
}
return *this;
}
template<class K, class V> inline Bitstream& Bitstream::operator>>(QHash<K, V>& hash) {
int size;
*this >> size;
hash.clear();
hash.reserve(size);
for (int i = 0; i < size; i++) {
K key;
V value;
*this >> key;
*this >> value;
hash.insertMulti(key, value);
}
return *this;
}
Q_DECLARE_METATYPE(const QMetaObject*)
/// Macro for registering streamable meta-objects.

View file

@ -15,6 +15,7 @@
REGISTER_META_OBJECT(MetavoxelGuide)
REGISTER_META_OBJECT(DefaultMetavoxelGuide)
REGISTER_META_OBJECT(ScriptedMetavoxelGuide)
REGISTER_META_OBJECT(ThrobbingMetavoxelGuide)
MetavoxelData::MetavoxelData() : _size(1.0f) {

View file

@ -8,8 +8,10 @@
#include <QByteArray>
#include <QDoubleSpinBox>
#include <QHBoxLayout>
#include <QItemEditorFactory>
#include <QLineEdit>
#include <QPushButton>
#include <QStandardItemEditorCreator>
#include <QVBoxLayout>
#include <QtDebug>
@ -19,6 +21,8 @@
#include "MetavoxelUtil.h"
REGISTER_SIMPLE_TYPE_STREAMER(ParameterizedURL)
class DelegatingItemEditorFactory : public QItemEditorFactory {
public:
@ -112,15 +116,43 @@ bool ParameterizedURL::operator!=(const ParameterizedURL& other) const {
return _url != other._url || _parameters != other._parameters;
}
uint qHash(const ParameterizedURL& url, uint seed) {
// just hash on the URL, for now
return qHash(url.getURL(), seed);
}
Bitstream& operator<<(Bitstream& out, const ParameterizedURL& url) {
out << url.getURL();
out << url.getParameters();
return out;
}
Bitstream& operator>>(Bitstream& in, ParameterizedURL& url) {
QUrl qurl;
in >> qurl;
QVariantHash parameters;
in >> parameters;
url = ParameterizedURL(qurl, parameters);
return in;
}
ParameterizedURLEditor::ParameterizedURLEditor(QWidget* parent) :
QWidget(parent) {
QVBoxLayout* layout = new QVBoxLayout();
layout->setContentsMargins(QMargins());
setLayout(layout);
layout->addWidget(_line = new QLineEdit());
connect(_line, SIGNAL(textChanged(const QString&)), SLOT(updateURL()));
}
void ParameterizedURLEditor::setURL(const ParameterizedURL& url) {
_url = url;
_line->setText(url.getURL().toString());
}
void ParameterizedURLEditor::updateURL() {
_url = ParameterizedURL(_line->text());
emit urlChanged(_url);
}

View file

@ -45,6 +45,8 @@ public:
ParameterizedURL(const QUrl& url = QUrl(), const QVariantHash& parameters = QVariantHash());
bool isValid() const { return _url.isValid(); }
void setURL(const QUrl& url) { _url = url; }
const QUrl& getURL() const { return _url; }
@ -60,21 +62,34 @@ private:
QVariantHash _parameters;
};
uint qHash(const ParameterizedURL& url, uint seed = 0);
Bitstream& operator<<(Bitstream& out, const ParameterizedURL& url);
Bitstream& operator>>(Bitstream& in, ParameterizedURL& url);
Q_DECLARE_METATYPE(ParameterizedURL)
/// Allows editing parameterized URLs.
class ParameterizedURLEditor : public QWidget {
Q_OBJECT
Q_PROPERTY(ParameterizedURL url MEMBER _url WRITE setURL USER true)
Q_PROPERTY(ParameterizedURL url MEMBER _url WRITE setURL NOTIFY urlChanged USER true)
public:
ParameterizedURLEditor(QWidget* parent = NULL);
signals:
void urlChanged(const ParameterizedURL& url);
public slots:
void setURL(const ParameterizedURL& url);
private slots:
void updateURL();
private:
ParameterizedURL _url;