Fix calling multiple time slot VPropertyFormView::dataSubmitted.

--HG--
branch : feature
This commit is contained in:
dismine 2014-08-28 11:17:36 +03:00
parent c48c627682
commit a8a99febf4
9 changed files with 84 additions and 40 deletions

View File

@ -35,6 +35,7 @@
#include "../libs/vpropertyexplorer/plugins/vnumberproperty.h"
#include "../libs/vpropertyexplorer/plugins/vstringproperty.h"
#include "../libs/vpropertyexplorer/plugins/vpointfproperty.h"
#include "../libs/vpropertyexplorer/plugins/venumproperty.h"
#include <QDockWidget>
#include <QHBoxLayout>
@ -138,6 +139,10 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property)
{
currentItem->setPos(variant.toPointF());
}
// else if (id == QLatin1String("list"))
// {
// qDebug()<<prop->data(VProperty::DPC_Data, Qt::DisplayRole);
// }
break;
}
// case VGraphicsSimpleTextItem::Type:
@ -206,6 +211,11 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item)
VPointFProperty* itemPosition = new VPointFProperty(tr("Position"));
itemPosition->setValue(i->pos());
AddProperty(itemPosition, QLatin1String("position"));
// VEnumProperty *enumProperty = new VEnumProperty(tr("list"));
// QStringList list = QStringList()<<"a1"<<"a2"<<"a3";
// enumProperty->setLiterals(list);
// AddProperty(enumProperty, QLatin1String("list"));
break;
}
case VGraphicsSimpleTextItem::Type:

View File

@ -2,14 +2,15 @@
#include "vproperty_p.h"
#include <QComboBox>
#include <QCoreApplication>
using namespace VPE;
VEnumProperty::VEnumProperty(const QString& name)
: VProperty(name, QVariant::Int)
: QObject(), VProperty(name, QVariant::Int)
{
d_ptr->VariantValue = 0;
d_ptr->VariantValue.convert(QVariant::Int);
VProperty::d_ptr->VariantValue = 0;
VProperty::d_ptr->VariantValue.convert(QVariant::Int);
}
@ -19,7 +20,7 @@ QVariant VEnumProperty::data (int column, int role) const
if(EnumerationLiterals.empty())
return QVariant();
int tmpIndex = d_ptr->VariantValue.toInt();
int tmpIndex = VProperty::d_ptr->VariantValue.toInt();
if(tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count())
tmpIndex = 0;
@ -41,9 +42,12 @@ QWidget* VEnumProperty::createEditor(QWidget * parent, const QStyleOptionViewIte
QComboBox* tmpEditor = new QComboBox(parent);
tmpEditor->clear();
tmpEditor->addItems(EnumerationLiterals);
tmpEditor->setCurrentIndex(d_ptr->VariantValue.toInt());
tmpEditor->setCurrentIndex(VProperty::d_ptr->VariantValue.toInt());
connect(tmpEditor, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
&VEnumProperty::currentIndexChanged);
return tmpEditor;
VProperty::d_ptr->editor = tmpEditor;
return VProperty::d_ptr->editor;
}
//! Gets the data from the widget
@ -76,7 +80,13 @@ void VEnumProperty::setValue(const QVariant& value)
if(tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count())
tmpIndex = 0;
d_ptr->VariantValue.setValue(tmpIndex);
VProperty::d_ptr->VariantValue = tmpIndex;
VProperty::d_ptr->VariantValue.convert(QVariant::Int);
if (VProperty::d_ptr->editor != nullptr)
{
setEditorData(VProperty::d_ptr->editor);
}
}
QString VEnumProperty::type() const
@ -107,3 +117,10 @@ QStringList VEnumProperty::getSettingKeys() const
{
return QStringList("literals");
}
void VEnumProperty::currentIndexChanged(int index)
{
Q_UNUSED(index)
UserChangeEvent *event = new UserChangeEvent();
QCoreApplication::postEvent ( VProperty::d_ptr->editor, event );
}

View File

@ -7,8 +7,9 @@
namespace VPE{
class VPROPERTYEXPLORERSHARED_EXPORT VEnumProperty : public VProperty
class VPROPERTYEXPLORERSHARED_EXPORT VEnumProperty : public QObject, public VProperty
{
Q_OBJECT
public:
//! Constructor
VEnumProperty(const QString& name);
@ -57,6 +58,9 @@ public:
//! Returns the list of keys of the property's settings
virtual QStringList getSettingKeys() const;
public slots:
void currentIndexChanged(int index);
protected:
//! The list of possible options to choose frome
QStringList EnumerationLiterals;

View File

@ -3,6 +3,7 @@
#include <QDoubleSpinBox>
#include <QSpinBox>
#include <QSizePolicy>
#include <QCoreApplication>
#include "vproperty_p.h"
@ -13,18 +14,18 @@ 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)
: QObject(), VProperty(name, QVariant::Int), Min(StandardMin), Max(StandardMax)
{
VProperty::setSettings(settings);
d_ptr->VariantValue.setValue(0);
d_ptr->VariantValue.convert(QVariant::Int);
VProperty::d_ptr->VariantValue.setValue(0);
VProperty::d_ptr->VariantValue.convert(QVariant::Int);
}
VIntegerProperty::VIntegerProperty(const QString &name)
: VProperty(name), Min(StandardMin), Max(StandardMax)
: QObject(), VProperty(name), Min(StandardMin), Max(StandardMax)
{
d_ptr->VariantValue.setValue(0);
d_ptr->VariantValue.convert(QVariant::Int);
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
@ -37,10 +38,12 @@ QWidget* VIntegerProperty::createEditor(QWidget * parent, const QStyleOptionView
tmpEditor->setMinimum(Min);
tmpEditor->setMaximum(Max);
tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tmpEditor->setValue(d_ptr->VariantValue.toInt());
tmpEditor->setValue(VProperty::d_ptr->VariantValue.toInt());
connect(tmpEditor, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&VIntegerProperty::valueChanged);
d_ptr->editor = tmpEditor;
return d_ptr->editor;
VProperty::d_ptr->editor = tmpEditor;
return VProperty::d_ptr->editor;
}
//! Gets the data from the widget
@ -92,6 +95,13 @@ VProperty* VIntegerProperty::clone(bool include_children, VProperty* container)
return VProperty::clone(include_children, container ? container : new VIntegerProperty(getName()));
}
void VIntegerProperty::valueChanged(int i)
{
Q_UNUSED(i)
UserChangeEvent *event = new UserChangeEvent();
QCoreApplication::postEvent ( VProperty::d_ptr->editor, event );
}
@ -102,17 +112,17 @@ VDoubleProperty::VDoubleProperty(const QString& name, const QMap<QString, QVaria
: VIntegerProperty(name), Precision(StandardPrecision)
{
VProperty::setSettings(settings);
d_ptr->VariantValue.setValue(0);
d_ptr->VariantValue.convert(QVariant::Double);
d_ptr->PropertyVariantType = QVariant::Double;
VProperty::d_ptr->VariantValue.setValue(0);
VProperty::d_ptr->VariantValue.convert(QVariant::Double);
VProperty::d_ptr->PropertyVariantType = QVariant::Double;
}
VDoubleProperty::VDoubleProperty(const QString &name)
: VIntegerProperty(name), Precision(StandardPrecision)
{
d_ptr->VariantValue.setValue(0);
d_ptr->VariantValue.convert(QVariant::Double);
d_ptr->PropertyVariantType = QVariant::Double;
VProperty::d_ptr->VariantValue.setValue(0);
VProperty::d_ptr->VariantValue.convert(QVariant::Double);
VProperty::d_ptr->PropertyVariantType = QVariant::Double;
}
//! Returns an editor widget, or NULL if it doesn't supply one
@ -125,10 +135,12 @@ QWidget* VDoubleProperty::createEditor(QWidget * parent, const QStyleOptionViewI
tmpEditor->setMaximum(Max);
tmpEditor->setDecimals(Precision);
tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tmpEditor->setValue(d_ptr->VariantValue.toDouble());
tmpEditor->setValue(VProperty::d_ptr->VariantValue.toDouble());
connect(tmpEditor, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this,
&VIntegerProperty::valueChanged);
d_ptr->editor = tmpEditor;
return d_ptr->editor;
VProperty::d_ptr->editor = tmpEditor;
return VProperty::d_ptr->editor;
}
//! Gets the data from the widget

View File

@ -8,8 +8,9 @@ namespace VPE {
//! Class for holding an integer property
class VPROPERTYEXPLORERSHARED_EXPORT VIntegerProperty : public VProperty
class VPROPERTYEXPLORERSHARED_EXPORT VIntegerProperty : public QObject, public VProperty
{
Q_OBJECT
public:
VIntegerProperty(const QString& name, const QMap<QString, QVariant>& settings);
@ -49,7 +50,8 @@ public:
//! \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:
int Min, Max;
@ -61,6 +63,7 @@ protected:
//! Class for holding a double property
class VPROPERTYEXPLORERSHARED_EXPORT VDoubleProperty : public VIntegerProperty
{
Q_OBJECT
public:
VDoubleProperty(const QString& name, const QMap<QString, QVariant>& settings);

View File

@ -122,8 +122,6 @@ void VPropertyFormView::dataSubmitted(VProperty *property)
if(tmpModel && d_ptr->UpdateEditors) {
static_cast<VPropertyFormViewPrivate*>(d_ptr)->IgnoreDataChangedSignal = true;
tmpModel->onDataChangedByModel(property);
tmpModel->showDataChangedByEditor(property);
static_cast<VPropertyFormViewPrivate*>(d_ptr)->IgnoreDataChangedSignal = false;
}
}
@ -171,7 +169,8 @@ void VPropertyFormView::connectPropertyFormWidget(VPropertyFormWidget *widget)
if(!widget)
return;
connect(widget, SIGNAL(propertyDataSubmitted(VProperty*)), this, SLOT(dataSubmitted(VProperty*)));
connect(widget, &VPropertyFormWidget::propertyDataSubmitted, this, &VPropertyFormView::dataSubmitted,
Qt::UniqueConnection);
QList<VPropertyFormWidget*> tmpList = widget->getChildPropertyFormWidgets();
foreach(VPropertyFormWidget* tmpEditorWidget, tmpList) {

View File

@ -7,6 +7,7 @@
#include <QEvent>
#include <QKeyEvent>
#include "vproperty.h"
#include <QDebug>
using namespace VPE;
@ -125,10 +126,10 @@ void VPropertyFormWidget::commitData(int row)
tmpEditorWidget.FormWidget->commitData();
else if(tmpEditorWidget.Editor && tmpProperty) {
QVariant newValue = tmpProperty->getEditorData(tmpEditorWidget.Editor);
QVariant oldValue = tmpProperty->data(VProperty::DPC_Data);
QVariant oldValue = tmpProperty->data(VProperty::DPC_Data, Qt::EditRole);
if (oldValue != newValue)
{
tmpProperty->setValue(tmpProperty->getEditorData(tmpEditorWidget.Editor));
tmpProperty->setValue(newValue);
emit propertyDataSubmitted(tmpProperty);
}
}
@ -205,6 +206,10 @@ bool VPropertyFormWidget::eventFilter(QObject *object, QEvent *event)
event->accept();
return true;
}
else
{
return QGroupBox::eventFilter(object, event);
}
// Default:
return false;

View File

@ -230,12 +230,8 @@ void VPropertyModel::onDataChangedByModel(VProperty* property)
if(tmpIndex.isValid())
{
emit dataChanged(tmpIndex, tmpIndex);
}
}
void VPropertyModel::showDataChangedByEditor(VProperty *property)
{
emit onDataChangedByEditor(property);
}
}
const VPropertySet *VPropertyModel::getPropertySet() const

View File

@ -124,8 +124,6 @@ public slots:
//! This function causes the views to update the property
void onDataChangedByModel(VProperty* property);
void showDataChangedByEditor(VProperty* property);
protected:
//! Gets a property by its ModelIndex
virtual QModelIndex getIndexFromProperty(VProperty* property, int column = 0) const;