--HG--
branch : develop
This commit is contained in:
dismine 2014-09-10 20:57:08 +03:00
parent 9a735b29bf
commit 1d4f0a6a55
86 changed files with 1087 additions and 557 deletions

View File

@ -40,8 +40,8 @@ VFormula::VFormula()
//---------------------------------------------------------------------------------------------------------------------
VFormula::VFormula(const QString &formula, const VContainer *container)
:formula(qApp->FormulaToUser(formula)), value(QString(tr("Error"))), checkZero(true), data(container), toolId(NULL_ID),
postfix(QStringLiteral("")), _error(true), dValue(0)
:formula(qApp->FormulaToUser(formula)), value(QString(tr("Error"))), checkZero(true), data(container),
toolId(NULL_ID), postfix(QStringLiteral("")), _error(true), dValue(0)
{
this->formula.replace("\n", " ");// Replace line return with spaces for calc if exist
Eval();

View File

@ -48,7 +48,8 @@
* @param parent parent widget
*/
DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *parent)
:DialogTool(data, NULL_ID, parent), ui(new Ui::DialogIncrements), data(data), doc(doc), row(0), column(0), m(nullptr)
:DialogTool(data, NULL_ID, parent), ui(new Ui::DialogIncrements), data(data), doc(doc), row(0), column(0),
m(nullptr)
{
ui->setupUi(this);

View File

@ -393,4 +393,3 @@ void VToolBisector::setFirstPointId(const quint32 &value)
SaveOption(obj);
}
}

View File

@ -338,4 +338,3 @@ void VToolHeight::setP1LineId(const quint32 &value)
SaveOption(obj);
}
}

View File

@ -397,4 +397,3 @@ void VToolLineIntersect::setP1Line1(const quint32 &value)
SaveOption(obj);
}
}

View File

@ -353,4 +353,3 @@ void VToolNormal::ShowVisualization(bool show)
vis = nullptr;
}
}

View File

@ -397,4 +397,3 @@ void VToolShoulderPoint::setP2Line(const quint32 &value)
SaveOption(obj);
}
}

View File

@ -112,8 +112,3 @@ void VisToolSpline::setKCurve(const qreal &value)
{
kCurve = value;
}

View File

@ -63,18 +63,26 @@ VFormulaProperty::VFormulaProperty(const QString &name) :
QVariant VFormulaProperty::data (int column, int role) const
{
if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
{
return getValue();
}
else
{
return VProperty::data(column, role);
}
}
Qt::ItemFlags VFormulaProperty::flags(int column) const
{
if (column == DPC_Name || column == DPC_Data)
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
else
{
return Qt::NoItemFlags;
}
}
//---------------------------------------------------------------------------------------------------------------------
//! Returns an editor widget, or NULL if it doesn't supply one
@ -132,12 +140,15 @@ QString VFormulaProperty::type() const
//---------------------------------------------------------------------------------------------------------------------
VProperty *VFormulaProperty::clone(bool include_children, VProperty *container) const
{
if(!container) {
if (!container)
{
container = new VFormulaProperty(getName());
if(!include_children) {
if (!include_children)
{
QList<VProperty*> tmpChildren = container->getChildren();
foreach(VProperty* tmpChild, tmpChildren) {
foreach (VProperty* tmpChild, tmpChildren)
{
container->removeChild(tmpChild);
delete tmpChild;
}
@ -174,7 +185,9 @@ VFormula VFormulaProperty::getFormula() const
void VFormulaProperty::setFormula(const VFormula &formula)
{
if (d_ptr->Children.count() < 2)
{
return;
}
QVariant value;
value.setValue(formula);

View File

@ -33,9 +33,7 @@
class VFormula;
using namespace VPE;
class VFormulaProperty : public VProperty
class VFormulaProperty : public VPE::VProperty
{
public:
@ -50,8 +48,10 @@ public:
//! Returns an editor widget, or NULL if it doesn't supply one
//! \param parent The widget to which the editor will be added as a child
//! \options Render options
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate);
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
//! slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate);
//! Sets the property's data to the editor (returns false, if the standard delegate should do that)
virtual bool setEditorData(QWidget* editor);
@ -64,7 +64,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const;

View File

@ -267,4 +267,3 @@ void VMainGraphicsView::setShowToolOptions(bool value)
{
showToolOptions = value;
}

View File

@ -41,8 +41,6 @@ class QGraphicsItem;
class QScrollArea;
class VFormula;
using namespace VPE;
class VToolOptionsPropertyBrowser : public QObject
{
Q_OBJECT
@ -50,19 +48,19 @@ public:
VToolOptionsPropertyBrowser(QDockWidget *parent);
public slots:
void itemClicked(QGraphicsItem *item);
void userChangedData(VProperty* property);
void userChangedData(VPE::VProperty* property);
void UpdateOptions();
private:
Q_DISABLE_COPY(VToolOptionsPropertyBrowser)
VPropertyModel* PropertyModel;
VPropertyFormView* formView;
VPE::VPropertyModel* PropertyModel;
VPE::VPropertyFormView* formView;
QGraphicsItem *currentItem;
QMap<VProperty *, QString> propertyToId;
QMap<QString, VProperty *> idToProperty;
QMap<VPE::VProperty *, QString> propertyToId;
QMap<QString, VPE::VProperty *> idToProperty;
void AddProperty(VProperty *property, const QString &id);
void AddProperty(VPE::VProperty *property, const QString &id);
void ShowItemOptions(QGraphicsItem *item);
template<class Tool>
@ -78,24 +76,24 @@ private:
QStringList PropertiesList() const;
void ChangeDataToolSinglePoint(VProperty *property);
void ChangeDataToolEndLine(VProperty *property);
void ChangeDataToolAlongLine(VProperty *property);
void ChangeDataToolArc(VProperty *property);
void ChangeDataToolBisector(VProperty *property);
void ChangeDataToolCutArc(VProperty *property);
void ChangeDataToolCutSpline(VProperty *property);
void ChangeDataToolCutSplinePath(VProperty *property);
void ChangeDataToolHeight(VProperty *property);
void ChangeDataToolLine(VProperty *property);
void ChangeDataToolLineIntersect(VProperty *property);
void ChangeDataToolNormal(VProperty *property);
void ChangeDataToolPointOfContact(VProperty *property);
void ChangeDataToolPointOfIntersection(VProperty *property);
void ChangeDataToolShoulderPoint(VProperty *property);
void ChangeDataToolSpline(VProperty *property);
void ChangeDataToolSplinePath(VProperty *property);
void ChangeDataToolTriangle(VProperty *property);
void ChangeDataToolSinglePoint(VPE::VProperty *property);
void ChangeDataToolEndLine(VPE::VProperty *property);
void ChangeDataToolAlongLine(VPE::VProperty *property);
void ChangeDataToolArc(VPE::VProperty *property);
void ChangeDataToolBisector(VPE::VProperty *property);
void ChangeDataToolCutArc(VPE::VProperty *property);
void ChangeDataToolCutSpline(VPE::VProperty *property);
void ChangeDataToolCutSplinePath(VPE::VProperty *property);
void ChangeDataToolHeight(VPE::VProperty *property);
void ChangeDataToolLine(VPE::VProperty *property);
void ChangeDataToolLineIntersect(VPE::VProperty *property);
void ChangeDataToolNormal(VPE::VProperty *property);
void ChangeDataToolPointOfContact(VPE::VProperty *property);
void ChangeDataToolPointOfIntersection(VPE::VProperty *property);
void ChangeDataToolShoulderPoint(VPE::VProperty *property);
void ChangeDataToolSpline(VPE::VProperty *property);
void ChangeDataToolSplinePath(VPE::VProperty *property);
void ChangeDataToolTriangle(VPE::VProperty *property);
void ShowOptionsToolSinglePoint(QGraphicsItem *item);
void ShowOptionsToolEndLine(QGraphicsItem *item);

View File

@ -55,7 +55,9 @@ QVariant QVector3DProperty::data (int column, int role) const
Qt::ItemFlags QVector3DProperty::flags(int column) const
{
if (column == DPC_Name || column == DPC_Data)
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
else
return Qt::NoItemFlags;
}
@ -67,7 +69,9 @@ Vector3D QVector3DProperty::getVector() const
Vector3D tmpVect;
if (d_ptr->Children.count() < 3)
{
return tmpVect;
}
tmpVect.X = d_ptr->Children.at(0)->getValue().toFloat();
tmpVect.Y = d_ptr->Children.at(1)->getValue().toFloat();
@ -85,7 +89,9 @@ void QVector3DProperty::setVector(const Vector3D &vect)
void QVector3DProperty::setVector(float x, float y, float z)
{
if (d_ptr->Children.count() < 3)
{
return;
}
QVariant tmpX(x); tmpX.convert(QVariant::Double);
QVariant tmpY(y); tmpY.convert(QVariant::Double);
@ -102,12 +108,15 @@ QString QVector3DProperty::type() const
VProperty* QVector3DProperty::clone(bool include_children, VProperty* container) const
{
if(!container) {
if (!container)
{
container = new QVector3DProperty(getName());
if(!include_children) {
if (!include_children)
{
QList<VProperty*> tmpChildren = container->getChildren();
foreach(VProperty* tmpChild, tmpChildren) {
foreach (VProperty* tmpChild, tmpChildren)
{
container->removeChild(tmpChild);
delete tmpChild;
}
@ -120,7 +129,8 @@ VProperty* QVector3DProperty::clone(bool include_children, VProperty* container)
void QVector3DProperty::setValue(const QVariant &value)
{
QStringList tmpStrings = value.toString().split(",");
if(tmpStrings.count() == 3) {
if (tmpStrings.count() == 3)
{
setVector(tmpStrings[0].toDouble(), tmpStrings[1].toDouble(), tmpStrings[2].toDouble());
}

View File

@ -25,7 +25,8 @@
#include "vproperty.h"
namespace VPE{
namespace VPE
{
struct VPROPERTYEXPLORERSHARED_EXPORT Vector3D
{
@ -80,7 +81,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const;

View File

@ -41,8 +41,14 @@ VBoolProperty::VBoolProperty(const QString& name) :
d_ptr->VariantValue.convert(QVariant::Bool);
// I'm not sure, how Qt handles the translations...
if(TrueText.isNull()) TrueText = QObject::tr("True");
if(TrueText.isNull()) FalseText = QObject::tr("False");
if (TrueText.isNull())
{
TrueText = QObject::tr("True");
}
if (TrueText.isNull())
{
FalseText = QObject::tr("False");
}
}
@ -50,9 +56,13 @@ VBoolProperty::VBoolProperty(const QString& name) :
QVariant VBoolProperty::data (int column, int role) const
{
if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
{
return d_ptr->VariantValue.toBool() ? TrueText : FalseText;
}
if (column == DPC_Data && Qt::CheckStateRole == role)
{
return d_ptr->VariantValue.toBool() ? Qt::Checked : Qt::Unchecked;
}
else
return VProperty::data(column, role);
}
@ -61,7 +71,8 @@ bool VBoolProperty::setData(const QVariant &data, int role)
{
if (Qt::CheckStateRole == role)
{
d_ptr->VariantValue = (Qt::Checked == static_cast<Qt::CheckState>(data.toInt())); return true;
d_ptr->VariantValue = (Qt::Checked == static_cast<Qt::CheckState>(data.toInt()));
return true;
}
return false;
@ -71,7 +82,9 @@ bool VBoolProperty::setData(const QVariant &data, int role)
Qt::ItemFlags VBoolProperty::flags(int column) const
{
if (column == DPC_Data)
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
}
else
return VProperty::flags(column);
}

View File

@ -23,7 +23,8 @@
#include "vproperty.h"
namespace VPE{
namespace VPE
{
//! The VBoolProperty can take two states: True or False.
class VPROPERTYEXPLORERSHARED_EXPORT VBoolProperty : public VProperty
@ -52,7 +53,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const;

View File

@ -35,17 +35,24 @@ VColorProperty::VColorProperty(const QString &name) :
QVariant VColorProperty::data (int column, int role) const
{
if (column == DPC_Data && (Qt::DisplayRole == role))
{
return VColorPropertyEditor::getColorString(d_ptr->VariantValue.value<QColor>());
}
else if (Qt::EditRole == role)
{
return QVariant();
}
else if (column == DPC_Data && (Qt::DecorationRole == role))
{
return VColorPropertyEditor::getColorPixmap(d_ptr->VariantValue.value<QColor>());
}
else
return VProperty::data(column, role);
}
//! Returns an editor widget, or NULL if it doesn't supply one
QWidget* VColorProperty::createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate)
QWidget* VColorProperty::createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate)
{
Q_UNUSED(options);
Q_UNUSED(delegate);
@ -60,7 +67,9 @@ bool VColorProperty::setEditorData(QWidget* editor)
{
VColorPropertyEditor* tmpWidget = qobject_cast<VColorPropertyEditor*>(editor);
if (tmpWidget)
{
tmpWidget->setColor(d_ptr->VariantValue.value<QColor>());
}
else
return false;
@ -72,7 +81,9 @@ QVariant VColorProperty::getEditorData(QWidget* editor) const
{
VColorPropertyEditor* tmpWidget = qobject_cast<VColorPropertyEditor*>(editor);
if (tmpWidget)
{
return tmpWidget->getColor();
}
return QVariant();
}

View File

@ -25,7 +25,8 @@
#include "vproperty.h"
namespace VPE {
namespace VPE
{
class VPROPERTYEXPLORERSHARED_EXPORT VColorProperty : public VProperty
{
@ -39,8 +40,10 @@ public:
//! Returns an editor widget, or NULL if it doesn't supply one
//! \param parent The widget to which the editor will be added as a child
//! \options Render options
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate);
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
//! slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate);
//! Sets the property's data to the editor (returns false, if the standard delegate should do that)
virtual bool setEditorData(QWidget* editor);
@ -53,7 +56,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const;

View File

@ -101,7 +101,8 @@ void VColorPropertyEditor::onToolButtonClicked()
bool ok = false;
QRgb oldRgba = Color.rgba();
QRgb newRgba = QColorDialog::getRgba(oldRgba, &ok, this);
if (ok && newRgba != oldRgba) {
if (ok && newRgba != oldRgba)
{
setColor(QColor::fromRgba(newRgba));
emit dataChangedByUser(Color, this);
UserChangeEvent *event = new UserChangeEvent();
@ -127,8 +128,6 @@ VColorPropertyEditor::~VColorPropertyEditor()
//
}
QColor VColorPropertyEditor::getColor()
{
return Color;

View File

@ -29,7 +29,8 @@
#include <QLabel>
#include <QSpacerItem>
namespace VPE{
namespace VPE
{
class VPROPERTYEXPLORERSHARED_EXPORT VColorPropertyEditor : public QWidget
{

View File

@ -43,17 +43,24 @@ VEmptyProperty::~VEmptyProperty()
QVariant VEmptyProperty::data (int column, int role) const
{
if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
{
return QVariant();
}
else if (role == Qt::BackgroundRole)
{
return QBrush(QColor(217, 217, 217));
}
else if (role == Qt::FontRole)
{ QFont tmpFont; tmpFont.setBold(true); return tmpFont; }
{
QFont tmpFont; tmpFont.setBold(true); return tmpFont;
}
else
return VProperty::data(column, role);
}
//! Returns an editor widget, or NULL if it doesn't supply one
QWidget* VEmptyProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate)
QWidget* VEmptyProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate)
{
Q_UNUSED(options);
Q_UNUSED(parent);

View File

@ -23,7 +23,8 @@
#include "vproperty.h"
namespace VPE {
namespace VPE
{
class VPROPERTYEXPLORERSHARED_EXPORT VEmptyProperty : public VProperty
{
@ -40,8 +41,10 @@ public:
//! Returns an editor widget, or NULL if it doesn't supply one
//! \param parent The widget to which the editor will be added as a child
//! \options Render options
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate);
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
//! slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate);
//! Gets the data from the widget
virtual QVariant getEditorData(QWidget* editor) const;
@ -54,7 +57,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const;

View File

@ -38,24 +38,33 @@ VEnumProperty::VEnumProperty(const QString& name)
QVariant VEnumProperty::data (int column, int role) const
{
if (EnumerationLiterals.empty())
{
return QVariant();
}
int tmpIndex = VProperty::d_ptr->VariantValue.toInt();
if (tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count())
{
tmpIndex = 0;
}
if (column == DPC_Data && Qt::DisplayRole == role)
{
return EnumerationLiterals.at(tmpIndex);
}
else if (column == DPC_Data && Qt::EditRole == role)
{
return tmpIndex;
}
else
return VProperty::data(column, role);
}
//! Returns an editor widget, or NULL if it doesn't supply one
QWidget* VEnumProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate)
QWidget* VEnumProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate)
{
Q_UNUSED(options);
Q_UNUSED(delegate);
@ -75,7 +84,9 @@ QVariant VEnumProperty::getEditorData(QWidget* editor) const
{
QComboBox* tmpEditor = qobject_cast<QComboBox*>(editor);
if (tmpEditor)
{
return tmpEditor->currentIndex();
}
return QVariant(0);
}
@ -98,7 +109,9 @@ void VEnumProperty::setValue(const QVariant& value)
int tmpIndex = value.toInt();
if (tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count())
{
tmpIndex = 0;
}
VProperty::d_ptr->VariantValue = tmpIndex;
VProperty::d_ptr->VariantValue.convert(QVariant::Int);
@ -122,13 +135,17 @@ VProperty* VEnumProperty::clone(bool include_children, VProperty* container) con
void VEnumProperty::setSetting(const QString& key, const QVariant& value)
{
if (key == "literals")
{
setLiterals(value.toString().split(";;"));
}
}
QVariant VEnumProperty::getSetting(const QString& key) const
{
if (key == "literals")
{
return getLiterals().join(";;");
}
else
return VProperty::getSetting(key);
}

View File

@ -25,7 +25,8 @@
#include <QStringList>
namespace VPE{
namespace VPE
{
class VPROPERTYEXPLORERSHARED_EXPORT VEnumProperty : public VProperty
{
@ -43,8 +44,10 @@ public:
//! Returns an editor widget, or NULL if it doesn't supply one
//! \param parent The widget to which the editor will be added as a child
//! \options Render options
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate);
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
//! slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate);
//! Gets the data from the widget
virtual QVariant getEditorData(QWidget* editor) const;
@ -63,7 +66,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const;
@ -84,7 +88,8 @@ public slots:
protected:
//! The list of possible options to choose frome
QStringList EnumerationLiterals;
// No use of d-pointer in this case, because it is unlikely this will change. If it does, we can still add other members by reimplementing the VPropertyPrivate class without touching this header file.
// No use of d-pointer in this case, because it is unlikely this will change. If it does, we can still add other
//members by reimplementing the VPropertyPrivate class without touching this header file.
};
}

View File

@ -76,13 +76,17 @@ QVariant VFileProperty::data (int column, int role) const
}
QWidget* VFileProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate)
QWidget* VFileProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate)
{
Q_UNUSED(options);
VFileEditWidget* tmpWidget = new VFileEditWidget(parent);
if (delegate)
{
VFileEditWidget::connect(tmpWidget, SIGNAL(commitData(QWidget*)), delegate, SIGNAL(commitData(QWidget*)));
}
tmpWidget->setFilter(static_cast<VFilePropertyPrivate*>(d_ptr)->FileFilters); // todo: parse this string
tmpWidget->setFile(d_ptr->VariantValue.toString());
tmpWidget->setDirectory(static_cast<VFilePropertyPrivate*>(d_ptr)->Directory);
@ -94,7 +98,9 @@ bool VFileProperty::setEditorData(QWidget* editor)
{
VFileEditWidget* tmpWidget = qobject_cast<VFileEditWidget*>(editor);
if (tmpWidget)
{
tmpWidget->setFile(d_ptr->VariantValue.toString());
}
else
return false;
@ -106,7 +112,9 @@ QVariant VFileProperty::getEditorData(QWidget* editor) const
{
VFileEditWidget* tmpWidget = qobject_cast<VFileEditWidget*>(editor);
if (tmpWidget)
{
return tmpWidget->getFile();
}
return QVariant();
}
@ -114,17 +122,25 @@ QVariant VFileProperty::getEditorData(QWidget* editor) const
void VFileProperty::setSetting(const QString& key, const QVariant& value)
{
if (key == "FileFilters")
{
setFileFilters(value.toString());
}
else if (key == "Directory")
{
setDirectory(value.toBool());
}
}
QVariant VFileProperty::getSetting(const QString& key) const
{
if (key == "FileFilters")
{
return getFileFilters();
}
else if (key == "Directory")
{
return isDirectory();
}
else
return VProperty::getSetting(key);
}

View File

@ -27,7 +27,8 @@
#include <QPointer>
namespace VPE {
namespace VPE
{
class VPROPERTYEXPLORERSHARED_EXPORT VFileProperty : public VProperty
{
@ -55,8 +56,10 @@ public:
//! Returns an editor widget, or NULL if it doesn't supply one
//! \param parent The widget to which the editor will be added as a child
//! \options Render options
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate);
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
//! slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate);
//! Sets the property's data to the editor (returns false, if the standard delegate should do that)
virtual bool setEditorData(QWidget* editor);
@ -80,7 +83,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const;

View File

@ -101,10 +101,14 @@ QString VFileEditWidget::getFile()
void VFileEditWidget::onToolButtonClicked()
{
QString filepath = (Directory ? QFileDialog::getExistingDirectory(0, tr("Directory"), CurrentFilePath) : QFileDialog::getOpenFileName(0, tr("Open File"), CurrentFilePath, FileDialogFilter));
if (!filepath.isNull())
QString filepath = (Directory ? QFileDialog::getExistingDirectory(0, tr("Directory"), CurrentFilePath)
: QFileDialog::getOpenFileName(0, tr("Open File"), CurrentFilePath,
FileDialogFilter));
if (filepath.isNull() == false)
{
setFile(filepath, true);
}
}
bool VFileEditWidget::eventFilter(QObject *obj, QEvent *ev)
@ -113,12 +117,18 @@ bool VFileEditWidget::eventFilter(QObject *obj, QEvent *ev)
{
ev->ignore();
if (ev->type() == QEvent::DragEnter)
{
dragEnterEvent(static_cast<QDragEnterEvent*>(ev));
}
else if (ev->type() == QEvent::Drop)
{
dropEvent(static_cast<QDropEvent*>(ev));
}
if (ev->isAccepted())
{
return true;
}
else
return QWidget::eventFilter(obj, ev);
}
@ -190,7 +200,9 @@ bool VFileEditWidget::checkMimeData(const QMimeData* data, QString& file) const
foreach(QUrl tmpUrl, tmpUrlList)
if (QFile::exists(tmpUrl.toLocalFile()))
{ tmpFileInfo = QFileInfo(tmpUrl.toLocalFile()); break; }
{
tmpFileInfo = QFileInfo(tmpUrl.toLocalFile()); break;
}
if (checkFileFilter(tmpFileInfo.fileName()))
{
@ -205,20 +217,25 @@ bool VFileEditWidget::checkMimeData(const QMimeData* data, QString& file) const
bool VFileEditWidget::checkFileFilter(const QString& file) const
{
if (FilterList.isEmpty())
{
return true;
}
QFileInfo tmpFileInfo(file);
if ((Directory && !tmpFileInfo.isDir()) || (!Directory && !tmpFileInfo.isFile()))
{
return false;
}
foreach(QString tmpFilter, FilterList)
{
QRegExp tmpRegExpFilter(tmpFilter, Qt::CaseInsensitive, QRegExp::Wildcard);
if (tmpRegExpFilter.exactMatch(file))
{
return true;
}
}
return false;
}

View File

@ -28,7 +28,8 @@
#include <QLineEdit>
#include <QMimeData>
namespace VPE{
namespace VPE
{
class VPROPERTYEXPLORERSHARED_EXPORT VFileEditWidget : public QWidget
@ -85,8 +86,6 @@ protected:
void dragLeaveEvent(QDragLeaveEvent* event);
void dropEvent(QDropEvent* event);
//! This function checks the mime data, if it is compatible with the filters
virtual bool checkMimeData(const QMimeData* data, QString& getFile) const;

View File

@ -34,7 +34,7 @@ const int VIntegerProperty::StandardMin = -1000000;
const int VIntegerProperty::StandardMax = 1000000;
VIntegerProperty::VIntegerProperty(const QString& name, const QMap<QString, QVariant>& settings)
: VProperty(name, QVariant::Int), min(StandardMin), max(StandardMax), singleStep(1.0)
: VProperty(name, QVariant::Int), minValue(StandardMin), maxValue(StandardMax), singleStep(1.0)
{
VProperty::setSettings(settings);
VProperty::d_ptr->VariantValue.setValue(0);
@ -42,21 +42,22 @@ VIntegerProperty::VIntegerProperty(const QString& name, const QMap<QString, QVar
}
VIntegerProperty::VIntegerProperty(const QString &name)
: VProperty(name), min(StandardMin), max(StandardMax)
: VProperty(name), minValue(StandardMin), maxValue(StandardMax)
{
VProperty::d_ptr->VariantValue.setValue(0);
VProperty::d_ptr->VariantValue.convert(QVariant::Int);
}
//! Returns an editor widget, or NULL if it doesn't supply one
QWidget* VIntegerProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate)
QWidget* VIntegerProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate)
{
Q_UNUSED(options);
Q_UNUSED(delegate);
QSpinBox* tmpEditor = new QSpinBox(parent);
tmpEditor->setMinimum(min);
tmpEditor->setMaximum(max);
tmpEditor->setMinimum(minValue);
tmpEditor->setMaximum(maxValue);
tmpEditor->setSingleStep(singleStep);
tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tmpEditor->setValue(VProperty::d_ptr->VariantValue.toInt());
@ -72,36 +73,50 @@ QVariant VIntegerProperty::getEditorData(QWidget* editor) const
{
QSpinBox* tmpEditor = qobject_cast<QSpinBox*>(editor);
if (tmpEditor)
{
return tmpEditor->value();
}
return QVariant(0);
}
void VIntegerProperty::setSettings(int minimum, int maxiumum, int singleStep)
{
min = minimum;
max = maxiumum;
minValue = minimum;
maxValue = maxiumum;
this->singleStep = singleStep;
}
void VIntegerProperty::setSetting(const QString& key, const QVariant& value)
{
if (key == QLatin1String("Min"))
setSettings(value.toInt(), max);
{
setSettings(value.toInt(), maxValue);
}
else if (key == QLatin1String("Max"))
setSettings(min, value.toInt());
{
setSettings(minValue, value.toInt());
}
else if (key == QLatin1String("Step"))
{
setSettings(singleStep, value.toInt());
}
}
QVariant VIntegerProperty::getSetting(const QString& key) const
{
if (key == QLatin1String("Min"))
return min;
{
return minValue;
}
if (key == QLatin1String("Max"))
return max;
{
return maxValue;
}
if (key == QLatin1String("Step"))
{
return singleStep;
}
else
return VProperty::getSetting(key);
}
@ -128,10 +143,6 @@ void VIntegerProperty::valueChanged(int i)
QCoreApplication::postEvent ( VProperty::d_ptr->editor, event );
}
const double VDoubleProperty::StandardPrecision = 5;
VDoubleProperty::VDoubleProperty(const QString& name, const QMap<QString, QVariant>& settings)
@ -152,13 +163,14 @@ VDoubleProperty::VDoubleProperty(const QString &name)
}
//! Returns an editor widget, or NULL if it doesn't supply one
QWidget* VDoubleProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate)
QWidget* VDoubleProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate)
{
Q_UNUSED(options);
Q_UNUSED(delegate);
QDoubleSpinBox* tmpEditor = new QDoubleSpinBox(parent);
tmpEditor->setMinimum(min);
tmpEditor->setMaximum(max);
tmpEditor->setMinimum(minValue);
tmpEditor->setMaximum(maxValue);
tmpEditor->setDecimals(Precision);
tmpEditor->setSingleStep(singleStep);
tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@ -175,15 +187,17 @@ QVariant VDoubleProperty::getEditorData(QWidget* editor) const
{
QDoubleSpinBox* tmpEditor = qobject_cast<QDoubleSpinBox*>(editor);
if (tmpEditor)
{
return tmpEditor->value();
}
return QVariant(0);
}
void VDoubleProperty::setSettings(double minimum, double maxiumum, double singleStep, int precision)
{
min = minimum;
max = maxiumum;
minValue = minimum;
maxValue = maxiumum;
this->singleStep = singleStep;
Precision = precision;
}
@ -191,25 +205,41 @@ void VDoubleProperty::setSettings(double minimum, double maxiumum, double single
void VDoubleProperty::setSetting(const QString& key, const QVariant& value)
{
if (key == QLatin1String("Min"))
setSettings(value.toDouble(), max, singleStep, Precision);
{
setSettings(value.toDouble(), maxValue, singleStep, Precision);
}
else if (key == QLatin1String("Max"))
setSettings(min, value.toDouble(), singleStep, Precision);
{
setSettings(minValue, value.toDouble(), singleStep, Precision);
}
else if (key == QLatin1String("Step"))
setSettings(min, max, value.toDouble(), Precision);
{
setSettings(minValue, maxValue, value.toDouble(), Precision);
}
else if (key == QLatin1String("Precision"))
setSettings(min, max, singleStep, value.toDouble());
{
setSettings(minValue, maxValue, singleStep, value.toDouble());
}
}
QVariant VDoubleProperty::getSetting(const QString& key) const
{
if (key == QLatin1String("Min"))
return min;
{
return minValue;
}
if (key == QLatin1String("Max"))
return max;
{
return maxValue;
}
if (key == QLatin1String("Step"))
{
return singleStep;
}
if (key == QLatin1String("Precision"))
{
return Precision;
}
else
return VProperty::getSetting(key);
}

View File

@ -24,7 +24,8 @@
#include "vpropertyexplorer_global.h"
#include "vproperty.h"
namespace VPE {
namespace VPE
{
//! Class for holding an integer property
@ -39,8 +40,10 @@ public:
//! Returns an editor widget, or NULL if it doesn't supply one
//! \param parent The widget to which the editor will be added as a child
//! \options Render options
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate);
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
//! slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate);
//! Gets the data from the widget
virtual QVariant getEditorData(QWidget* editor) const;
@ -67,13 +70,14 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const;
public slots:
void valueChanged(int i);
protected:
double min, max, singleStep;
double minValue, maxValue, singleStep;
static const int StandardMin;// = -1000000;
static const int StandardMax;// = 1000000;
@ -92,8 +96,10 @@ public:
//! Returns an editor widget, or NULL if it doesn't supply one
//! \param parent The widget to which the editor will be added as a child
//! \options Render options
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate);
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
//! slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate);
//! Gets the data from the widget
virtual QVariant getEditorData(QWidget* editor) const;
@ -121,7 +127,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const;

View File

@ -38,7 +38,9 @@ VObjectProperty::VObjectProperty(const QString& name)
QVariant VObjectProperty::data (int column, int role) const
{
if (objects.empty())
{
return QVariant();
}
QComboBox* tmpEditor = qobject_cast<QComboBox*>(VProperty::d_ptr->editor);
@ -47,7 +49,9 @@ QVariant VObjectProperty::data (int column, int role) const
return VProperty::d_ptr->VariantValue;
}
else if (column == DPC_Data && Qt::EditRole == role)
{
return tmpEditor->currentIndex();
}
else
return VProperty::data(column, role);
}
@ -72,7 +76,9 @@ QWidget* VObjectProperty::createEditor(QWidget * parent, const QStyleOptionViewI
bool VObjectProperty::setEditorData(QWidget *editor)
{
if (!editor)
{
return false;
}
QComboBox* tmpEditor = qobject_cast<QComboBox*>(editor);
if (tmpEditor)
@ -98,7 +104,9 @@ QVariant VObjectProperty::getEditorData(QWidget* editor) const
{
QComboBox* tmpEditor = qobject_cast<QComboBox*>(editor);
if (tmpEditor)
{
return tmpEditor->itemData(tmpEditor->currentIndex());
}
return QVariant(0);
}

View File

@ -27,7 +27,8 @@
class QComboBox;
namespace VPE{
namespace VPE
{
class VPROPERTYEXPLORERSHARED_EXPORT VObjectProperty : public VProperty
{
@ -45,8 +46,10 @@ public:
//! Returns an editor widget, or NULL if it doesn't supply one
//! \param parent The widget to which the editor will be added as a child
//! \options Render options
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate);
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
//! slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate);
//! Sets the property's data to the editor (returns false, if the standard delegate should do that)
virtual bool setEditorData(QWidget* editor);
@ -68,7 +71,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const;
@ -80,7 +84,8 @@ protected:
QMap<QString, quint32> objects;
void FillList(QComboBox *box, const QMap<QString, quint32> &list)const;
// No use of d-pointer in this case, because it is unlikely this will change. If it does, we can still add other members by reimplementing the VPropertyPrivate class without touching this header file.
// No use of d-pointer in this case, because it is unlikely this will change. If it does, we can still add other
//members by reimplementing the VPropertyPrivate class without touching this header file.
};
}

View File

@ -56,7 +56,9 @@ QVariant VPointFProperty::data(int column, int role) const
Qt::ItemFlags VPointFProperty::flags(int column) const
{
if (column == DPC_Name || column == DPC_Data)
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
else
return Qt::NoItemFlags;
}
@ -66,7 +68,9 @@ QPointF VPointFProperty::getPointF() const
QPointF tmpValue;
if (d_ptr->Children.count() < 2)
{
return tmpValue;
}
tmpValue.setX(d_ptr->Children.at(0)->getValue().toDouble());
tmpValue.setY(d_ptr->Children.at(1)->getValue().toDouble());
@ -82,7 +86,9 @@ void VPointFProperty::setPointF(const QPointF &point)
void VPointFProperty::setPointF(qreal x, qreal y)
{
if (d_ptr->Children.count() < 2)
{
return;
}
QVariant tmpX(x);
tmpX.convert(QVariant::Double);
@ -101,12 +107,15 @@ QString VPointFProperty::type() const
VProperty *VPointFProperty::clone(bool include_children, VProperty *container) const
{
if(!container) {
if (!container)
{
container = new VPointFProperty(getName());
if(!include_children) {
if (!include_children)
{
QList<VProperty*> tmpChildren = container->getChildren();
foreach(VProperty* tmpChild, tmpChildren) {
foreach(VProperty* tmpChild, tmpChildren)
{
container->removeChild(tmpChild);
delete tmpChild;
}

View File

@ -25,7 +25,8 @@
#include "vproperty.h"
namespace VPE{
namespace VPE
{
class VPROPERTYEXPLORERSHARED_EXPORT VPointFProperty : public VProperty
{
@ -54,7 +55,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const;

View File

@ -58,7 +58,9 @@ QWidget* VShortcutProperty::createEditor(QWidget * parent, const QStyleOptionVie
VShortcutEditWidget* tmpWidget = new VShortcutEditWidget(parent);
if (delegate)
{
VShortcutEditWidget::connect(tmpWidget, SIGNAL(commitData(QWidget*)), delegate, SIGNAL(commitData(QWidget*)));
}
return tmpWidget;
return nullptr;
@ -69,7 +71,9 @@ bool VShortcutProperty::setEditorData(QWidget* editor)
{
VShortcutEditWidget* tmpWidget = qobject_cast<VShortcutEditWidget*>(editor);
if (tmpWidget)
{
tmpWidget->setShortcut(d_ptr->VariantValue.toString(), false);
}
else
return false;
@ -81,7 +85,9 @@ QVariant VShortcutProperty::getEditorData(QWidget* editor) const
{
VShortcutEditWidget* tmpWidget = qobject_cast<VShortcutEditWidget*>(editor);
if (tmpWidget)
{
return tmpWidget->getShortcutAsString();
}
return QVariant();
}
@ -101,4 +107,3 @@ void VShortcutProperty::setValue(const QVariant &value)
{
VProperty::setValue(QKeySequence::fromString(value.toString()).toString());
}

View File

@ -24,7 +24,8 @@
#include "vpropertyexplorer_global.h"
#include "vproperty.h"
namespace VPE {
namespace VPE
{
//! This property can be used to handle key shortcuts
class VPROPERTYEXPLORERSHARED_EXPORT VShortcutProperty : public VProperty
@ -41,7 +42,8 @@ public:
//! Returns an editor widget, or NULL if it doesn't supply one
//! \param parent The widget to which the editor will be added as a child
//! \options Render options
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots.
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
//! slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate);
@ -56,7 +58,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const;

View File

@ -51,8 +51,10 @@ VShortcutEditWidget::~VShortcutEditWidget()
bool VShortcutEditWidget::eventFilter(QObject *obj, QEvent *event)
{
if (obj == LineEdit) {
if (event->type() == QEvent::KeyPress) {
if (obj == LineEdit)
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
int keys = keyEvent->key();
@ -83,8 +85,6 @@ QKeySequence VShortcutEditWidget::getShortcut()
return CurrentKeySequence;
}
void VShortcutEditWidget::setShortcut(const QString &shortcut, bool emit_signal)
{
setShortcut(QKeySequence::fromString(shortcut), emit_signal);
@ -92,13 +92,16 @@ void VShortcutEditWidget::setShortcut(const QString &shortcut, bool emit_signal)
void VShortcutEditWidget::setShortcut(const QKeySequence &shortcut, bool emit_signal)
{
if(shortcut != CurrentKeySequence) {
if (shortcut != CurrentKeySequence)
{
CurrentKeySequence = shortcut;
LineEdit->setText(CurrentKeySequence.toString());
if (emit_signal)
{
emit dataChangedByUser(CurrentKeySequence, this);
}
}
}
void VShortcutEditWidget::onTextEdited(const QString &text)
{

View File

@ -28,7 +28,8 @@
#include <QLineEdit>
#include <QMimeData>
namespace VPE{
namespace VPE
{
class VPROPERTYEXPLORERSHARED_EXPORT VShortcutEditWidget : public QWidget

View File

@ -62,7 +62,9 @@ QVariant VPE::VStringProperty::getEditorData(QWidget *editor) const
{
QLineEdit* tmpEditor = qobject_cast<QLineEdit*>(editor);
if (tmpEditor)
{
return tmpEditor->text();
}
return QVariant(QStringLiteral(""));
}
@ -75,17 +77,25 @@ void VPE::VStringProperty::setReadOnly(bool readOnly)
void VPE::VStringProperty::setSetting(const QString &key, const QVariant &value)
{
if (key == QLatin1String("ReadOnly"))
{
setReadOnly(value.toBool());
}
if (key == QLatin1String("TypeForParent"))
{
setTypeForParent(value.toInt());
}
}
QVariant VPE::VStringProperty::getSetting(const QString &key) const
{
if (key == QLatin1String("ReadOnly"))
{
return readOnly;
}
else if (key == QLatin1String("TypeForParent"))
{
return typeForParent;
}
else
return VProperty::getSetting(key);
}
@ -121,4 +131,3 @@ void VStringProperty::setTypeForParent(int value)
{
typeForParent = value;
}

View File

@ -24,7 +24,8 @@
#include "vpropertyexplorer_global.h"
#include "vproperty.h"
namespace VPE {
namespace VPE
{
//! Class for holding a string property
@ -38,8 +39,10 @@ public:
//! Returns an editor widget, or NULL if it doesn't supply one
//! \param parent The widget to which the editor will be added as a child
//! \options Render options
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate);
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
//! slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate);
//! Gets the data from the widget
virtual QVariant getEditorData(QWidget* editor) const;
@ -60,7 +63,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const;

View File

@ -25,9 +25,6 @@
using namespace VPE;
VWidgetProperty::VWidgetProperty(const QString& name, QWidget* widget)
: VEmptyProperty(new VWidgetPropertyPrivate(name, QVariant::Invalid, widget))
{
@ -48,7 +45,9 @@ void VWidgetProperty::setWidget(QWidget* widget)
VWidgetPropertyPrivate* tmpDPtr = static_cast<VWidgetPropertyPrivate*>(d_ptr);
QWidget* tmpOldWidget = tmpDPtr->Widget.data();
if (tmpOldWidget)
{
tmpOldWidget->deleteLater();
}
tmpDPtr->Widget = widget;
}
@ -61,6 +60,8 @@ QString VWidgetProperty::type() const
VProperty* VWidgetProperty::clone(bool include_children, VProperty* container) const
{
// todo: This is a tricky one to clone... don't know what would be the best way to do so... Maybe serialize the widget somehow?
/* todo: This is a tricky one to clone... don't know what would be the best way to do so... Maybe serialize the
* widget somehow?
*/
return VProperty::clone(include_children, container ? container : new VWidgetProperty(getName()));
}

View File

@ -27,11 +27,14 @@
#include <QPointer>
namespace VPE {
namespace VPE
{
// todo: this way, this class doesn't really make sense. What we have to do is pass a widget factory instead of the actual widget!
// todo: this way, this class doesn't really make sense. What we have to do is pass a widget factory instead of the
// actual widget!
//! This property holds a QWidget and displays it, if the view supports that. If not, it will behave like an empty property
//! This property holds a QWidget and displays it, if the view supports that. If not, it will behave like an empty
//! property
class VPROPERTYEXPLORERSHARED_EXPORT VWidgetProperty : public VEmptyProperty
{
public:
@ -52,7 +55,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const;
};

View File

@ -24,7 +24,8 @@
#include "vpropertyexplorer_global.h"
#include <QObject>
namespace VPE {
namespace VPE
{
class VProperty;

View File

@ -25,9 +25,11 @@
#include "vproperty_p.h"
namespace VPE {
namespace VPE
{
class VFilePropertyPrivate : public VPropertyPrivate {
class VFilePropertyPrivate : public VPropertyPrivate
{
public:
//! File filters
QString FileFilters;

View File

@ -63,11 +63,17 @@ QString VProperty::type() const
QVariant VProperty::data (int column, int role) const
{
if (column == DPC_Name && Qt::DisplayRole == role)
{
return QVariant(d_ptr->Name);
}
else if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
{
return d_ptr->VariantValue;
}
else if (Qt::ToolTipRole == role)
{
return QVariant(d_ptr->Description);
}
else
return QVariant();
}
@ -84,7 +90,8 @@ bool VProperty::setData(const QVariant &data, int role)
return tmpResult;
}
bool VProperty::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, const QAbstractItemDelegate *delegate) const
bool VProperty::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index,
const QAbstractItemDelegate *delegate) const
{
Q_UNUSED(painter);
Q_UNUSED(option);
@ -95,7 +102,8 @@ bool VProperty::paint(QPainter *painter, const QStyleOptionViewItem &option, con
}
//! Returns an editor widget, or NULL if it doesn't supply one
QWidget* VProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate)
QWidget* VProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate)
{
Q_UNUSED(options);
Q_UNUSED(delegate);
@ -112,11 +120,14 @@ QWidget* VProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& o
bool VProperty::setEditorData(QWidget* editor)
{
if (!editor)
{
return false;
}
QByteArray n = editor->metaObject()->userProperty().name();
if (!n.isEmpty()) {
if (!n.isEmpty())
{
editor->blockSignals(true);
editor->setProperty(n, d_ptr->VariantValue);
editor->blockSignals(false);
@ -130,12 +141,16 @@ bool VProperty::setEditorData(QWidget* editor)
QVariant VProperty::getEditorData(QWidget* editor) const
{
if (!editor)
{
return QVariant();
}
QByteArray n = editor->metaObject()->userProperty().name();
if (!n.isEmpty())
{
return editor->property(n);
}
else
return QVariant();
}
@ -144,9 +159,13 @@ QVariant VProperty::getEditorData(QWidget* editor) const
Qt::ItemFlags VProperty::flags(int column) const
{
if (column == DPC_Name)
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
else if (column == DPC_Data)
{
return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable;
}
else
return Qt::NoItemFlags;
}
@ -162,7 +181,6 @@ void VProperty::setValue(const QVariant &value)
}
}
QVariant VProperty::getValue() const
{
return d_ptr->VariantValue;
@ -202,9 +220,6 @@ QString VProperty::getDescription() const
return d_ptr->Description;
}
//! Returns a reference to the list of children
QList<VProperty*>& VProperty::getChildren()
{
@ -221,7 +236,9 @@ const QList<VProperty*>& VProperty::getChildren() const
VProperty* VProperty::getChild(int row) const
{
if (row >= 0 && row < getRowCount())
{
return d_ptr->Children.at(row);
}
else
return nullptr;
}
@ -242,22 +259,30 @@ VProperty* VProperty::getParent() const
void VProperty::setParent(VProperty* parent)
{
if (d_ptr->Parent == parent)
{
return;
}
VProperty* oldParent = d_ptr->Parent;
d_ptr->Parent = parent;
if (oldParent)
{
oldParent->removeChild(this);
}
if (d_ptr->Parent && d_ptr->Parent->getChildRow(this) == -1)
{
d_ptr->Parent->addChild(this);
}
}
int VProperty::addChild(VProperty *child)
{
if (child && child->getParent() != this)
{
child->setParent(this);
}
if (!d_ptr->Children.contains(child) && child != nullptr)
{
@ -276,8 +301,10 @@ void VProperty::removeChild(VProperty* child)
d_ptr->Children.removeAll(child);
if (child && child->getParent() == this)
{
child->setParent(nullptr);
}
}
//! Returns the row the child has
int VProperty::getChildRow(VProperty* child) const
@ -285,7 +312,6 @@ int VProperty::getChildRow(VProperty* child) const
return d_ptr->Children.indexOf(child);
}
//! Returns whether the views have to update the parent of this property if it changes
bool VProperty::getUpdateParent() const
{
@ -309,7 +335,8 @@ void VProperty::setUpdateBehaviour(bool update_parent, bool update_children)
void VProperty::setSettings(const QMap<QString, QVariant>& settings)
{
QMap<QString, QVariant>::const_iterator tmpIterator = settings.constBegin();
for (; tmpIterator != settings.constEnd(); ++tmpIterator) {
for (; tmpIterator != settings.constEnd(); ++tmpIterator)
{
setSetting(tmpIterator.key(), tmpIterator.value());
}
}
@ -347,7 +374,9 @@ QStringList VProperty::getSettingKeys() const
VProperty* VProperty::clone(bool include_children, VProperty* container) const
{
if (!container)
{
container = new VProperty(getName(), d_ptr->PropertyVariantType);
}
container->setName(getName());
container->setDescription(getDescription());
@ -356,7 +385,8 @@ VProperty* VProperty::clone(bool include_children, VProperty* container) const
container->setUpdateBehaviour(getUpdateParent(), getUpdateChildren());
container->setPropertyType(propertyType());
if(include_children) {
if (include_children)
{
foreach(VProperty* tmpChild, d_ptr->Children)
container->addChild(tmpChild->clone(true));
}

View File

@ -30,7 +30,8 @@
#include <QAbstractItemDelegate>
#include <QEvent>
namespace VPE {
namespace VPE
{
enum class Property : char{Simple, Complex};
@ -48,7 +49,8 @@ class VPROPERTYEXPLORERSHARED_EXPORT VProperty : public QObject
{
Q_OBJECT
public:
enum DPC_DisplayColumn {
enum DPC_DisplayColumn
{
DPC_Name = 0,
DPC_Data
};
@ -74,13 +76,16 @@ public:
//! This is called by the delegate when the property value is being drawn.
//! The standard implementation doesn't do anything.
//! If you reimplement this in a sub property, make sure to return true or the delegate will draw the item.
virtual bool paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, const QAbstractItemDelegate* delegate) const;
virtual bool paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index,
const QAbstractItemDelegate* delegate) const;
//! Returns an editor widget, or NULL if it doesn't supply one
//! \param parent The widget to which the editor will be added as a child
//! \options Render options
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate);
//! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
//! slots.
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate);
//! Sets the property's data to the editor (returns false, if the standard delegate should do that)
virtual bool setEditorData(QWidget* editor);
@ -104,12 +109,15 @@ public:
virtual void deserialize(const QString& value);
// The following functions are experimental and not yet implemented.
/*//! Returns a pointer to the data stored and handled by this property. In most cases this function shouldn't be used.
//! \return Returns a void pointer to the data. Not all properties have to support this. By default, this implementation returns a NULL pointer.
/*//! Returns a pointer to the data stored and handled by this property. In most cases this function shouldn't be
//! used.
//! \return Returns a void pointer to the data. Not all properties have to support this. By default, this
//! implementation returns a NULL pointer.
virtual void* getDataPointer();
//! Sets the data.
//! \return Returns a void pointer to the data. Not all properties have to support this. By default, this implementation returns a NULL pointer.
//! \return Returns a void pointer to the data. Not all properties have to support this. By default, this
//! implementation returns a NULL pointer.
virtual bool setDataPointer(void* pointer);*/
//! Sets the name of the property
@ -160,7 +168,8 @@ public:
//! Sets whether the views should update Parents or children after this property changes
virtual void setUpdateBehaviour(bool update_parent, bool update_children);
//! Sets the settings by calling the overloaded setSetting(const QString& key, const QVariant& value) for each item in the map.
//! Sets the settings by calling the overloaded setSetting(const QString& key, const QVariant& value) for each item
//! in the map.
virtual void setSettings(const QMap<QString, QVariant>& settings);
//! Get the settings.
@ -177,7 +186,8 @@ public:
//! Clones this property
//! \param include_children Indicates whether to also clone the children
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function.
//! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
//! to fill all the data into container. This can also be used when subclassing this function.
//! \return Returns the newly created property (or container, if it was not NULL)
virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const;

View File

@ -27,9 +27,11 @@
#include <QString>
#include "vproperty.h"
namespace VPE {
namespace VPE
{
class VPropertyPrivate {
class VPropertyPrivate
{
public:
//! The property's value.
//! This does not have to be used by subclasses, but it makes sense in cases where QVariant supports

View File

@ -38,7 +38,8 @@ VPropertyDelegate::~VPropertyDelegate()
//
}
QWidget* VPropertyDelegate::createEditor (QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
QWidget* VPropertyDelegate::createEditor (QWidget* parent, const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
QWidget* tmpWidget = nullptr;
if (index.isValid())
@ -62,8 +63,10 @@ void VPropertyDelegate::setEditorData (QWidget * editor, const QModelIndex & ind
}
if (!done)
{
QStyledItemDelegate::setEditorData(editor, index);
}
}
//! Updates the index data
void VPropertyDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const
@ -76,7 +79,9 @@ void VPropertyDelegate::setModelData (QWidget * editor, QAbstractItemModel * mod
}
if (tmpData.isNull())
{
QStyledItemDelegate::setModelData(editor, model, index);
}
else
model->setData(index, tmpData);
}
@ -87,7 +92,9 @@ QSize VPropertyDelegate::sizeHint (const QStyleOptionViewItem& option, const QMo
tmpStandardSizeHint.setHeight(tmpStandardSizeHint.height() + 1);
if (RowHeight > 0)
{
return QSize(tmpStandardSizeHint.width(), AddRowHeight ? tmpStandardSizeHint.height() + RowHeight : RowHeight);
}
else
return tmpStandardSizeHint;
}
@ -102,10 +109,14 @@ void VPropertyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& opt
{
bool done = false;
if (index.isValid() && index.column() == 1)
{
done = reinterpret_cast<VProperty*>(index.internalPointer())->paint(painter, option, index, this);
}
if (!done)
{
QStyledItemDelegate::paint(painter, option, index);
}
QColor tmpPenColor = static_cast<QRgb>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &option));
@ -115,6 +126,3 @@ void VPropertyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& opt
painter->drawLine(option.rect.x(), option.rect.bottom(), option.rect.right(), option.rect.bottom());
painter->setPen(tmpOldPen);
}

View File

@ -25,7 +25,8 @@
#include <QStyledItemDelegate>
namespace VPE {
namespace VPE
{
class VPROPERTYEXPLORERSHARED_EXPORT VPropertyDelegate : public QStyledItemDelegate
{

View File

@ -39,7 +39,8 @@ VPropertyFactoryManager::~VPropertyFactoryManager()
{
// Delete all factories
QList<VAbstractPropertyFactory*> tmpFactories = d_ptr->Factories.values();
while(!tmpFactories.isEmpty()) {
while (!tmpFactories.isEmpty())
{
VAbstractPropertyFactory* tmpFactory = tmpFactories.takeLast();
tmpFactories.removeAll(tmpFactory);
delete tmpFactory;
@ -48,13 +49,17 @@ VPropertyFactoryManager::~VPropertyFactoryManager()
delete d_ptr;
if (this == DefaultManager)
{
DefaultManager = NULL;
}
}
void VPropertyFactoryManager::registerFactory(const QString& type, VAbstractPropertyFactory* factory)
{
if (type.isEmpty())
{
return;
}
// Remove old factory
unregisterFactory(getFactory(type), type, true);
@ -62,27 +67,41 @@ void VPropertyFactoryManager::registerFactory(const QString& type, VAbstractProp
d_ptr->Factories[type] = factory;
}
void VPropertyFactoryManager::unregisterFactory(VAbstractPropertyFactory* factory, const QString& type, bool delete_if_unused)
void VPropertyFactoryManager::unregisterFactory(VAbstractPropertyFactory* factory, const QString& type,
bool delete_if_unused)
{
if (!factory)
{
return;
}
if(!type.isEmpty()) {
if (!type.isEmpty())
{
// Remove all occurances
QString tmpKey;
do {
do
{
tmpKey = d_ptr->Factories.key(factory, QString());
if(!tmpKey.isEmpty()) d_ptr->Factories.remove(tmpKey);
if (!tmpKey.isEmpty())
{
d_ptr->Factories.remove(tmpKey);
}
} while(!tmpKey.isEmpty());
} else {
}
else
{
// Only remove one type
if (d_ptr->Factories.value(type, NULL) == factory)
{
d_ptr->Factories.remove(type);
}
}
if (delete_if_unused && !isRegistered(factory))
{
delete factory;
}
}
bool VPropertyFactoryManager::isRegistered(VAbstractPropertyFactory* factory)
{
@ -95,27 +114,33 @@ VAbstractPropertyFactory* VPropertyFactoryManager::getFactory(const QString& typ
}
VProperty* VPropertyFactoryManager::createProperty(const QString& type, const QString& name, const QString& description, const QString &default_value)
VProperty* VPropertyFactoryManager::createProperty(const QString& type, const QString& name, const QString& description,
const QString &default_value)
{
VAbstractPropertyFactory* tmpFactory = getFactory(type);
VProperty* tmpResult = NULL;
if(tmpFactory) {
if (tmpFactory)
{
tmpResult = tmpFactory->createProperty(type, name);
if(tmpResult) {
if (tmpResult)
{
tmpResult->setDescription(description);
if (!default_value.isEmpty())
{
tmpResult->deserialize(default_value);
}
}
}
return tmpResult;
}
VPropertyFactoryManager *VPropertyFactoryManager::getDefaultManager()
{
if(!DefaultManager) {
if (!DefaultManager)
{
DefaultManager = new VPropertyFactoryManager();
/*VStandardPropertyFactory* tmpStandardProp = */new VStandardPropertyFactory(DefaultManager);
}

View File

@ -24,7 +24,8 @@
#include "vpropertyexplorer_global.h"
#include <QObject>
namespace VPE {
namespace VPE
{
class VAbstractPropertyFactory;
class VPropertyFactoryManagerPrivate;
@ -47,8 +48,10 @@ public:
//! Removes a factory from the manager.
//! \param factory The factory to unregister
//! \param type The type from which to remove the factory. If this is empty, all the types the factory is registered for are being removed
//! \param delete_if_unused Determines whether the factory should be deleted, if it not used anymore by this manager. Default: true. Otherwise, if the factory is unused by this manager, ownership is being passed on.
//! \param type The type from which to remove the factory. If this is empty, all the types the factory is registered
//! for are being removed
//! \param delete_if_unused Determines whether the factory should be deleted, if it not used anymore by this
//! manager. Default: true. Otherwise, if the factory is unused by this manager, ownership is being passed on.
void unregisterFactory(VAbstractPropertyFactory* factory, const QString& type = QString(),
bool delete_if_unused = true);

View File

@ -26,11 +26,13 @@
#include <QMap>
#include <QString>
namespace VPE {
namespace VPE
{
class VAbstractPropertyFactory;
class VPropertyFactoryManagerPrivate {
class VPropertyFactoryManagerPrivate
{
public:
QMap<QString, VAbstractPropertyFactory*> Factories;

View File

@ -67,16 +67,21 @@ void VPropertyFormView::setModel(VPropertyModel *model)
// Set model
static_cast<VPropertyFormViewPrivate*>(d_ptr)->Model = model;
if(model) {
if (model)
{
// Set the property list
if (model->getPropertySet())
{
d_ptr->Properties = model->getPropertySet()->getRootProperties();
}
// Connect signals // todo: more signals neccesary!!!
connect(model, SIGNAL(destroyed()), this, SLOT(modelDestroyed()));
connect(model, SIGNAL(rowsInserted(const QModelIndex&, int, int)), this, SLOT(rowsInserted(QModelIndex,int,int)));
connect(model, SIGNAL(rowsInserted(const QModelIndex&, int, int)), this,
SLOT(rowsInserted(QModelIndex, int, int)));
connect(model, SIGNAL(modelReset()), this, SLOT(modelReset()));
connect(model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), this, SLOT(rowsRemoved(QModelIndex,int,int)));
connect(model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), this,
SLOT(rowsRemoved(QModelIndex, int, int)));
}
// Build the widget
@ -90,7 +95,8 @@ void VPropertyFormView::setPropertySet(VPropertySet* property_set)
// Set property set
static_cast<VPropertyFormViewPrivate*>(d_ptr)->PropertySet = property_set;
if(property_set) {
if (property_set)
{
// Set the property list
d_ptr->Properties = property_set->getRootProperties();
}
@ -131,7 +137,9 @@ void VPropertyFormView::modelDestroyed()
void VPropertyFormView::dataChanged(const QModelIndex &top_left, const QModelIndex &bottom_right)
{
if (static_cast<VPropertyFormViewPrivate*>(d_ptr)->IgnoreDataChangedSignal)
{
return;
}
// todo: handle data changes
}
@ -139,7 +147,8 @@ void VPropertyFormView::dataSubmitted(VProperty *property)
{
VPropertyModel* tmpModel = static_cast<VPropertyFormViewPrivate*>(d_ptr)->Model;
if(tmpModel && d_ptr->UpdateEditors) {
if (tmpModel && d_ptr->UpdateEditors)
{
static_cast<VPropertyFormViewPrivate*>(d_ptr)->IgnoreDataChangedSignal = true;
tmpModel->onDataChangedByModel(property);
static_cast<VPropertyFormViewPrivate*>(d_ptr)->IgnoreDataChangedSignal = false;
@ -150,7 +159,9 @@ void VPropertyFormView::showEvent(QShowEvent *event)
{
Q_UNUSED(event)
if (static_cast<VPropertyFormViewPrivate*>(d_ptr)->NeedsRebuild)
{
build();
}
static_cast<VPropertyFormViewPrivate*>(d_ptr)->NeedsRebuild = false;
}
@ -160,21 +171,28 @@ void VPropertyFormView::updatePropertyList()
VPropertySet* tmpSet = static_cast<VPropertyFormViewPrivate*>(d_ptr)->PropertySet;
if (tmpModel && tmpModel->getPropertySet())
{
d_ptr->Properties = tmpModel->getPropertySet()->getRootProperties();
}
else if (tmpSet)
{
d_ptr->Properties = tmpSet->getRootProperties();
}
else
d_ptr->Properties.clear();
if (isVisible())
{
build();
}
else
static_cast<VPropertyFormViewPrivate*>(d_ptr)->NeedsRebuild = true;
}
void VPropertyFormView::removeModelAndSet()
{
if(static_cast<VPropertyFormViewPrivate*>(d_ptr)->Model) {
if (static_cast<VPropertyFormViewPrivate*>(d_ptr)->Model)
{
disconnect(static_cast<VPropertyFormViewPrivate*>(d_ptr)->Model, 0, this, 0);
static_cast<VPropertyFormViewPrivate*>(d_ptr)->Model = nullptr;
}
@ -187,13 +205,16 @@ void VPropertyFormView::removeModelAndSet()
void VPropertyFormView::connectPropertyFormWidget(VPropertyFormWidget *widget)
{
if (!widget)
{
return;
}
connect(widget, &VPropertyFormWidget::propertyDataSubmitted, this, &VPropertyFormView::dataSubmitted,
Qt::UniqueConnection);
QList<VPropertyFormWidget*> tmpList = widget->getChildPropertyFormWidgets();
foreach(VPropertyFormWidget* tmpEditorWidget, tmpList) {
foreach(VPropertyFormWidget* tmpEditorWidget, tmpList)
{
connectPropertyFormWidget(tmpEditorWidget);
}
}

View File

@ -25,7 +25,8 @@
#include <QPointer>
#include "vpropertyformwidget.h"
namespace VPE {
namespace VPE
{
class VProperty;
class VPropertyModel;
@ -57,7 +58,8 @@ public slots:
//! \param model The model to use
void setModel(VPropertyModel* model);
//! Set the property set to use. Note that if using a property set directly, adding and removing properties to the property set leads to undifined behaviour for the property set misses notification signals.
//! Set the property set to use. Note that if using a property set directly, adding and removing properties to the
//! property set leads to undifined behaviour for the property set misses notification signals.
//! \param model The property set to use
void setPropertySet(VPropertySet* property_set);

View File

@ -25,7 +25,8 @@
#include "vpropertyformwidget_p.h"
namespace VPE {
namespace VPE
{
class VPropertyModel;
class VPropertySet;

View File

@ -31,7 +31,8 @@
using namespace VPE;
VPropertyFormWidget::VPropertyFormWidget(const QString &title, const QString &description, const QList<VProperty*>& properties, QWidget *parent)
VPropertyFormWidget::VPropertyFormWidget(const QString &title, const QString &description,
const QList<VProperty*>& properties, QWidget *parent)
: QGroupBox(title, parent), d_ptr(new VPropertyFormWidgetPrivate(properties))
{
build();
@ -42,7 +43,8 @@ VPropertyFormWidget::VPropertyFormWidget(const QString &title, const QString &de
VPropertyFormWidget::VPropertyFormWidget(VProperty *parent_property, QWidget *parent)
: QGroupBox(parent), d_ptr(new VPropertyFormWidgetPrivate())
{
if(parent_property) {
if (parent_property)
{
d_ptr->Properties = parent_property->getChildren();
build();
setTitle(parent_property->getName());
@ -51,7 +53,8 @@ VPropertyFormWidget::VPropertyFormWidget(VProperty *parent_property, QWidget *pa
}
}
VPropertyFormWidget::VPropertyFormWidget(VPropertyFormWidgetPrivate *d_pointer, QWidget *parent, const QString &title, const QString &description)
VPropertyFormWidget::VPropertyFormWidget(VPropertyFormWidgetPrivate *d_pointer, QWidget *parent, const QString &title,
const QString &description)
: QGroupBox(title, parent), d_ptr(d_pointer)
{
build();
@ -69,28 +72,40 @@ void VPropertyFormWidget::build()
{
// Clear the old content, delete old widgets
d_ptr->EditorWidgets.clear();
if(layout()) {
if (layout())
{
QLayoutItem *child;
while (layout()->count() > 0 && (child = layout()->takeAt(0)) != 0) {
while (layout()->count() > 0 && (child = layout()->takeAt(0)) != 0)
{
if (child->widget())
{
delete child->widget();
}
delete child;
}
delete layout();
}
// Create new content
if(d_ptr->Properties.isEmpty()) return; //... only if there are properties
if (d_ptr->Properties.isEmpty())
{
return; //... only if there are properties
}
QFormLayout* tmpFormLayout = new QFormLayout(this);
setLayout(tmpFormLayout);
for(int i = 0; i < d_ptr->Properties.count(); ++i) {
for (int i = 0; i < d_ptr->Properties.count(); ++i)
{
// Get the current property
VProperty* tmpProperty = d_ptr->Properties.value(i, nullptr);
if(!tmpProperty) continue;
if (!tmpProperty)
{
continue;
}
if(tmpProperty->getRowCount() > 0) {
if (tmpProperty->getRowCount() > 0)
{
if (tmpProperty->propertyType() == Property::Complex)
{
buildEditor(tmpProperty, tmpFormLayout, Property::Complex);
@ -122,11 +137,15 @@ void VPropertyFormWidget::build()
d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpNewFormWidget));
tmpNewFormWidget->setCommitBehaviour(d_ptr->UpdateEditors);
}
} else if(tmpProperty->type() == "widget") {
}
else if (tmpProperty->type() == "widget")
{
VWidgetProperty* tmpWidgetProperty = static_cast<VWidgetProperty*>(tmpProperty);
tmpFormLayout->addRow(tmpWidgetProperty->getWidget());
d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpWidgetProperty->getWidget()));
} else {
}
else
{
buildEditor(tmpProperty, tmpFormLayout);
}
}
@ -138,7 +157,9 @@ void VPropertyFormWidget::buildEditor(VProperty* property, QFormLayout* formLayo
// Create the editor (if it doesn't work, create empty widget)
QWidget* tmpEditor = property->createEditor(this, QStyleOptionViewItem(), nullptr);
if (!tmpEditor)
{
tmpEditor = new QWidget(this);
}
// set tooltip and whats this
tmpEditor->setToolTip(property->getDescription());
@ -167,23 +188,32 @@ void VPropertyFormWidget::buildEditor(VProperty* property, QFormLayout* formLayo
void VPropertyFormWidget::commitData()
{
for (int i = 0; i < d_ptr->Properties.count(); ++i)
{
commitData(i);
}
}
void VPropertyFormWidget::loadData()
{
for (int i = 0; i < d_ptr->Properties.count(); ++i)
{
loadData(i);
}
}
void VPropertyFormWidget::commitData(int row)
{
if(row < 0 || row >= d_ptr->EditorWidgets.count() || row >= d_ptr->Properties.count()) return;
if (row < 0 || row >= d_ptr->EditorWidgets.count() || row >= d_ptr->Properties.count())
{
return;
}
VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget = d_ptr->EditorWidgets[row];
VProperty* tmpProperty = d_ptr->Properties[row];
if (tmpEditorWidget.FormWidget)
{
tmpEditorWidget.FormWidget->commitData();
}
else if (tmpEditorWidget.Editor && tmpProperty)
{
QVariant newValue = tmpProperty->getEditorData(tmpEditorWidget.Editor);
@ -212,13 +242,19 @@ void VPropertyFormWidget::commitData(int row)
void VPropertyFormWidget::loadData(int row)
{
if(row < 0 || row >= d_ptr->EditorWidgets.count() || row >= d_ptr->Properties.count()) return;
if (row < 0 || row >= d_ptr->EditorWidgets.count() || row >= d_ptr->Properties.count())
{
return;
}
VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget = d_ptr->EditorWidgets[row];
VProperty* tmpProperty = d_ptr->Properties[row];
if (tmpEditorWidget.FormWidget)
{
tmpEditorWidget.FormWidget->loadData();
else if(tmpEditorWidget.Editor && tmpProperty) {
}
else if (tmpEditorWidget.Editor && tmpProperty)
{
tmpProperty->setEditorData(tmpEditorWidget.Editor);
}
}
@ -228,19 +264,25 @@ void VPropertyFormWidget::setCommitBehaviour(bool auto_commit)
d_ptr->UpdateEditors = auto_commit;
QList<VPropertyFormWidget*> tmpChildFormWidgets = getChildPropertyFormWidgets();
foreach(VPropertyFormWidget* tmpChild, tmpChildFormWidgets) {
foreach(VPropertyFormWidget* tmpChild, tmpChildFormWidgets)
{
if (tmpChild)
{
tmpChild->setCommitBehaviour(auto_commit);
}
}
}
QList<VPropertyFormWidget *> VPropertyFormWidget::getChildPropertyFormWidgets() const
{
QList<VPropertyFormWidget *> tmpResult;
foreach(const VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget, d_ptr->EditorWidgets) {
foreach(const VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget, d_ptr->EditorWidgets)
{
if (tmpEditorWidget.FormWidget)
{
tmpResult.append(tmpEditorWidget.FormWidget);
}
}
return tmpResult;
}
@ -248,14 +290,20 @@ QList<VPropertyFormWidget *> VPropertyFormWidget::getChildPropertyFormWidgets()
bool VPropertyFormWidget::eventFilter(QObject *object, QEvent *event)
{
if (!d_ptr->UpdateEditors)
{
return false;
}
QWidget* editor = qobject_cast<QWidget*>(object);
if (!editor)
{
return false;
}
if (event->type() == QEvent::KeyPress) {
switch (static_cast<QKeyEvent *>(event)->key()) {
if (event->type() == QEvent::KeyPress)
{
switch (static_cast<QKeyEvent *>(event)->key())
{
case Qt::Key_Tab:
case Qt::Key_Backtab:
case Qt::Key_Enter:
@ -267,16 +315,23 @@ bool VPropertyFormWidget::eventFilter(QObject *object, QEvent *event)
default:
return false;
}
} else if (event->type() == QEvent::FocusOut || (event->type() == QEvent::Hide && editor->isWindow())) {
}
else if (event->type() == QEvent::FocusOut || (event->type() == QEvent::Hide && editor->isWindow()))
{
commitData(editor);
return false;
} else if (event->type() == QEvent::ShortcutOverride) {
if (static_cast<QKeyEvent*>(event)->key() == Qt::Key_Escape) {
}
else if (event->type() == QEvent::ShortcutOverride)
{
if (static_cast<QKeyEvent*>(event)->key() == Qt::Key_Escape)
{
commitData(editor);
event->accept();
return true;
}
} else if (event->type() == MyCustomEventType) {
}
else if (event->type() == MyCustomEventType)
{
commitData(editor);
event->accept();
return true;
@ -293,11 +348,16 @@ bool VPropertyFormWidget::eventFilter(QObject *object, QEvent *event)
void VPropertyFormWidget::commitData(QWidget *editor)
{
if (!editor)
{
return;
}
for(int i = 0; i < d_ptr->EditorWidgets.count(); ++i) {
for (int i = 0; i < d_ptr->EditorWidgets.count(); ++i)
{
VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget = d_ptr->EditorWidgets[i];
if (tmpEditorWidget.Editor == editor)
{
commitData(i);
}
}
}

View File

@ -27,7 +27,8 @@
class QFormLayout;
namespace VPE {
namespace VPE
{
class VPropertyFormWidgetPrivate;
class VPropertySet;
@ -38,7 +39,8 @@ class VPROPERTYEXPLORERSHARED_EXPORT VPropertyFormWidget : public QGroupBox
Q_OBJECT
public:
//! Constructor
VPropertyFormWidget(const QString& title, const QString& description, const QList<VProperty*>& properties, QWidget* parent);
VPropertyFormWidget(const QString& title, const QString& description, const QList<VProperty*>& properties,
QWidget* parent);
//! Constructor
VPropertyFormWidget(VProperty* parent_property, QWidget* parent);
@ -69,7 +71,8 @@ public slots:
void loadData(int row);
//! Sets the update behaviour
//! \param auto_commit If set to true, whenever an event like focusOut is triggered on an editor, the data will be submitted to the property.
//! \param auto_commit If set to true, whenever an event like focusOut is triggered on an editor, the data will be
//! submitted to the property.
void setCommitBehaviour(bool auto_commit = true);
signals:

View File

@ -26,12 +26,15 @@
#include <QList>
#include "vproperty.h"
namespace VPE {
namespace VPE
{
class VPropertyFormWidgetPrivate {
class VPropertyFormWidgetPrivate
{
public:
//! Stores either another VPropertyFormWidget (then Editor is null) or an editor widget (then FormWidget is null)
struct SEditorWidget {
struct SEditorWidget
{
SEditorWidget() : FormWidget(nullptr), Editor(nullptr) {}
SEditorWidget(VPropertyFormWidget* form_widget) : FormWidget(form_widget), Editor(nullptr) {}
SEditorWidget(QWidget* editor_widget) : FormWidget(nullptr), Editor(editor_widget) {}
@ -46,7 +49,8 @@ public:
//! Binds the properties to their editors
QList<SEditorWidget> EditorWidgets;
//! Determines the behaviour of the editors. If this is true, when a focus out event etc. happens, the data will be submitted to the VProperty. If false, you will have to call commitData() yourself.
//! Determines the behaviour of the editors. If this is true, when a focus out event etc. happens, the data will be
//! submitted to the VProperty. If false, you will have to call commitData() yourself.
bool UpdateEditors;
//! Default constructor

View File

@ -41,7 +41,9 @@ VPropertyModel::VPropertyModel(QObject * parent) :
VPropertyModel::~VPropertyModel()
{
if (d_ptr->Properties)
{
delete d_ptr->Properties;
}
delete d_ptr;
}
@ -50,12 +52,17 @@ VPropertyModel::~VPropertyModel()
bool VPropertyModel::addProperty(VProperty* property, const QString& id, const QString &parentid, bool emitsignals)
{
if (!property)
{
return false;
}
if (!d_ptr->Properties) // If not existant, create property set
{
d_ptr->Properties = new VPropertySet();
}
if(emitsignals) {
if (emitsignals)
{
VProperty* tmpParent = getProperty(parentid);
int tmpRow = tmpParent != nullptr ? tmpParent->getRowCount() : d_ptr->Properties->getRootPropertyCount();
beginInsertRows((tmpParent != nullptr ? getIndexFromProperty(tmpParent) : QModelIndex()), tmpRow, tmpRow);
@ -64,19 +71,24 @@ bool VPropertyModel::addProperty(VProperty* property, const QString& id, const Q
d_ptr->Properties->addProperty(property, id, parentid);
if (emitsignals)
{
endInsertRows();
}
return true;
}
//! Creates a property and adds it to the model
VProperty* VPropertyModel::createProperty(const QString& id, const QString& name, const QString& parentid, const QVariant& data)
VProperty* VPropertyModel::createProperty(const QString& id, const QString& name, const QString& parentid,
const QVariant& data)
{
VProperty* tmpProp = new VProperty(name);
tmpProp->setValue(data);
if (tmpProp && addProperty(tmpProp, id, parentid))
{
return tmpProp;
}
else
return nullptr;
}
@ -87,23 +99,29 @@ VProperty* VPropertyModel::getProperty(const QString& id)
return d_ptr->Properties != nullptr ? d_ptr->Properties->getProperty(id) : nullptr;
}
//! Returns the model index at row/column
QModelIndex VPropertyModel::index(int row, int column, const QModelIndex& parent) const
{
if (d_ptr->Properties == nullptr || (parent.isValid() && parent.column() > 1))
{
return QModelIndex();
}
if(parent.isValid()) {
if (parent.isValid())
{
// Get the parent index
VProperty* parentItem = getProperty(parent);
if(parentItem) {
if (parentItem)
{
VProperty* childItem = parentItem->getChild(row);
if (childItem)
{
return createIndex(row, column, childItem);
}
} else if(row >= 0 && row < d_ptr->Properties->count()) {
}
}
else if (row >= 0 && row < d_ptr->Properties->count())
{
return createIndex(row, column, d_ptr->Properties->getRootProperty(row));
}
@ -114,19 +132,26 @@ QModelIndex VPropertyModel::index(int row, int column, const QModelIndex& parent
QModelIndex VPropertyModel::parent ( const QModelIndex & index ) const
{
if (!index.isValid())
{
return QModelIndex();
}
VProperty* childItem = getProperty(index);
if(childItem) {
if (childItem)
{
VProperty* parentItem = childItem->getParent();
if(parentItem) {
if (parentItem)
{
VProperty* grandParentItem = parentItem->getParent();
int parents_row = grandParentItem != nullptr ? grandParentItem->getChildRow(parentItem) : d_ptr->Properties->getRootProperties().indexOf(parentItem);
int parents_row = grandParentItem != nullptr ? grandParentItem->getChildRow(parentItem)
: d_ptr->Properties->getRootProperties().indexOf(parentItem);
if (parents_row >= 0)
{
return createIndex(parents_row, 0, parentItem);
}
}
}
return QModelIndex();
}
@ -136,7 +161,9 @@ Qt::ItemFlags VPropertyModel::flags (const QModelIndex& index) const
{
VProperty* tmpProperty = getProperty(index);
if (!tmpProperty)
{
return Qt::NoItemFlags;
}
else
return tmpProperty->flags(index.column());
}
@ -145,16 +172,20 @@ Qt::ItemFlags VPropertyModel::flags (const QModelIndex& index) const
bool VPropertyModel::setData (const QModelIndex& index, const QVariant& value, int role)
{
VProperty* tmpProperty = getProperty(index);
if(index.column() == 1 && tmpProperty) {
if (index.column() == 1 && tmpProperty)
{
bool tmpHasChanged = tmpProperty->setData(value, role);
if(tmpProperty->getUpdateParent() && tmpHasChanged) { // If neccessary, update the parent as well
if (tmpProperty->getUpdateParent() && tmpHasChanged)
{ // If neccessary, update the parent as well
QModelIndex tmpParentIndex = parent(index);
emit dataChanged(tmpParentIndex, tmpParentIndex);
}
if (tmpHasChanged)
{
emit onDataChangedByEditor(tmpProperty);
}
}
return true;
@ -166,7 +197,9 @@ QVariant VPropertyModel::data ( const QModelIndex & index, int role ) const
{
VProperty* tmpProperty = getProperty(index);
if (!tmpProperty)
{
return QVariant();
}
else
return tmpProperty->data(index.column(), role);
}
@ -174,13 +207,22 @@ QVariant VPropertyModel::data ( const QModelIndex & index, int role ) const
QVariant VPropertyModel::headerData (int section, Qt::Orientation orientation, int role) const
{
if(orientation == Qt::Horizontal && role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
// Header data
if (section == 0) return d_ptr->HeadlineProperty;
else if (section == 1) return d_ptr->HeadlineValue;
if (section == 0)
{
return d_ptr->HeadlineProperty;
}
else if (section == 1)
{
return d_ptr->HeadlineValue;
}
}
else if (role == Qt::DisplayRole)
{
return QVariant(section);
}
return QVariant();
}
@ -189,15 +231,20 @@ QVariant VPropertyModel::headerData (int section, Qt::Orientation orientation, i
//! Returns the number of rows
int VPropertyModel::rowCount ( const QModelIndex & parent ) const
{
if(parent.isValid()) {
if (parent.isValid())
{
VProperty* tmpParent = getProperty(parent);
if (tmpParent)
{
return tmpParent->getRowCount();
}
}
// Return the root property count
if (d_ptr->Properties)
{
return d_ptr->Properties->getRootPropertyCount();
}
return 0;
}
@ -214,12 +261,15 @@ int VPropertyModel::columnCount ( const QModelIndex & parent) const
//! Gets a property by its ModelIndex
VProperty* VPropertyModel::getProperty(const QModelIndex &index) const
{
if (index.isValid()) {
if (index.isValid())
{
VProperty* prop = static_cast<VProperty*>(index.internalPointer());
if (prop)
{
return prop;
}
}
return nullptr;
}
@ -231,12 +281,15 @@ QString VPropertyModel::getPropertyID(VProperty *prop) const
QModelIndex VPropertyModel::getIndexFromProperty(VProperty* property, int column) const
{
if (!property || column > columnCount() || column < 0)
{
return QModelIndex();
}
VProperty* parentItem = property->getParent();
int row = 0;
if(parentItem) {
if (parentItem)
{
row = parentItem->getChildRow(property);
}
@ -268,9 +321,15 @@ VPropertySet *VPropertyModel::takePropertySet(VPropertySet *new_property_set, bo
{
VPropertySet* tmpOldPropertySet = d_ptr->Properties;
if(emit_signals) emit beginResetModel();
if (emit_signals)
{
emit beginResetModel();
}
d_ptr->Properties = new_property_set;
if(emit_signals) emit endResetModel();
if (emit_signals)
{
emit endResetModel();
}
return tmpOldPropertySet;
}
@ -279,13 +338,16 @@ void VPropertyModel::setPropertySet(VPropertySet *property_set, bool emit_signal
{
VPropertySet* tmpOldPropertySet = takePropertySet(property_set, emit_signals);
if (tmpOldPropertySet)
{
delete tmpOldPropertySet;
}
}
VProperty *VPropertyModel::takeProperty(const QString &id)
{
QModelIndex tmpIndex = getIndexFromProperty(getProperty(id));
if(d_ptr->Properties && tmpIndex.isValid()) {
if (d_ptr->Properties && tmpIndex.isValid())
{
beginRemoveRows(tmpIndex.parent(), tmpIndex.row(), tmpIndex.row());
VProperty* tmpProp = d_ptr->Properties->takeProperty(id);
endRemoveRows();
@ -298,7 +360,8 @@ VProperty *VPropertyModel::takeProperty(const QString &id)
void VPropertyModel::removeProperty(const QString &id)
{
QModelIndex tmpIndex = getIndexFromProperty(getProperty(id));
if(d_ptr->Properties && tmpIndex.isValid()) {
if (d_ptr->Properties && tmpIndex.isValid())
{
beginRemoveRows(tmpIndex.parent(), tmpIndex.row(), tmpIndex.row());
d_ptr->Properties->removeProperty(id);
endRemoveRows();

View File

@ -29,7 +29,8 @@
#include "vproperty.h"
namespace VPE {
namespace VPE
{
class VPropertyModelPrivate;
class VPropertySet;
@ -61,7 +62,8 @@ public:
virtual ~VPropertyModel();
//! Adds the property to the model and attaches it to the parentid
//! \param emitsignals If this is set to false, this function will not call beginInsertRows() and endInsertRows(), so it has to be called from a subclass
//! \param emitsignals If this is set to false, this function will not call beginInsertRows() and endInsertRows(),
//! so it has to be called from a subclass
virtual bool addProperty(VProperty* property, const QString& id, const QString& parentid = QString(),
bool emitsignals = true);
@ -96,8 +98,6 @@ public:
//! Returns the number of columns
virtual int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
//! Gets a property by its ModelIndex
//! \param index The modelIndex of the property.
//! \return Returns the property with the given index, or NULL if none such property exists
@ -110,23 +110,29 @@ public:
//! \return Returns the ID under which the property is stored within the model
virtual QString getPropertyID(VProperty* prop) const;
//! Returns a const pointer to the property set managed by this model. If you want to manipulate the property set, either use the methods provided by the model or use takePropertySet() and setPropertySet().
//! Returns a const pointer to the property set managed by this model. If you want to manipulate the property set,
//! either use the methods provided by the model or use takePropertySet() and setPropertySet().
//! \return A constant pointer to the property set or NULL if there currently is none.
virtual const VPropertySet* getPropertySet() const;
//! Clears the model, deletes the property set managed by this model.
//! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset model signals
//! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset
//! model signals
virtual void clear(bool emit_signals = true);
//! Removes the current property set and returns it. If new_property_set is set, the old one will be replaced by the new one
//! Removes the current property set and returns it. If new_property_set is set, the old one will be replaced by the
//! new one
//! \param new_property_set The new property set to replace the old one with. Default: NULL
//! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset model signals
//! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset
//! model signals
//! \return A constant pointer to the property set or NULL if there currently is none.
virtual VPropertySet* takePropertySet(VPropertySet* new_property_set = nullptr, bool emit_signals = true);
//! Sets a new property set. The model will take ownership of the property set. The old property set will be deleted.
//! Sets a new property set. The model will take ownership of the property set. The old property set will be
//! deleted.
//! \param property_set The new property set. Setting this to NULL has the same effect as calling clear.
//! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset model signals
//! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset
//! model signals
//! \return A constant pointer to the property set or NULL if there currently is none.
virtual void setPropertySet(VPropertySet* property_set, bool emit_signals = true);

View File

@ -27,12 +27,14 @@
#include <QString>
#include <QObject>
namespace VPE {
namespace VPE
{
class VProperty;
class VPropertySet;
class VPropertyModelPrivate {
class VPropertyModelPrivate
{
public:
//! The property set holding the properties
VPropertySet* Properties;

View File

@ -42,7 +42,9 @@ bool VPropertySet::addProperty(VProperty *property, const QString &id, const QSt
{
// Check if the property to add is not a null pointer
if (!property)
{
return false;
}
VProperty* tmpParent = parentid.isEmpty() ? NULL : getProperty(parentid);
return addProperty(property, id, tmpParent);
@ -52,22 +54,33 @@ bool VPropertySet::addProperty(VProperty *property, const QString &id, VProperty
{
// Check if the property to add is not a null pointer
if (!property)
{
return false;
}
QString tmpOldID = getPropertyID(property);
if (!tmpOldID.isEmpty())
{
d_ptr->Properties.remove(tmpOldID);
}
if (parent_property)
{
parent_property->addChild(property);
else {
}
else
{
d_ptr->RootProperties.append(property);
if (property->getParent())
{
property->getParent()->removeChild(property);
}
}
if (!id.isEmpty())
{
d_ptr->Properties.insert(id, property);
}
return true;
}
@ -75,7 +88,9 @@ bool VPropertySet::addProperty(VProperty *property, const QString &id, VProperty
bool VPropertySet::hasProperty(VProperty *property) const
{
if (!property)
{
return false;
}
return hasProperty(property, NULL);
}
@ -98,8 +113,10 @@ void VPropertySet::removeProperty(const QString &id)
{
VProperty* tmpProp = takeProperty(id);
if (tmpProp)
{
delete tmpProp;
}
}
void VPropertySet::removeProperty(VProperty* prop, bool delete_property)
{
@ -107,13 +124,16 @@ void VPropertySet::removeProperty(VProperty* prop, bool delete_property)
removePropertyFromSet(prop);
// Remove from parent and optionally delete
if(prop) {
if (prop)
{
prop->setParent(NULL);
if (delete_property)
{
delete prop;
}
}
}
int VPropertySet::count() const
{
@ -123,9 +143,11 @@ int VPropertySet::count() const
void VPropertySet::clear(bool delete_properties)
{
d_ptr->Properties.clear();
while(!d_ptr->RootProperties.isEmpty()) {
while (!d_ptr->RootProperties.isEmpty())
{
VProperty* tmpProp = d_ptr->RootProperties.takeLast();
if(tmpProp != nullptr && delete_properties) {
if (tmpProp != nullptr && delete_properties)
{
delete tmpProp;
}
}
@ -136,16 +158,21 @@ QString VPropertySet::getPropertyID(const VProperty *prop, bool look_for_parent_
QString tmpResult;
const VProperty* tmpCurrentProp = prop;
while(tmpCurrentProp && (look_for_parent_id || prop == tmpCurrentProp) && tmpResult.isEmpty()) {
while (tmpCurrentProp && (look_for_parent_id || prop == tmpCurrentProp) && tmpResult.isEmpty())
{
// todo: The following code doesn't work, because .key() doesn't accept a const VProperty* pointer ...
//tmpResult = d_ptr->Properties.key(tmpCurrentProp, QString());
// ... which is why we need the code below
for (QMap<QString, VProperty*>::const_iterator i = d_ptr->Properties.constBegin(); i != d_ptr->Properties.constEnd(); ++i) {
for (QMap<QString, VProperty*>::const_iterator i = d_ptr->Properties.constBegin();
i != d_ptr->Properties.constEnd(); ++i)
{
if (tmpCurrentProp == (*i))
{
return i.key();
}
}
tmpCurrentProp = tmpCurrentProp->getParent();
}
@ -184,36 +211,48 @@ VPropertySet* VPropertySet::clone() const
return tmpResult;
}
bool VPropertySet::hasProperty(VProperty *property, VProperty *parent) const
{
if (!property)
{
return false;
}
const QList<VProperty*>& tmpChildrenList = (parent != NULL ? parent->getChildren() : d_ptr->RootProperties);
foreach(VProperty* tmpProp, tmpChildrenList) {
foreach(VProperty* tmpProp, tmpChildrenList)
{
if (!tmpProp)
{
continue;
}
else if (tmpProp == property || hasProperty(property, tmpProp))
{
return true;
}
}
return false;
}
void VPropertySet::cloneProperty(VProperty* property_to_clone, VProperty *parent_property, VPropertySet *output_set) const
void VPropertySet::cloneProperty(VProperty* property_to_clone, VProperty *parent_property,
VPropertySet *output_set) const
{
if (!output_set || !property_to_clone || !hasProperty(property_to_clone))
{
return;
}
QString tmpID = getPropertyID(property_to_clone, false);
VProperty* tmpNewProperty = property_to_clone->clone(false); // We want to clone the children ourselves (because of the IDs)
// We want to clone the children ourselves (because of the IDs)
VProperty* tmpNewProperty = property_to_clone->clone(false);
output_set->addProperty(tmpNewProperty, tmpID, parent_property);
for (int i = 0; i < property_to_clone->getRowCount(); ++i)
{
cloneProperty(property_to_clone->getChild(i), tmpNewProperty, output_set);
}
}
void VPropertySet::removePropertyFromSet(VProperty *prop)
{

View File

@ -28,7 +28,8 @@
#include "vproperty.h"
namespace VPE {
namespace VPE
{
// Forward declaration
class VPropertySetPrivate;
@ -49,15 +50,19 @@ public:
//! Destructor
virtual ~VPropertySet();
//! Adds the property to the model and attaches it to the parentid. Note that if the property has a parent which is not part of this set, it will be removed from that parent.
//! Adds the property to the model and attaches it to the parentid. Note that if the property has a parent which is
//! not part of this set, it will be removed from that parent.
//! \param property The property to add
//! \param id The property ID. If id is empty, the property will not be accessable by it's id but still be added. If the property was filed under another ID before, that will no longer be valid.
//! \param parentid The property's ID to which to add the property as child. Pass empty string to add it to the root properties.
//! \param id The property ID. If id is empty, the property will not be accessable by it's id but still be added.
//! If the property was filed under another ID before, that will no longer be valid.
//! \param parentid The property's ID to which to add the property as child. Pass empty string to add it to the
//! root properties.
virtual bool addProperty(VProperty* property, const QString& id, const QString& parentid);
//! Adds the property to the model and attaches it to the parent property.
//! \param property The property to add
//! \param id The property ID. If id is empty, the property will not be accessable by it's id but still be added. If the property was filed under another ID before, that will no longer be valid.
//! \param id The property ID. If id is empty, the property will not be accessable by it's id but still be added.
//! If the property was filed under another ID before, that will no longer be valid.
//! \param parentid The property to which to add the property as child. Pass NULL to add it to the root properties.
virtual bool addProperty(VProperty* property, const QString& id, VProperty* parent_property = nullptr);

View File

@ -26,14 +26,17 @@
#include <QMap>
#include <QString>
namespace VPE {
namespace VPE
{
class VProperty;
class VPropertySetPrivate {
class VPropertySetPrivate
{
public:
//! Property map (ID, Property)
QMap<QString, VProperty*> Properties; // All the Properties managed by this model are being stored in this map for quick access
QMap<QString, VProperty*> Properties; // All the Properties managed by this model are being stored in this map for
//quick access
//! List containing the root properties
QList<VProperty*> RootProperties;

View File

@ -39,15 +39,19 @@ VPropertyTreeView::VPropertyTreeView(VPropertyModel *model, QWidget *parent)
init();
if (model)
{
setModel(model);
}
}
VPropertyTreeView::VPropertyTreeView(VPropertyTreeViewPrivate *d, bool init_, QWidget *parent)
: QTreeView(parent), d_ptr(d)
{
if (init_)
{
init();
}
}
VPropertyTreeView::~VPropertyTreeView()
{
@ -73,5 +77,3 @@ void VPropertyTreeView::init()
setEditTriggers(QAbstractItemView::CurrentChanged | QAbstractItemView::SelectedClicked);
}

View File

@ -24,7 +24,8 @@
#include <QTreeView>
#include "vpropertyexplorer_global.h"
namespace VPE {
namespace VPE
{
class VPropertyTreeViewPrivate;

View File

@ -26,7 +26,8 @@
#include <QMap>
#include <QString>
namespace VPE {
namespace VPE
{
class VPropertyDelegate;

View File

@ -33,7 +33,8 @@ VSerializedProperty::VSerializedProperty()
VSerializedProperty::VSerializedProperty(const VProperty* property, const VPropertySet* set)
: ID(), Type(property ? property->type() : QString()), Value(property ? property->getValue() : QVariant())
{
if(set) {
if (set)
{
ID = set->getPropertyID(property);
initChildren(property, set);
@ -58,12 +59,13 @@ VPE::VSerializedProperty::~VSerializedProperty()
void VSerializedProperty::initChildren(const VProperty *property, const VPropertySet *set)
{
if(property && set) {
if (property && set)
{
const QList<VProperty*>& tmpChildren = property->getChildren();
foreach(const VProperty* tmpChild, tmpChildren) {
foreach(const VProperty* tmpChild, tmpChildren)
{
QString tmpChildID = set->getPropertyID(property);
Children.append(VSerializedProperty(tmpChild, tmpChildID, set));
}
}
}

View File

@ -30,7 +30,8 @@
#include "vproperty.h"
#include "vpropertyset.h"
namespace VPE {
namespace VPE
{
class VPROPERTYEXPLORERSHARED_EXPORT VSerializedProperty

View File

@ -44,7 +44,8 @@ VStandardPropertyFactory::VStandardPropertyFactory()
VStandardPropertyFactory::VStandardPropertyFactory(VPropertyFactoryManager *manager)
: VAbstractPropertyFactory()
{
if(manager) {
if (manager)
{
manager->registerFactory("string", this);
manager->registerFactory("bool", this);
manager->registerFactory("color", this);
@ -60,25 +61,44 @@ VStandardPropertyFactory::VStandardPropertyFactory(VPropertyFactoryManager *mana
VProperty *VStandardPropertyFactory::createProperty(const QString &type, const QString &name)
{
if(type == QString("string")) {
if (type == QString("string"))
{
return new VProperty(name);
} else if(type == QString("bool")) {
}
else if (type == QString("bool"))
{
return new VBoolProperty(name);
} else if(type == QString("color")) {
}
else if (type == QString("color"))
{
return new VColorProperty(name);
} else if(type == QString("empty")) {
}
else if (type == QString("empty"))
{
return new VEmptyProperty(name);
} else if(type == QString("enum")) {
}
else if (type == QString("enum"))
{
return new VEnumProperty(name);
} else if(type == QString("file")) {
}
else if (type == QString("file"))
{
return new VFileProperty(name);
} else if(type == QString("integer")) {
}
else if (type == QString("integer"))
{
return new VIntegerProperty(name);
} else if(type == QString("double")) {
}
else if (type == QString("double"))
{
return new VDoubleProperty(name);
} else if(type == QString("shortcut")) {
}
else if (type == QString("shortcut"))
{
return new VShortcutProperty(name);
} else if(type == QString("vector3d")) {
}
else if (type == QString("vector3d"))
{
return new QVector3DProperty(name);
}
else

View File

@ -24,7 +24,8 @@
#include "vpropertyexplorer_global.h"
#include "vabstractpropertyfactory.h"
namespace VPE {
namespace VPE
{
class VProperty;

View File

@ -28,9 +28,11 @@
#include <QPointer>
#include <QWidget>
namespace VPE {
namespace VPE
{
class VWidgetPropertyPrivate : public VPropertyPrivate {
class VWidgetPropertyPrivate : public VPropertyPrivate
{
public:
//! The widget to show
QPointer<QWidget> Widget;
@ -44,10 +46,13 @@ public:
: VPropertyPrivate(), Widget(nullptr) {}
//! Destructor
~VWidgetPropertyPrivate() {
~VWidgetPropertyPrivate()
{
if (Widget)
{
Widget->deleteLater();
}
}
};
}