Vera++.
--HG-- branch : develop
This commit is contained in:
parent
9a735b29bf
commit
1d4f0a6a55
|
@ -190,7 +190,7 @@ void Calculator::InitVariables(const VContainer *data, const QMap<int, QString>
|
|||
|
||||
if (found == false)
|
||||
{
|
||||
throw qmu::QmuParserError (ecUNASSIGNABLE_TOKEN , i.value(), formula, i.key());
|
||||
throw qmu::QmuParserError (ecUNASSIGNABLE_TOKEN, i.value(), formula, i.key());
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
|
|
@ -437,7 +437,7 @@ const QMap<QString, QSharedPointer<T> > VContainer::DataVar(const VarType &type)
|
|||
QHash<QString, QSharedPointer<VInternalVariable> >::const_iterator i;
|
||||
for (i = d->variables.constBegin(); i != d->variables.constEnd(); ++i)
|
||||
{
|
||||
if(i.value()->GetType() == type)
|
||||
if (i.value()->GetType() == type)
|
||||
{
|
||||
QSharedPointer<T> var = GetVariable<T>(i.key());
|
||||
map.insert(qApp->VarToUser(i.key()), var);
|
||||
|
|
|
@ -175,9 +175,9 @@ public:
|
|||
template <typename T>
|
||||
void AddVariable(const QString& name, T *var)
|
||||
{
|
||||
if(d->variables.contains(name))
|
||||
if (d->variables.contains(name))
|
||||
{
|
||||
if(d->variables.value(name)->GetType() == var->GetType())
|
||||
if (d->variables.value(name)->GetType() == var->GetType())
|
||||
{
|
||||
d->variables[name].clear();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -185,7 +185,7 @@ int main(int argc, char *argv[])
|
|||
//Before we load pattern show window.
|
||||
w.show();
|
||||
|
||||
for(int i=0;i<args.size();++i)
|
||||
for (int i=0;i<args.size();++i)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
|
|
|
@ -767,7 +767,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MainWindow::customEvent(QEvent *event)
|
||||
{
|
||||
if(event->type() == UNDO_EVENT)
|
||||
if (event->type() == UNDO_EVENT)
|
||||
{
|
||||
qApp->getUndoStack()->undo();
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ private:
|
|||
QString CheckPathToMeasurements(const QString &path, const MeasurementsType &patternType);
|
||||
void OpenPattern(const QString &filePath);
|
||||
QComboBox *SetGradationList(const QString &label, const QStringList &list);
|
||||
void ChangePP(int index , bool zoomBestFit = true);
|
||||
void ChangePP(int index, bool zoomBestFit = true);
|
||||
/**
|
||||
* @brief EndVisualization try show dialog after and working with tool visualization.
|
||||
*/
|
||||
|
|
|
@ -393,4 +393,3 @@ void VToolBisector::setFirstPointId(const quint32 &value)
|
|||
SaveOption(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -338,4 +338,3 @@ void VToolHeight::setP1LineId(const quint32 &value)
|
|||
SaveOption(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -397,4 +397,3 @@ void VToolLineIntersect::setP1Line1(const quint32 &value)
|
|||
SaveOption(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -353,4 +353,3 @@ void VToolNormal::ShowVisualization(bool show)
|
|||
vis = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -397,4 +397,3 @@ void VToolShoulderPoint::setP2Line(const quint32 &value)
|
|||
SaveOption(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -354,7 +354,7 @@ void VToolSpline::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
|
|||
void VToolSpline::RefreshGeometry()
|
||||
{
|
||||
//this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
|
||||
if(isHovered)
|
||||
if (isHovered)
|
||||
{
|
||||
this->setPath(ToolPath(PathDirection::Show));
|
||||
}
|
||||
|
|
|
@ -417,7 +417,7 @@ void VToolSplinePath::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &ob
|
|||
*/
|
||||
void VToolSplinePath::RefreshGeometry()
|
||||
{
|
||||
if(isHovered)
|
||||
if (isHovered)
|
||||
{
|
||||
this->setPath(ToolPath(PathDirection::Show));
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ qreal VisLine::CorrectAngle(const qreal &angle) const
|
|||
ang = angle - 360 * qFloor(angle/360);
|
||||
}
|
||||
|
||||
switch(qFloor((qAbs(ang)+22.5)/45))
|
||||
switch (qFloor((qAbs(ang)+22.5)/45))
|
||||
{
|
||||
case 0: // <22.5
|
||||
return 0;
|
||||
|
@ -86,7 +86,7 @@ qreal VisLine::CorrectAngle(const qreal &angle) const
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QPointF VisLine::Ray(const QPointF &firstPoint, const qreal &angle) const
|
||||
{
|
||||
if(this->scene() == nullptr)
|
||||
if (this->scene() == nullptr)
|
||||
{
|
||||
QLineF line = QLineF(firstPoint, Visualization::scenePos);
|
||||
line.setAngle(angle);
|
||||
|
|
|
@ -112,8 +112,3 @@ void VisToolSpline::setKCurve(const qreal &value)
|
|||
{
|
||||
kCurve = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ void VisToolTriangle::DrawAimedAxis(QGraphicsPathItem *item, const QLineF &line,
|
|||
axis.setLength(arrow_step);
|
||||
|
||||
int steps = qFloor(line.length()/arrow_step);
|
||||
for(int i=0; i<steps; ++i)
|
||||
for (int i=0; i<steps; ++i)
|
||||
{
|
||||
DrawArrow(axis, path, arrow_size);
|
||||
axis.setLength(axis.length()+arrow_step);
|
||||
|
|
|
@ -2075,13 +2075,13 @@ void VApplication::restoreOverrideCursor(const QString &pixmapPath, int hotX, in
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QStringList VApplication::LabelLanguages()
|
||||
{
|
||||
QStringList list{"de" , // German
|
||||
"en" , // English
|
||||
"fr" , // French
|
||||
"ru" , // Russian
|
||||
"uk" , // Ukrainian
|
||||
"hr" , // Croatian
|
||||
"sr" , // Serbian
|
||||
QStringList list{"de", // German
|
||||
"en", // English
|
||||
"fr", // French
|
||||
"ru", // Russian
|
||||
"uk", // Ukrainian
|
||||
"hr", // Croatian
|
||||
"sr", // Serbian
|
||||
"bs" // Bosnian
|
||||
};
|
||||
return list;
|
||||
|
|
|
@ -62,18 +62,26 @@ VFormulaProperty::VFormulaProperty(const QString &name) :
|
|||
//! Get the data how it should be displayed
|
||||
QVariant VFormulaProperty::data (int column, int role) const
|
||||
{
|
||||
if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
|
||||
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)
|
||||
if (column == DPC_Name || column == DPC_Data)
|
||||
{
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Qt::NoItemFlags;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -97,7 +105,7 @@ QWidget* VFormulaProperty::createEditor(QWidget* parent, const QStyleOptionViewI
|
|||
bool VFormulaProperty::setEditorData(QWidget* editor)
|
||||
{
|
||||
VFormulaPropertyEditor* tmpWidget = qobject_cast<VFormulaPropertyEditor*>(editor);
|
||||
if(tmpWidget)
|
||||
if (tmpWidget)
|
||||
{
|
||||
VFormula formula = VProperty::d_ptr->VariantValue.value<VFormula>();
|
||||
tmpWidget->setFormula(formula);
|
||||
|
@ -113,7 +121,7 @@ bool VFormulaProperty::setEditorData(QWidget* editor)
|
|||
QVariant VFormulaProperty::getEditorData(QWidget* editor) const
|
||||
{
|
||||
VFormulaPropertyEditor* tmpWidget = qobject_cast<VFormulaPropertyEditor*>(editor);
|
||||
if(tmpWidget)
|
||||
if (tmpWidget)
|
||||
{
|
||||
QVariant value;
|
||||
value.setValue(tmpWidget->getFormula());
|
||||
|
@ -132,19 +140,22 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return VProperty::clone(false, container); // Child
|
||||
return VProperty::clone(false, container); // Child
|
||||
|
||||
}
|
||||
|
||||
|
@ -173,8 +184,10 @@ VFormula VFormulaProperty::getFormula() const
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VFormulaProperty::setFormula(const VFormula &formula)
|
||||
{
|
||||
if(d_ptr->Children.count() < 2)
|
||||
if (d_ptr->Children.count() < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QVariant value;
|
||||
value.setValue(formula);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ VFormulaPropertyEditor::VFormulaPropertyEditor(QWidget *parent) :
|
|||
ToolButton->setText(tr("..."));
|
||||
ToolButton->setFixedWidth(20);
|
||||
ToolButton->installEventFilter(this);
|
||||
setFocusProxy(ToolButton); // Make the ToolButton the focus proxy
|
||||
setFocusProxy(ToolButton); // Make the ToolButton the focus proxy
|
||||
setFocusPolicy(ToolButton->focusPolicy());
|
||||
connect(ToolButton, SIGNAL(clicked()), this, SLOT(onToolButtonClicked()));
|
||||
|
||||
|
@ -105,7 +105,7 @@ void VFormulaPropertyEditor::onToolButtonClicked()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VFormulaPropertyEditor::eventFilter(QObject *obj, QEvent *ev)
|
||||
{
|
||||
if(obj == ToolButton && (ev->type() == QEvent::KeyPress || ev->type() == QEvent::KeyPress))
|
||||
if (obj == ToolButton && (ev->type() == QEvent::KeyPress || ev->type() == QEvent::KeyPress))
|
||||
{
|
||||
// Ignore the event, so that eventually the delegate gets the event.
|
||||
ev->ignore();
|
||||
|
|
|
@ -267,4 +267,3 @@ void VMainGraphicsView::setShowToolOptions(bool value)
|
|||
{
|
||||
showToolOptions = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -201,7 +201,7 @@ qreal VAbstractMeasurements::UnitConvertor(qreal value, const Unit &from, const
|
|||
switch (from)
|
||||
{
|
||||
case Unit::Mm:
|
||||
switch(to)
|
||||
switch (to)
|
||||
{
|
||||
case Unit::Mm:
|
||||
return value;
|
||||
|
@ -214,7 +214,7 @@ qreal VAbstractMeasurements::UnitConvertor(qreal value, const Unit &from, const
|
|||
}
|
||||
break;
|
||||
case Unit::Cm:
|
||||
switch(to)
|
||||
switch (to)
|
||||
{
|
||||
case Unit::Mm:
|
||||
return value * 10.0;
|
||||
|
@ -227,7 +227,7 @@ qreal VAbstractMeasurements::UnitConvertor(qreal value, const Unit &from, const
|
|||
}
|
||||
break;
|
||||
case Unit::Inch:
|
||||
switch(to)
|
||||
switch (to)
|
||||
{
|
||||
case Unit::Mm:
|
||||
return value * 25.4;
|
||||
|
|
|
@ -723,7 +723,7 @@ void VPattern::LiteParseTree(const Document &parse)
|
|||
try
|
||||
{
|
||||
emit SetEnabledGUI(true);
|
||||
switch(parse)
|
||||
switch (parse)
|
||||
{
|
||||
case Document::LitePPParse:
|
||||
ParseCurrentPP();
|
||||
|
@ -832,7 +832,7 @@ void VPattern::ClearScene()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPattern::customEvent(QEvent *event)
|
||||
{
|
||||
if(event->type() == UNDO_EVENT)
|
||||
if (event->type() == UNDO_EVENT)
|
||||
{
|
||||
qApp->getUndoStack()->undo();
|
||||
}
|
||||
|
@ -1629,7 +1629,7 @@ QString VPattern::GetLabelBase(unsigned int index) const
|
|||
QStringList list = VApplication::LabelLanguages();
|
||||
|
||||
QStringList alphabet;
|
||||
switch(list.indexOf(checkedLocale))
|
||||
switch (list.indexOf(checkedLocale))
|
||||
{
|
||||
case 0: // de
|
||||
{
|
||||
|
@ -2369,7 +2369,7 @@ QString VPattern::GenerateLabel(const LabelType &type) const
|
|||
{
|
||||
QString name;
|
||||
int i = 0;
|
||||
for(;;)
|
||||
for (;;)
|
||||
{
|
||||
name = GetLabelBase(drawList.size() + i);
|
||||
if (data->IsUnique(name))
|
||||
|
|
|
@ -27,7 +27,7 @@ using namespace VPE;
|
|||
#include <QStringList>
|
||||
|
||||
QVector3DProperty::QVector3DProperty(const QString& name)
|
||||
: VProperty(name, QVariant::String) // todo: QVariant::Vector3D??
|
||||
: VProperty(name, QVariant::String) // todo: QVariant::Vector3D??
|
||||
{
|
||||
QVariant tmpFloat(0); tmpFloat.convert(QVariant::Double);
|
||||
VDoubleProperty* tmpX = new VDoubleProperty("X"); addChild(tmpX); tmpX->setUpdateBehaviour(true, false);
|
||||
|
@ -40,7 +40,7 @@ QVector3DProperty::QVector3DProperty(const QString& name)
|
|||
//! Get the data how it should be displayed
|
||||
QVariant QVector3DProperty::data (int column, int role) const
|
||||
{
|
||||
if(column == DPC_Data && Qt::DisplayRole == role)
|
||||
if (column == DPC_Data && Qt::DisplayRole == role)
|
||||
{
|
||||
Vector3D tmpVect = getVector();
|
||||
return QString("(%1, %2, %3)").arg(QString::number(tmpVect.X),
|
||||
|
@ -54,8 +54,10 @@ QVariant QVector3DProperty::data (int column, int role) const
|
|||
//! Returns item flags
|
||||
Qt::ItemFlags QVector3DProperty::flags(int column) const
|
||||
{
|
||||
if(column == DPC_Name || column == DPC_Data)
|
||||
if (column == DPC_Name || column == DPC_Data)
|
||||
{
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
else
|
||||
return Qt::NoItemFlags;
|
||||
}
|
||||
|
@ -66,8 +68,10 @@ Vector3D QVector3DProperty::getVector() const
|
|||
{
|
||||
Vector3D tmpVect;
|
||||
|
||||
if(d_ptr->Children.count() < 3)
|
||||
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();
|
||||
|
@ -84,8 +88,10 @@ void QVector3DProperty::setVector(const Vector3D &vect)
|
|||
|
||||
void QVector3DProperty::setVector(float x, float y, float z)
|
||||
{
|
||||
if(d_ptr->Children.count() < 3)
|
||||
if (d_ptr->Children.count() < 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QVariant tmpX(x); tmpX.convert(QVariant::Double);
|
||||
QVariant tmpY(y); tmpY.convert(QVariant::Double);
|
||||
|
@ -102,25 +108,29 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return VProperty::clone(false, container); // Child
|
||||
return VProperty::clone(false, container); // Child
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -41,27 +41,38 @@ 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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! Get the data how it should be displayed
|
||||
QVariant VBoolProperty::data (int column, int role) const
|
||||
{
|
||||
if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
|
||||
if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
|
||||
{
|
||||
return d_ptr->VariantValue.toBool() ? TrueText : FalseText;
|
||||
if(column == DPC_Data && Qt::CheckStateRole == role)
|
||||
}
|
||||
if (column == DPC_Data && Qt::CheckStateRole == role)
|
||||
{
|
||||
return d_ptr->VariantValue.toBool() ? Qt::Checked : Qt::Unchecked;
|
||||
}
|
||||
else
|
||||
return VProperty::data(column, role);
|
||||
}
|
||||
|
||||
bool VBoolProperty::setData(const QVariant &data, int role)
|
||||
{
|
||||
if(Qt::CheckStateRole == 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;
|
||||
|
@ -70,8 +81,10 @@ bool VBoolProperty::setData(const QVariant &data, int role)
|
|||
//! Returns item flags
|
||||
Qt::ItemFlags VBoolProperty::flags(int column) const
|
||||
{
|
||||
if(column == DPC_Data)
|
||||
if (column == DPC_Data)
|
||||
{
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
|
||||
}
|
||||
else
|
||||
return VProperty::flags(column);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -34,18 +34,25 @@ VColorProperty::VColorProperty(const QString &name) :
|
|||
//! Get the data how it should be displayed
|
||||
QVariant VColorProperty::data (int column, int role) const
|
||||
{
|
||||
if(column == DPC_Data && (Qt::DisplayRole == role))
|
||||
if (column == DPC_Data && (Qt::DisplayRole == role))
|
||||
{
|
||||
return VColorPropertyEditor::getColorString(d_ptr->VariantValue.value<QColor>());
|
||||
else if(Qt::EditRole == role)
|
||||
}
|
||||
else if (Qt::EditRole == role)
|
||||
{
|
||||
return QVariant();
|
||||
else if(column == DPC_Data && (Qt::DecorationRole == role))
|
||||
}
|
||||
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);
|
||||
|
@ -59,8 +66,10 @@ QWidget* VColorProperty::createEditor(QWidget* parent, const QStyleOptionViewIte
|
|||
bool VColorProperty::setEditorData(QWidget* editor)
|
||||
{
|
||||
VColorPropertyEditor* tmpWidget = qobject_cast<VColorPropertyEditor*>(editor);
|
||||
if(tmpWidget)
|
||||
if (tmpWidget)
|
||||
{
|
||||
tmpWidget->setColor(d_ptr->VariantValue.value<QColor>());
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
|
@ -71,8 +80,10 @@ bool VColorProperty::setEditorData(QWidget* editor)
|
|||
QVariant VColorProperty::getEditorData(QWidget* editor) const
|
||||
{
|
||||
VColorPropertyEditor* tmpWidget = qobject_cast<VColorPropertyEditor*>(editor);
|
||||
if(tmpWidget)
|
||||
if (tmpWidget)
|
||||
{
|
||||
return tmpWidget->getColor();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ VColorPropertyEditor::VColorPropertyEditor(QWidget *parent) :
|
|||
ToolButton->setText(tr("..."));
|
||||
ToolButton->setFixedWidth(20);
|
||||
ToolButton->installEventFilter(this);
|
||||
setFocusProxy(ToolButton); // Make the ToolButton the focus proxy
|
||||
setFocusProxy(ToolButton); // Make the ToolButton the focus proxy
|
||||
setFocusPolicy(ToolButton->focusPolicy());
|
||||
connect(ToolButton, SIGNAL(clicked()), this, SLOT(onToolButtonClicked()));
|
||||
|
||||
|
@ -65,7 +65,7 @@ VColorPropertyEditor::VColorPropertyEditor(QWidget *parent) :
|
|||
layout->addItem(Spacer);
|
||||
layout->addWidget(ToolButton);
|
||||
//TextLabel->hide();
|
||||
//ColorLabel->hide(); // for now, we just use the standard display and only add the button
|
||||
//ColorLabel->hide(); // for now, we just use the standard display and only add the button
|
||||
}
|
||||
|
||||
void VColorPropertyEditor::setColor(const QColor& color_)
|
||||
|
@ -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();
|
||||
|
@ -111,7 +112,7 @@ void VColorPropertyEditor::onToolButtonClicked()
|
|||
|
||||
bool VColorPropertyEditor::eventFilter(QObject *obj, QEvent *ev)
|
||||
{
|
||||
if(obj == ToolButton && (ev->type() == QEvent::KeyPress || ev->type() == QEvent::KeyPress))
|
||||
if (obj == ToolButton && (ev->type() == QEvent::KeyPress || ev->type() == QEvent::KeyPress))
|
||||
{
|
||||
// Ignore the event, so that eventually the delegate gets the event.
|
||||
ev->ignore();
|
||||
|
@ -127,8 +128,6 @@ VColorPropertyEditor::~VColorPropertyEditor()
|
|||
//
|
||||
}
|
||||
|
||||
|
||||
|
||||
QColor VColorPropertyEditor::getColor()
|
||||
{
|
||||
return Color;
|
||||
|
|
|
@ -29,7 +29,8 @@
|
|||
#include <QLabel>
|
||||
#include <QSpacerItem>
|
||||
|
||||
namespace VPE{
|
||||
namespace VPE
|
||||
{
|
||||
|
||||
class VPROPERTYEXPLORERSHARED_EXPORT VColorPropertyEditor : public QWidget
|
||||
{
|
||||
|
|
|
@ -42,18 +42,25 @@ VEmptyProperty::~VEmptyProperty()
|
|||
//! Get the data how it should be displayed
|
||||
QVariant VEmptyProperty::data (int column, int role) const
|
||||
{
|
||||
if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
|
||||
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; }
|
||||
}
|
||||
else if (role == Qt::BackgroundRole)
|
||||
{
|
||||
return QBrush(QColor(217, 217, 217));
|
||||
}
|
||||
else if (role == Qt::FontRole)
|
||||
{
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -37,25 +37,34 @@ VEnumProperty::VEnumProperty(const QString& name)
|
|||
//! Get the data how it should be displayed
|
||||
QVariant VEnumProperty::data (int column, int role) const
|
||||
{
|
||||
if(EnumerationLiterals.empty())
|
||||
if (EnumerationLiterals.empty())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
int tmpIndex = VProperty::d_ptr->VariantValue.toInt();
|
||||
|
||||
if(tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count())
|
||||
if (tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count())
|
||||
{
|
||||
tmpIndex = 0;
|
||||
}
|
||||
|
||||
if(column == DPC_Data && Qt::DisplayRole == role)
|
||||
if (column == DPC_Data && Qt::DisplayRole == role)
|
||||
{
|
||||
return EnumerationLiterals.at(tmpIndex);
|
||||
else if(column == DPC_Data && Qt::EditRole == role)
|
||||
}
|
||||
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);
|
||||
|
@ -74,8 +83,10 @@ QWidget* VEnumProperty::createEditor(QWidget * parent, const QStyleOptionViewIte
|
|||
QVariant VEnumProperty::getEditorData(QWidget* editor) const
|
||||
{
|
||||
QComboBox* tmpEditor = qobject_cast<QComboBox*>(editor);
|
||||
if(tmpEditor)
|
||||
if (tmpEditor)
|
||||
{
|
||||
return tmpEditor->currentIndex();
|
||||
}
|
||||
|
||||
return QVariant(0);
|
||||
}
|
||||
|
@ -97,8 +108,10 @@ void VEnumProperty::setValue(const QVariant& value)
|
|||
{
|
||||
int tmpIndex = value.toInt();
|
||||
|
||||
if(tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count())
|
||||
if (tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count())
|
||||
{
|
||||
tmpIndex = 0;
|
||||
}
|
||||
|
||||
VProperty::d_ptr->VariantValue = tmpIndex;
|
||||
VProperty::d_ptr->VariantValue.convert(QVariant::Int);
|
||||
|
@ -121,14 +134,18 @@ VProperty* VEnumProperty::clone(bool include_children, VProperty* container) con
|
|||
|
||||
void VEnumProperty::setSetting(const QString& key, const QVariant& value)
|
||||
{
|
||||
if(key == "literals")
|
||||
if (key == "literals")
|
||||
{
|
||||
setLiterals(value.toString().split(";;"));
|
||||
}
|
||||
}
|
||||
|
||||
QVariant VEnumProperty::getSetting(const QString& key) const
|
||||
{
|
||||
if(key == "literals")
|
||||
if (key == "literals")
|
||||
{
|
||||
return getLiterals().join(";;");
|
||||
}
|
||||
else
|
||||
return VProperty::getSetting(key);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ QString VFileProperty::getFile() const
|
|||
|
||||
QVariant VFileProperty::data (int column, int role) const
|
||||
{
|
||||
if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
|
||||
if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
|
||||
{
|
||||
QFileInfo tmpFile(d_ptr->VariantValue.toString());
|
||||
return tmpFile.fileName();
|
||||
|
@ -76,14 +76,18 @@ 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)
|
||||
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->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);
|
||||
return tmpWidget;
|
||||
|
@ -93,8 +97,10 @@ QWidget* VFileProperty::createEditor(QWidget * parent, const QStyleOptionViewIte
|
|||
bool VFileProperty::setEditorData(QWidget* editor)
|
||||
{
|
||||
VFileEditWidget* tmpWidget = qobject_cast<VFileEditWidget*>(editor);
|
||||
if(tmpWidget)
|
||||
if (tmpWidget)
|
||||
{
|
||||
tmpWidget->setFile(d_ptr->VariantValue.toString());
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
|
@ -105,26 +111,36 @@ bool VFileProperty::setEditorData(QWidget* editor)
|
|||
QVariant VFileProperty::getEditorData(QWidget* editor) const
|
||||
{
|
||||
VFileEditWidget* tmpWidget = qobject_cast<VFileEditWidget*>(editor);
|
||||
if(tmpWidget)
|
||||
if (tmpWidget)
|
||||
{
|
||||
return tmpWidget->getFile();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void VFileProperty::setSetting(const QString& key, const QVariant& value)
|
||||
{
|
||||
if(key == "FileFilters")
|
||||
if (key == "FileFilters")
|
||||
{
|
||||
setFileFilters(value.toString());
|
||||
else if(key == "Directory")
|
||||
}
|
||||
else if (key == "Directory")
|
||||
{
|
||||
setDirectory(value.toBool());
|
||||
}
|
||||
}
|
||||
|
||||
QVariant VFileProperty::getSetting(const QString& key) const
|
||||
{
|
||||
if(key == "FileFilters")
|
||||
if (key == "FileFilters")
|
||||
{
|
||||
return getFileFilters();
|
||||
else if(key == "Directory")
|
||||
}
|
||||
else if (key == "Directory")
|
||||
{
|
||||
return isDirectory();
|
||||
}
|
||||
else
|
||||
return VProperty::getSetting(key);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ VFileEditWidget::VFileEditWidget(QWidget *parent, bool is_directory)
|
|||
ToolButton->setText(tr("..."));
|
||||
ToolButton->setFixedWidth(20);
|
||||
ToolButton->installEventFilter(this);
|
||||
setFocusProxy(ToolButton); // Make the ToolButton the focus proxy
|
||||
setFocusProxy(ToolButton); // Make the ToolButton the focus proxy
|
||||
setFocusPolicy(ToolButton->focusPolicy());
|
||||
connect(ToolButton, SIGNAL(clicked()), this, SLOT(onToolButtonClicked()));
|
||||
|
||||
|
@ -73,7 +73,7 @@ void VFileEditWidget::setFile(const QString &value, bool emit_signal)
|
|||
CurrentFilePath = value;
|
||||
FileLineEdit->setText(CurrentFilePath);
|
||||
|
||||
if(emit_signal)
|
||||
if (emit_signal)
|
||||
{
|
||||
emit dataChangedByUser(CurrentFilePath, this);
|
||||
emit commitData(this);
|
||||
|
@ -101,36 +101,46 @@ 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)
|
||||
{
|
||||
if(ev->type() == QEvent::DragEnter || ev->type() == QEvent::Drop)
|
||||
if (ev->type() == QEvent::DragEnter || ev->type() == QEvent::Drop)
|
||||
{
|
||||
ev->ignore();
|
||||
if(ev->type() == QEvent::DragEnter)
|
||||
if (ev->type() == QEvent::DragEnter)
|
||||
{
|
||||
dragEnterEvent(static_cast<QDragEnterEvent*>(ev));
|
||||
else if(ev->type() == QEvent::Drop)
|
||||
}
|
||||
else if (ev->type() == QEvent::Drop)
|
||||
{
|
||||
dropEvent(static_cast<QDropEvent*>(ev));
|
||||
}
|
||||
|
||||
if(ev->isAccepted())
|
||||
if (ev->isAccepted())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return QWidget::eventFilter(obj, ev);
|
||||
}
|
||||
else if(obj == ToolButton && (ev->type() == QEvent::KeyPress || ev->type() == QEvent::KeyPress))
|
||||
else if (obj == ToolButton && (ev->type() == QEvent::KeyPress || ev->type() == QEvent::KeyPress))
|
||||
{
|
||||
// Ignore the event, so that eventually the delegate gets the event.
|
||||
ev->ignore();
|
||||
return true;
|
||||
}
|
||||
else if(obj == FileLineEdit)
|
||||
else if (obj == FileLineEdit)
|
||||
{
|
||||
if(ev->type() == QEvent::FocusOut)
|
||||
if (ev->type() == QEvent::FocusOut)
|
||||
{
|
||||
setFile(FileLineEdit->text(), true);
|
||||
// We don't return true here because we still want the line edit to catch the event as well
|
||||
|
@ -150,7 +160,7 @@ bool VFileEditWidget::isDirectory()
|
|||
void VFileEditWidget::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
QString tmpFileName;
|
||||
if(checkMimeData(event->mimeData(), tmpFileName))
|
||||
if (checkMimeData(event->mimeData(), tmpFileName))
|
||||
{
|
||||
event->accept();
|
||||
event->acceptProposedAction();
|
||||
|
@ -170,7 +180,7 @@ void VFileEditWidget::dragLeaveEvent(QDragLeaveEvent* event)
|
|||
void VFileEditWidget::dropEvent(QDropEvent* event)
|
||||
{
|
||||
QString tmpFileName;
|
||||
if(checkMimeData(event->mimeData(), tmpFileName))
|
||||
if (checkMimeData(event->mimeData(), tmpFileName))
|
||||
{
|
||||
setFile(tmpFileName);
|
||||
emit dataChangedByUser(getFile(), this);
|
||||
|
@ -189,10 +199,12 @@ bool VFileEditWidget::checkMimeData(const QMimeData* data, QString& file) const
|
|||
QFileInfo tmpFileInfo;
|
||||
|
||||
foreach(QUrl tmpUrl, tmpUrlList)
|
||||
if(QFile::exists(tmpUrl.toLocalFile()))
|
||||
{ tmpFileInfo = QFileInfo(tmpUrl.toLocalFile()); break; }
|
||||
if (QFile::exists(tmpUrl.toLocalFile()))
|
||||
{
|
||||
tmpFileInfo = QFileInfo(tmpUrl.toLocalFile()); break;
|
||||
}
|
||||
|
||||
if(checkFileFilter(tmpFileInfo.fileName()))
|
||||
if (checkFileFilter(tmpFileInfo.fileName()))
|
||||
{
|
||||
file = tmpFileInfo.absoluteFilePath();
|
||||
return true;
|
||||
|
@ -204,21 +216,26 @@ bool VFileEditWidget::checkMimeData(const QMimeData* data, QString& file) const
|
|||
|
||||
bool VFileEditWidget::checkFileFilter(const QString& file) const
|
||||
{
|
||||
if(FilterList.isEmpty())
|
||||
if (FilterList.isEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QFileInfo tmpFileInfo(file);
|
||||
|
||||
if((Directory && !tmpFileInfo.isDir()) || (!Directory && !tmpFileInfo.isFile()))
|
||||
if ((Directory && !tmpFileInfo.isDir()) || (!Directory && !tmpFileInfo.isFile()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach(QString tmpFilter, FilterList)
|
||||
{
|
||||
QRegExp tmpRegExpFilter(tmpFilter, Qt::CaseInsensitive, QRegExp::Wildcard);
|
||||
if(tmpRegExpFilter.exactMatch(file))
|
||||
if (tmpRegExpFilter.exactMatch(file))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
@ -71,37 +72,51 @@ QWidget* VIntegerProperty::createEditor(QWidget * parent, const QStyleOptionView
|
|||
QVariant VIntegerProperty::getEditorData(QWidget* editor) const
|
||||
{
|
||||
QSpinBox* tmpEditor = qobject_cast<QSpinBox*>(editor);
|
||||
if(tmpEditor)
|
||||
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);
|
||||
else if(key == QLatin1String("Max"))
|
||||
setSettings(min, value.toInt());
|
||||
else if(key == QLatin1String("Step"))
|
||||
if (key == QLatin1String("Min"))
|
||||
{
|
||||
setSettings(value.toInt(), maxValue);
|
||||
}
|
||||
else if (key == QLatin1String("Max"))
|
||||
{
|
||||
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;
|
||||
if(key == QLatin1String("Max"))
|
||||
return max;
|
||||
if(key == QLatin1String("Step"))
|
||||
if (key == QLatin1String("Min"))
|
||||
{
|
||||
return minValue;
|
||||
}
|
||||
if (key == QLatin1String("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);
|
||||
|
@ -174,42 +186,60 @@ QWidget* VDoubleProperty::createEditor(QWidget * parent, const QStyleOptionViewI
|
|||
QVariant VDoubleProperty::getEditorData(QWidget* editor) const
|
||||
{
|
||||
QDoubleSpinBox* tmpEditor = qobject_cast<QDoubleSpinBox*>(editor);
|
||||
if(tmpEditor)
|
||||
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;
|
||||
}
|
||||
|
||||
void VDoubleProperty::setSetting(const QString& key, const QVariant& value)
|
||||
{
|
||||
if(key == QLatin1String("Min"))
|
||||
setSettings(value.toDouble(), max, singleStep, Precision);
|
||||
else if(key == QLatin1String("Max"))
|
||||
setSettings(min, value.toDouble(), singleStep, Precision);
|
||||
else if(key == QLatin1String("Step"))
|
||||
setSettings(min, max, value.toDouble(), Precision);
|
||||
else if(key == QLatin1String("Precision"))
|
||||
setSettings(min, max, singleStep, value.toDouble());
|
||||
if (key == QLatin1String("Min"))
|
||||
{
|
||||
setSettings(value.toDouble(), maxValue, singleStep, Precision);
|
||||
}
|
||||
else if (key == QLatin1String("Max"))
|
||||
{
|
||||
setSettings(minValue, value.toDouble(), singleStep, Precision);
|
||||
}
|
||||
else if (key == QLatin1String("Step"))
|
||||
{
|
||||
setSettings(minValue, maxValue, value.toDouble(), Precision);
|
||||
}
|
||||
else if (key == QLatin1String("Precision"))
|
||||
{
|
||||
setSettings(minValue, maxValue, singleStep, value.toDouble());
|
||||
}
|
||||
}
|
||||
|
||||
QVariant VDoubleProperty::getSetting(const QString& key) const
|
||||
{
|
||||
if(key == QLatin1String("Min"))
|
||||
return min;
|
||||
if(key == QLatin1String("Max"))
|
||||
return max;
|
||||
if(key == QLatin1String("Step"))
|
||||
if (key == QLatin1String("Min"))
|
||||
{
|
||||
return minValue;
|
||||
}
|
||||
if (key == QLatin1String("Max"))
|
||||
{
|
||||
return maxValue;
|
||||
}
|
||||
if (key == QLatin1String("Step"))
|
||||
{
|
||||
return singleStep;
|
||||
if(key == QLatin1String("Precision"))
|
||||
}
|
||||
if (key == QLatin1String("Precision"))
|
||||
{
|
||||
return Precision;
|
||||
}
|
||||
else
|
||||
return VProperty::getSetting(key);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -37,17 +37,21 @@ VObjectProperty::VObjectProperty(const QString& name)
|
|||
//! Get the data how it should be displayed
|
||||
QVariant VObjectProperty::data (int column, int role) const
|
||||
{
|
||||
if(objects.empty())
|
||||
if (objects.empty())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QComboBox* tmpEditor = qobject_cast<QComboBox*>(VProperty::d_ptr->editor);
|
||||
|
||||
if(column == DPC_Data && Qt::DisplayRole == role)
|
||||
if (column == DPC_Data && Qt::DisplayRole == role)
|
||||
{
|
||||
return VProperty::d_ptr->VariantValue;
|
||||
}
|
||||
else if(column == DPC_Data && Qt::EditRole == role)
|
||||
else if (column == DPC_Data && Qt::EditRole == role)
|
||||
{
|
||||
return tmpEditor->currentIndex();
|
||||
}
|
||||
else
|
||||
return VProperty::data(column, role);
|
||||
}
|
||||
|
@ -71,11 +75,13 @@ QWidget* VObjectProperty::createEditor(QWidget * parent, const QStyleOptionViewI
|
|||
|
||||
bool VObjectProperty::setEditorData(QWidget *editor)
|
||||
{
|
||||
if(!editor)
|
||||
if (!editor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QComboBox* tmpEditor = qobject_cast<QComboBox*>(editor);
|
||||
if(tmpEditor)
|
||||
if (tmpEditor)
|
||||
{
|
||||
quint32 objId = VProperty::d_ptr->VariantValue.toUInt();
|
||||
qint32 tmpIndex = tmpEditor->findData(objId);
|
||||
|
@ -97,8 +103,10 @@ bool VObjectProperty::setEditorData(QWidget *editor)
|
|||
QVariant VObjectProperty::getEditorData(QWidget* editor) const
|
||||
{
|
||||
QComboBox* tmpEditor = qobject_cast<QComboBox*>(editor);
|
||||
if(tmpEditor)
|
||||
if (tmpEditor)
|
||||
{
|
||||
return tmpEditor->itemData(tmpEditor->currentIndex());
|
||||
}
|
||||
|
||||
return QVariant(0);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ VPE::VPointFProperty::VPointFProperty(const QString &name)
|
|||
|
||||
QVariant VPointFProperty::data(int column, int role) const
|
||||
{
|
||||
if(column == DPC_Data && Qt::DisplayRole == role)
|
||||
if (column == DPC_Data && Qt::DisplayRole == role)
|
||||
{
|
||||
return getPointF();
|
||||
}
|
||||
|
@ -55,8 +55,10 @@ QVariant VPointFProperty::data(int column, int role) const
|
|||
|
||||
Qt::ItemFlags VPointFProperty::flags(int column) const
|
||||
{
|
||||
if(column == DPC_Name || column == DPC_Data)
|
||||
if (column == DPC_Name || column == DPC_Data)
|
||||
{
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
else
|
||||
return Qt::NoItemFlags;
|
||||
}
|
||||
|
@ -65,8 +67,10 @@ QPointF VPointFProperty::getPointF() const
|
|||
{
|
||||
QPointF tmpValue;
|
||||
|
||||
if(d_ptr->Children.count() < 2)
|
||||
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());
|
||||
|
@ -81,8 +85,10 @@ void VPointFProperty::setPointF(const QPointF &point)
|
|||
|
||||
void VPointFProperty::setPointF(qreal x, qreal y)
|
||||
{
|
||||
if(d_ptr->Children.count() < 2)
|
||||
if (d_ptr->Children.count() < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QVariant tmpX(x);
|
||||
tmpX.convert(QVariant::Double);
|
||||
|
@ -101,19 +107,22 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return VProperty::clone(false, container); // Child
|
||||
return VProperty::clone(false, container); // Child
|
||||
}
|
||||
|
||||
void VPointFProperty::setValue(const QVariant &value)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ VShortcutProperty::~VShortcutProperty()
|
|||
|
||||
QVariant VShortcutProperty::data (int column, int role) const
|
||||
{
|
||||
if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
|
||||
if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
|
||||
{
|
||||
return d_ptr->VariantValue;
|
||||
}
|
||||
|
@ -57,8 +57,10 @@ QWidget* VShortcutProperty::createEditor(QWidget * parent, const QStyleOptionVie
|
|||
Q_UNUSED(options);
|
||||
|
||||
VShortcutEditWidget* tmpWidget = new VShortcutEditWidget(parent);
|
||||
if(delegate)
|
||||
if (delegate)
|
||||
{
|
||||
VShortcutEditWidget::connect(tmpWidget, SIGNAL(commitData(QWidget*)), delegate, SIGNAL(commitData(QWidget*)));
|
||||
}
|
||||
|
||||
return tmpWidget;
|
||||
return nullptr;
|
||||
|
@ -68,8 +70,10 @@ QWidget* VShortcutProperty::createEditor(QWidget * parent, const QStyleOptionVie
|
|||
bool VShortcutProperty::setEditorData(QWidget* editor)
|
||||
{
|
||||
VShortcutEditWidget* tmpWidget = qobject_cast<VShortcutEditWidget*>(editor);
|
||||
if(tmpWidget)
|
||||
if (tmpWidget)
|
||||
{
|
||||
tmpWidget->setShortcut(d_ptr->VariantValue.toString(), false);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
|
@ -80,8 +84,10 @@ bool VShortcutProperty::setEditorData(QWidget* editor)
|
|||
QVariant VShortcutProperty::getEditorData(QWidget* editor) const
|
||||
{
|
||||
VShortcutEditWidget* tmpWidget = qobject_cast<VShortcutEditWidget*>(editor);
|
||||
if(tmpWidget)
|
||||
if (tmpWidget)
|
||||
{
|
||||
return tmpWidget->getShortcutAsString();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -101,4 +107,3 @@ void VShortcutProperty::setValue(const QVariant &value)
|
|||
{
|
||||
VProperty::setValue(QKeySequence::fromString(value.toString()).toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -51,13 +51,15 @@ 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();
|
||||
|
||||
if(keys != Qt::Key_Shift &&
|
||||
if (keys != Qt::Key_Shift &&
|
||||
keys != Qt::Key_Control &&
|
||||
keys != Qt::Key_Meta &&
|
||||
keys != Qt::Key_AltGr &&
|
||||
|
@ -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,11 +92,14 @@ 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)
|
||||
if (emit_signal)
|
||||
{
|
||||
emit dataChangedByUser(CurrentKeySequence, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
#include <QLineEdit>
|
||||
#include <QMimeData>
|
||||
|
||||
namespace VPE{
|
||||
namespace VPE
|
||||
{
|
||||
|
||||
|
||||
class VPROPERTYEXPLORERSHARED_EXPORT VShortcutEditWidget : public QWidget
|
||||
|
|
|
@ -61,8 +61,10 @@ QWidget *VPE::VStringProperty::createEditor(QWidget *parent, const QStyleOptionV
|
|||
QVariant VPE::VStringProperty::getEditorData(QWidget *editor) const
|
||||
{
|
||||
QLineEdit* tmpEditor = qobject_cast<QLineEdit*>(editor);
|
||||
if(tmpEditor)
|
||||
if (tmpEditor)
|
||||
{
|
||||
return tmpEditor->text();
|
||||
}
|
||||
|
||||
return QVariant(QStringLiteral(""));
|
||||
}
|
||||
|
@ -74,18 +76,26 @@ void VPE::VStringProperty::setReadOnly(bool readOnly)
|
|||
|
||||
void VPE::VStringProperty::setSetting(const QString &key, const QVariant &value)
|
||||
{
|
||||
if(key == QLatin1String("ReadOnly"))
|
||||
if (key == QLatin1String("ReadOnly"))
|
||||
{
|
||||
setReadOnly(value.toBool());
|
||||
if(key == QLatin1String("TypeForParent"))
|
||||
}
|
||||
if (key == QLatin1String("TypeForParent"))
|
||||
{
|
||||
setTypeForParent(value.toInt());
|
||||
}
|
||||
}
|
||||
|
||||
QVariant VPE::VStringProperty::getSetting(const QString &key) const
|
||||
{
|
||||
if(key == QLatin1String("ReadOnly"))
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -25,9 +25,6 @@
|
|||
|
||||
using namespace VPE;
|
||||
|
||||
|
||||
|
||||
|
||||
VWidgetProperty::VWidgetProperty(const QString& name, QWidget* widget)
|
||||
: VEmptyProperty(new VWidgetPropertyPrivate(name, QVariant::Invalid, widget))
|
||||
{
|
||||
|
@ -47,8 +44,10 @@ void VWidgetProperty::setWidget(QWidget* widget)
|
|||
{
|
||||
VWidgetPropertyPrivate* tmpDPtr = static_cast<VWidgetPropertyPrivate*>(d_ptr);
|
||||
QWidget* tmpOldWidget = tmpDPtr->Widget.data();
|
||||
if(tmpOldWidget)
|
||||
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()));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
#include "vpropertyexplorer_global.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace VPE {
|
||||
namespace VPE
|
||||
{
|
||||
|
||||
class VProperty;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -45,7 +45,7 @@ VProperty::~VProperty()
|
|||
{
|
||||
setParent(nullptr);
|
||||
|
||||
while(!d_ptr->Children.isEmpty())
|
||||
while (!d_ptr->Children.isEmpty())
|
||||
{
|
||||
VProperty* tmpChild = d_ptr->Children.takeLast();
|
||||
delete tmpChild;
|
||||
|
@ -62,12 +62,18 @@ QString VProperty::type() const
|
|||
//! Get the data how it should be displayed
|
||||
QVariant VProperty::data (int column, int role) const
|
||||
{
|
||||
if(column == DPC_Name && Qt::DisplayRole == role)
|
||||
if (column == DPC_Name && Qt::DisplayRole == role)
|
||||
{
|
||||
return QVariant(d_ptr->Name);
|
||||
else if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
|
||||
}
|
||||
else if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
|
||||
{
|
||||
return d_ptr->VariantValue;
|
||||
else if(Qt::ToolTipRole == role)
|
||||
}
|
||||
else if (Qt::ToolTipRole == role)
|
||||
{
|
||||
return QVariant(d_ptr->Description);
|
||||
}
|
||||
else
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -75,7 +81,7 @@ QVariant VProperty::data (int column, int role) const
|
|||
bool VProperty::setData(const QVariant &data, int role)
|
||||
{
|
||||
bool tmpResult = false;
|
||||
if(Qt::EditRole == role)
|
||||
if (Qt::EditRole == role)
|
||||
{
|
||||
tmpResult = (d_ptr->VariantValue != data);
|
||||
setValue(data);
|
||||
|
@ -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);
|
||||
|
@ -111,12 +119,15 @@ QWidget* VProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& o
|
|||
|
||||
bool VProperty::setEditorData(QWidget* editor)
|
||||
{
|
||||
if(!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);
|
||||
|
@ -129,13 +140,17 @@ bool VProperty::setEditorData(QWidget* editor)
|
|||
//! Gets the data from the widget
|
||||
QVariant VProperty::getEditorData(QWidget* editor) const
|
||||
{
|
||||
if(!editor)
|
||||
if (!editor)
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QByteArray n = editor->metaObject()->userProperty().name();
|
||||
|
||||
if (!n.isEmpty())
|
||||
{
|
||||
return editor->property(n);
|
||||
}
|
||||
else
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -143,10 +158,14 @@ QVariant VProperty::getEditorData(QWidget* editor) const
|
|||
//! Returns item flags
|
||||
Qt::ItemFlags VProperty::flags(int column) const
|
||||
{
|
||||
if(column == DPC_Name)
|
||||
if (column == DPC_Name)
|
||||
{
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
else if(column == DPC_Data)
|
||||
}
|
||||
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()
|
||||
{
|
||||
|
@ -220,8 +235,10 @@ const QList<VProperty*>& VProperty::getChildren() const
|
|||
//! Returns the child at a certain row
|
||||
VProperty* VProperty::getChild(int row) const
|
||||
{
|
||||
if(row >= 0 && row < getRowCount())
|
||||
if (row >= 0 && row < getRowCount())
|
||||
{
|
||||
return d_ptr->Children.at(row);
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -241,25 +258,33 @@ VProperty* VProperty::getParent() const
|
|||
//! Sets the parent of this property
|
||||
void VProperty::setParent(VProperty* parent)
|
||||
{
|
||||
if(d_ptr->Parent == parent)
|
||||
if (d_ptr->Parent == parent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
VProperty* oldParent = d_ptr->Parent;
|
||||
d_ptr->Parent = parent;
|
||||
|
||||
if(oldParent)
|
||||
if (oldParent)
|
||||
{
|
||||
oldParent->removeChild(this);
|
||||
}
|
||||
|
||||
if(d_ptr->Parent && d_ptr->Parent->getChildRow(this) == -1)
|
||||
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)
|
||||
if (child && child->getParent() != this)
|
||||
{
|
||||
child->setParent(this);
|
||||
}
|
||||
|
||||
if(!d_ptr->Children.contains(child) && child != nullptr)
|
||||
if (!d_ptr->Children.contains(child) && child != nullptr)
|
||||
{
|
||||
d_ptr->Children.push_back(child);
|
||||
return d_ptr->Children.count()-1;
|
||||
|
@ -275,8 +300,10 @@ void VProperty::removeChild(VProperty* child)
|
|||
{
|
||||
d_ptr->Children.removeAll(child);
|
||||
|
||||
if(child && child->getParent() == this)
|
||||
if (child && child->getParent() == this)
|
||||
{
|
||||
child->setParent(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
//! Returns the row the child has
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -346,8 +373,10 @@ QStringList VProperty::getSettingKeys() const
|
|||
|
||||
VProperty* VProperty::clone(bool include_children, VProperty* container) const
|
||||
{
|
||||
if(!container)
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -38,10 +38,11 @@ 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())
|
||||
if (index.isValid())
|
||||
{
|
||||
VProperty* tmpProperty = reinterpret_cast<VProperty*>(index.internalPointer());
|
||||
tmpWidget = tmpProperty->createEditor(parent, option, this);
|
||||
|
@ -55,28 +56,32 @@ QWidget* VPropertyDelegate::createEditor (QWidget* parent, const QStyleOptionVie
|
|||
void VPropertyDelegate::setEditorData (QWidget * editor, const QModelIndex & index) const
|
||||
{
|
||||
bool done = false;
|
||||
if(index.isValid() && editor)
|
||||
if (index.isValid() && editor)
|
||||
{
|
||||
VProperty* tmpProperty = reinterpret_cast<VProperty*>(index.internalPointer());
|
||||
done = tmpProperty->setEditorData(editor);
|
||||
}
|
||||
|
||||
if(!done)
|
||||
if (!done)
|
||||
{
|
||||
QStyledItemDelegate::setEditorData(editor, index);
|
||||
}
|
||||
}
|
||||
|
||||
//! Updates the index data
|
||||
void VPropertyDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const
|
||||
{
|
||||
QVariant tmpData;
|
||||
if(index.isValid() && editor)
|
||||
if (index.isValid() && editor)
|
||||
{
|
||||
VProperty* tmpProperty = reinterpret_cast<VProperty*>(index.internalPointer());
|
||||
tmpData = tmpProperty->getEditorData(editor);
|
||||
}
|
||||
|
||||
if(tmpData.isNull())
|
||||
if (tmpData.isNull())
|
||||
{
|
||||
QStyledItemDelegate::setModelData(editor, model, index);
|
||||
}
|
||||
else
|
||||
model->setData(index, tmpData);
|
||||
}
|
||||
|
@ -86,8 +91,10 @@ QSize VPropertyDelegate::sizeHint (const QStyleOptionViewItem& option, const QMo
|
|||
QSize tmpStandardSizeHint = QStyledItemDelegate::sizeHint(option, index);
|
||||
tmpStandardSizeHint.setHeight(tmpStandardSizeHint.height() + 1);
|
||||
|
||||
if(RowHeight > 0)
|
||||
if (RowHeight > 0)
|
||||
{
|
||||
return QSize(tmpStandardSizeHint.width(), AddRowHeight ? tmpStandardSizeHint.height() + RowHeight : RowHeight);
|
||||
}
|
||||
else
|
||||
return tmpStandardSizeHint;
|
||||
}
|
||||
|
@ -101,11 +108,15 @@ void VPropertyDelegate::setRowHeight(int height, bool add_to_standard)
|
|||
void VPropertyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||
{
|
||||
bool done = false;
|
||||
if(index.isValid() && index.column() == 1)
|
||||
if (index.isValid() && index.column() == 1)
|
||||
{
|
||||
done = reinterpret_cast<VProperty*>(index.internalPointer())->paint(painter, option, index, this);
|
||||
}
|
||||
|
||||
if(!done)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
namespace VPE {
|
||||
namespace VPE
|
||||
{
|
||||
|
||||
class VPROPERTYEXPLORERSHARED_EXPORT VPropertyDelegate : public QStyledItemDelegate
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
@ -47,14 +48,18 @@ VPropertyFactoryManager::~VPropertyFactoryManager()
|
|||
|
||||
|
||||
delete d_ptr;
|
||||
if(this == DefaultManager)
|
||||
if (this == DefaultManager)
|
||||
{
|
||||
DefaultManager = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void VPropertyFactoryManager::registerFactory(const QString& type, VAbstractPropertyFactory* factory)
|
||||
{
|
||||
if(type.isEmpty())
|
||||
if (type.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove old factory
|
||||
unregisterFactory(getFactory(type), type, true);
|
||||
|
@ -62,26 +67,40 @@ 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)
|
||||
if (!factory)
|
||||
{
|
||||
return;
|
||||
|
||||
if(!type.isEmpty()) {
|
||||
// Remove all occurances
|
||||
QString tmpKey;
|
||||
do {
|
||||
tmpKey = d_ptr->Factories.key(factory, QString());
|
||||
if(!tmpKey.isEmpty()) d_ptr->Factories.remove(tmpKey);
|
||||
} while(!tmpKey.isEmpty());
|
||||
} else {
|
||||
// Only remove one type
|
||||
if(d_ptr->Factories.value(type, NULL) == factory)
|
||||
d_ptr->Factories.remove(type);
|
||||
}
|
||||
|
||||
if(delete_if_unused && !isRegistered(factory))
|
||||
if (!type.isEmpty())
|
||||
{
|
||||
// Remove all occurances
|
||||
QString tmpKey;
|
||||
do
|
||||
{
|
||||
tmpKey = d_ptr->Factories.key(factory, QString());
|
||||
if (!tmpKey.isEmpty())
|
||||
{
|
||||
d_ptr->Factories.remove(tmpKey);
|
||||
}
|
||||
} while(!tmpKey.isEmpty());
|
||||
}
|
||||
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,18 +114,23 @@ 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())
|
||||
if (!default_value.isEmpty())
|
||||
{
|
||||
tmpResult->deserialize(default_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,7 +139,8 @@ VProperty* VPropertyFactoryManager::createProperty(const QString& type, const QS
|
|||
|
||||
VPropertyFactoryManager *VPropertyFactoryManager::getDefaultManager()
|
||||
{
|
||||
if(!DefaultManager) {
|
||||
if (!DefaultManager)
|
||||
{
|
||||
DefaultManager = new VPropertyFactoryManager();
|
||||
/*VStandardPropertyFactory* tmpStandardProp = */new VStandardPropertyFactory(DefaultManager);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -26,11 +26,13 @@
|
|||
#include <QMap>
|
||||
#include <QString>
|
||||
|
||||
namespace VPE {
|
||||
namespace VPE
|
||||
{
|
||||
|
||||
class VAbstractPropertyFactory;
|
||||
|
||||
class VPropertyFactoryManagerPrivate {
|
||||
class VPropertyFactoryManagerPrivate
|
||||
{
|
||||
public:
|
||||
QMap<QString, VAbstractPropertyFactory*> Factories;
|
||||
|
||||
|
|
|
@ -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())
|
||||
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();
|
||||
}
|
||||
|
@ -130,8 +136,10 @@ void VPropertyFormView::modelDestroyed()
|
|||
|
||||
void VPropertyFormView::dataChanged(const QModelIndex &top_left, const QModelIndex &bottom_right)
|
||||
{
|
||||
if(static_cast<VPropertyFormViewPrivate*>(d_ptr)->IgnoreDataChangedSignal)
|
||||
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;
|
||||
|
@ -149,8 +158,10 @@ void VPropertyFormView::dataSubmitted(VProperty *property)
|
|||
void VPropertyFormView::showEvent(QShowEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
if(static_cast<VPropertyFormViewPrivate*>(d_ptr)->NeedsRebuild)
|
||||
if (static_cast<VPropertyFormViewPrivate*>(d_ptr)->NeedsRebuild)
|
||||
{
|
||||
build();
|
||||
}
|
||||
static_cast<VPropertyFormViewPrivate*>(d_ptr)->NeedsRebuild = false;
|
||||
}
|
||||
|
||||
|
@ -159,22 +170,29 @@ void VPropertyFormView::updatePropertyList()
|
|||
VPropertyModel* tmpModel = static_cast<VPropertyFormViewPrivate*>(d_ptr)->Model;
|
||||
VPropertySet* tmpSet = static_cast<VPropertyFormViewPrivate*>(d_ptr)->PropertySet;
|
||||
|
||||
if(tmpModel && tmpModel->getPropertySet())
|
||||
if (tmpModel && tmpModel->getPropertySet())
|
||||
{
|
||||
d_ptr->Properties = tmpModel->getPropertySet()->getRootProperties();
|
||||
else if(tmpSet)
|
||||
}
|
||||
else if (tmpSet)
|
||||
{
|
||||
d_ptr->Properties = tmpSet->getRootProperties();
|
||||
}
|
||||
else
|
||||
d_ptr->Properties.clear();
|
||||
|
||||
if(isVisible())
|
||||
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;
|
||||
}
|
||||
|
@ -186,14 +204,17 @@ void VPropertyFormView::removeModelAndSet()
|
|||
|
||||
void VPropertyFormView::connectPropertyFormWidget(VPropertyFormWidget *widget)
|
||||
{
|
||||
if(!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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
@ -96,6 +98,6 @@ protected:
|
|||
|
||||
};
|
||||
|
||||
} // Namespace VPE
|
||||
} // Namespace VPE
|
||||
|
||||
#endif // VPROPERTYFORMVIEW_H
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
|
||||
#include "vpropertyformwidget_p.h"
|
||||
|
||||
namespace VPE {
|
||||
namespace VPE
|
||||
{
|
||||
|
||||
class VPropertyModel;
|
||||
class VPropertySet;
|
||||
|
|
|
@ -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) {
|
||||
if(child->widget())
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -137,8 +156,10 @@ void VPropertyFormWidget::buildEditor(VProperty* property, QFormLayout* formLayo
|
|||
// Add property (no child properties)
|
||||
// Create the editor (if it doesn't work, create empty widget)
|
||||
QWidget* tmpEditor = property->createEditor(this, QStyleOptionViewItem(), nullptr);
|
||||
if(!tmpEditor)
|
||||
if (!tmpEditor)
|
||||
{
|
||||
tmpEditor = new QWidget(this);
|
||||
}
|
||||
|
||||
// set tooltip and whats this
|
||||
tmpEditor->setToolTip(property->getDescription());
|
||||
|
@ -166,25 +187,34 @@ void VPropertyFormWidget::buildEditor(VProperty* property, QFormLayout* formLayo
|
|||
|
||||
void VPropertyFormWidget::commitData()
|
||||
{
|
||||
for(int i = 0; i < d_ptr->Properties.count(); ++i)
|
||||
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)
|
||||
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)
|
||||
if (tmpEditorWidget.FormWidget)
|
||||
{
|
||||
tmpEditorWidget.FormWidget->commitData();
|
||||
else if(tmpEditorWidget.Editor && tmpProperty)
|
||||
}
|
||||
else if (tmpEditorWidget.Editor && tmpProperty)
|
||||
{
|
||||
QVariant newValue = tmpProperty->getEditorData(tmpEditorWidget.Editor);
|
||||
QVariant oldValue = tmpProperty->data(VProperty::DPC_Data, Qt::EditRole);
|
||||
|
@ -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)
|
||||
if (tmpEditorWidget.FormWidget)
|
||||
{
|
||||
tmpEditorWidget.FormWidget->loadData();
|
||||
else if(tmpEditorWidget.Editor && tmpProperty) {
|
||||
}
|
||||
else if (tmpEditorWidget.Editor && tmpProperty)
|
||||
{
|
||||
tmpProperty->setEditorData(tmpEditorWidget.Editor);
|
||||
}
|
||||
}
|
||||
|
@ -228,18 +264,24 @@ void VPropertyFormWidget::setCommitBehaviour(bool auto_commit)
|
|||
d_ptr->UpdateEditors = auto_commit;
|
||||
|
||||
QList<VPropertyFormWidget*> tmpChildFormWidgets = getChildPropertyFormWidgets();
|
||||
foreach(VPropertyFormWidget* tmpChild, tmpChildFormWidgets) {
|
||||
if(tmpChild)
|
||||
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) {
|
||||
if(tmpEditorWidget.FormWidget)
|
||||
foreach(const VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget, d_ptr->EditorWidgets)
|
||||
{
|
||||
if (tmpEditorWidget.FormWidget)
|
||||
{
|
||||
tmpResult.append(tmpEditorWidget.FormWidget);
|
||||
}
|
||||
}
|
||||
|
||||
return tmpResult;
|
||||
|
@ -247,15 +289,21 @@ QList<VPropertyFormWidget *> VPropertyFormWidget::getChildPropertyFormWidgets()
|
|||
|
||||
bool VPropertyFormWidget::eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
if(!d_ptr->UpdateEditors)
|
||||
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,20 +315,27 @@ 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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return QGroupBox::eventFilter(object, event);
|
||||
|
@ -292,12 +347,17 @@ bool VPropertyFormWidget::eventFilter(QObject *object, QEvent *event)
|
|||
|
||||
void VPropertyFormWidget::commitData(QWidget *editor)
|
||||
{
|
||||
if(!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)
|
||||
if (tmpEditorWidget.Editor == editor)
|
||||
{
|
||||
commitData(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
@ -92,6 +95,6 @@ protected:
|
|||
|
||||
};
|
||||
|
||||
} // Namespace VPE
|
||||
} // Namespace VPE
|
||||
|
||||
#endif // VPROPERTYFORMWIDGET_H
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -40,8 +40,10 @@ VPropertyModel::VPropertyModel(QObject * parent) :
|
|||
|
||||
VPropertyModel::~VPropertyModel()
|
||||
{
|
||||
if(d_ptr->Properties)
|
||||
if (d_ptr->Properties)
|
||||
{
|
||||
delete d_ptr->Properties;
|
||||
}
|
||||
|
||||
delete d_ptr;
|
||||
}
|
||||
|
@ -49,13 +51,18 @@ VPropertyModel::~VPropertyModel()
|
|||
//! Adds the property to the model and attaches it to the parentid
|
||||
bool VPropertyModel::addProperty(VProperty* property, const QString& id, const QString &parentid, bool emitsignals)
|
||||
{
|
||||
if(!property)
|
||||
if (!property)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!d_ptr->Properties) // If not existant, create property set
|
||||
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);
|
||||
|
@ -63,20 +70,25 @@ bool VPropertyModel::addProperty(VProperty* property, const QString& id, const Q
|
|||
|
||||
d_ptr->Properties->addProperty(property, id, parentid);
|
||||
|
||||
if(emitsignals)
|
||||
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))
|
||||
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,17 +132,24 @@ 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)
|
||||
if (parents_row >= 0)
|
||||
{
|
||||
return createIndex(parents_row, 0, parentItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,8 +160,10 @@ QModelIndex VPropertyModel::parent ( const QModelIndex & index ) const
|
|||
Qt::ItemFlags VPropertyModel::flags (const QModelIndex& index) const
|
||||
{
|
||||
VProperty* tmpProperty = getProperty(index);
|
||||
if(!tmpProperty)
|
||||
if (!tmpProperty)
|
||||
{
|
||||
return Qt::NoItemFlags;
|
||||
}
|
||||
else
|
||||
return tmpProperty->flags(index.column());
|
||||
}
|
||||
|
@ -145,15 +172,19 @@ 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)
|
||||
if (tmpHasChanged)
|
||||
{
|
||||
emit onDataChangedByEditor(tmpProperty);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -165,8 +196,10 @@ bool VPropertyModel::setData (const QModelIndex& index, const QVariant& value, i
|
|||
QVariant VPropertyModel::data ( const QModelIndex & index, int role ) const
|
||||
{
|
||||
VProperty* tmpProperty = getProperty(index);
|
||||
if(!tmpProperty)
|
||||
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)
|
||||
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)
|
||||
if (tmpParent)
|
||||
{
|
||||
return tmpParent->getRowCount();
|
||||
}
|
||||
}
|
||||
|
||||
// Return the root property count
|
||||
if(d_ptr->Properties)
|
||||
if (d_ptr->Properties)
|
||||
{
|
||||
return d_ptr->Properties->getRootPropertyCount();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -214,11 +261,14 @@ 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();
|
||||
{
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
VProperty* parentItem = property->getParent();
|
||||
int row = 0;
|
||||
|
||||
if(parentItem) {
|
||||
if (parentItem)
|
||||
{
|
||||
row = parentItem->getChildRow(property);
|
||||
}
|
||||
|
||||
|
@ -247,7 +300,7 @@ QModelIndex VPropertyModel::getIndexFromProperty(VProperty* property, int column
|
|||
void VPropertyModel::onDataChangedByModel(VProperty* property)
|
||||
{
|
||||
QModelIndex tmpIndex = getIndexFromProperty(property, 1);
|
||||
if(tmpIndex.isValid())
|
||||
if (tmpIndex.isValid())
|
||||
{
|
||||
emit dataChanged(tmpIndex, tmpIndex);
|
||||
emit onDataChangedByEditor(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;
|
||||
}
|
||||
|
@ -278,14 +337,17 @@ VPropertySet *VPropertyModel::takePropertySet(VPropertySet *new_property_set, bo
|
|||
void VPropertyModel::setPropertySet(VPropertySet *property_set, bool emit_signals)
|
||||
{
|
||||
VPropertySet* tmpOldPropertySet = takePropertySet(property_set, emit_signals);
|
||||
if(tmpOldPropertySet)
|
||||
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();
|
||||
|
|
|
@ -29,17 +29,18 @@
|
|||
|
||||
#include "vproperty.h"
|
||||
|
||||
namespace VPE {
|
||||
namespace VPE
|
||||
{
|
||||
|
||||
class VPropertyModelPrivate;
|
||||
class VPropertySet;
|
||||
|
||||
//! \brief This is the base model for managing all the properties
|
||||
//! and passing them to the view.
|
||||
//! \brief This is the base model for managing all the properties
|
||||
//! and passing them to the view.
|
||||
//!
|
||||
//! When you create your own "proxy models", this is the place to
|
||||
//! start: just subclass VPropertyModel and extend the new class.
|
||||
//! Have a look at existing examples of proxies.
|
||||
//! When you create your own "proxy models", this is the place to
|
||||
//! start: just subclass VPropertyModel and extend the new class.
|
||||
//! Have a look at existing examples of proxies.
|
||||
//!
|
||||
//! <strong>Note that in this context, the term "proxy model" does not refer
|
||||
//! to VProxyModel as that is another concept.</strong>
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -41,8 +41,10 @@ VPropertySet::~VPropertySet()
|
|||
bool VPropertySet::addProperty(VProperty *property, const QString &id, const QString &parentid)
|
||||
{
|
||||
// Check if the property to add is not a null pointer
|
||||
if(!property)
|
||||
if (!property)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
VProperty* tmpParent = parentid.isEmpty() ? NULL : getProperty(parentid);
|
||||
return addProperty(property, id, tmpParent);
|
||||
|
@ -51,31 +53,44 @@ bool VPropertySet::addProperty(VProperty *property, const QString &id, const QSt
|
|||
bool VPropertySet::addProperty(VProperty *property, const QString &id, VProperty *parent_property)
|
||||
{
|
||||
// Check if the property to add is not a null pointer
|
||||
if(!property)
|
||||
if (!property)
|
||||
{
|
||||
return false;
|
||||
|
||||
QString tmpOldID = getPropertyID(property);
|
||||
if(!tmpOldID.isEmpty())
|
||||
d_ptr->Properties.remove(tmpOldID);
|
||||
|
||||
if(parent_property)
|
||||
parent_property->addChild(property);
|
||||
else {
|
||||
d_ptr->RootProperties.append(property);
|
||||
if(property->getParent())
|
||||
property->getParent()->removeChild(property);
|
||||
}
|
||||
|
||||
if(!id.isEmpty())
|
||||
QString tmpOldID = getPropertyID(property);
|
||||
if (!tmpOldID.isEmpty())
|
||||
{
|
||||
d_ptr->Properties.remove(tmpOldID);
|
||||
}
|
||||
|
||||
if (parent_property)
|
||||
{
|
||||
parent_property->addChild(property);
|
||||
}
|
||||
else
|
||||
{
|
||||
d_ptr->RootProperties.append(property);
|
||||
if (property->getParent())
|
||||
{
|
||||
property->getParent()->removeChild(property);
|
||||
}
|
||||
}
|
||||
|
||||
if (!id.isEmpty())
|
||||
{
|
||||
d_ptr->Properties.insert(id, property);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VPropertySet::hasProperty(VProperty *property) const
|
||||
{
|
||||
if(!property)
|
||||
if (!property)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return hasProperty(property, NULL);
|
||||
}
|
||||
|
@ -97,8 +112,10 @@ VProperty *VPropertySet::takeProperty(const QString &id)
|
|||
void VPropertySet::removeProperty(const QString &id)
|
||||
{
|
||||
VProperty* tmpProp = takeProperty(id);
|
||||
if(tmpProp)
|
||||
if (tmpProp)
|
||||
{
|
||||
delete tmpProp;
|
||||
}
|
||||
}
|
||||
|
||||
void VPropertySet::removeProperty(VProperty* prop, bool delete_property)
|
||||
|
@ -107,11 +124,14 @@ 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)
|
||||
if (delete_property)
|
||||
{
|
||||
delete prop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,15 +158,20 @@ 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) {
|
||||
if(tmpCurrentProp == (*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,35 +211,47 @@ VPropertySet* VPropertySet::clone() const
|
|||
return tmpResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool VPropertySet::hasProperty(VProperty *property, VProperty *parent) const
|
||||
{
|
||||
if(!property)
|
||||
if (!property)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const QList<VProperty*>& tmpChildrenList = (parent != NULL ? parent->getChildren() : d_ptr->RootProperties);
|
||||
foreach(VProperty* tmpProp, tmpChildrenList) {
|
||||
if(!tmpProp)
|
||||
foreach(VProperty* tmpProp, tmpChildrenList)
|
||||
{
|
||||
if (!tmpProp)
|
||||
{
|
||||
continue;
|
||||
else if(tmpProp == property || hasProperty(property, tmpProp))
|
||||
}
|
||||
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))
|
||||
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)
|
||||
for (int i = 0; i < property_to_clone->getRowCount(); ++i)
|
||||
{
|
||||
cloneProperty(property_to_clone->getChild(i), tmpNewProperty, output_set);
|
||||
}
|
||||
}
|
||||
|
||||
void VPropertySet::removePropertyFromSet(VProperty *prop)
|
||||
|
|
|
@ -28,15 +28,16 @@
|
|||
|
||||
#include "vproperty.h"
|
||||
|
||||
namespace VPE {
|
||||
namespace VPE
|
||||
{
|
||||
|
||||
// Forward declaration
|
||||
class VPropertySetPrivate;
|
||||
|
||||
// todo: better description
|
||||
//! \brief VPropertySet is a simple class for managing a set of properties.
|
||||
//! If you don't need all the Model-functionality, chose this class
|
||||
//! over VPropertyModel.
|
||||
//! \brief VPropertySet is a simple class for managing a set of properties.
|
||||
//! If you don't need all the Model-functionality, chose this class
|
||||
//! over VPropertyModel.
|
||||
//!
|
||||
|
||||
//!
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -38,15 +38,19 @@ VPropertyTreeView::VPropertyTreeView(VPropertyModel *model, QWidget *parent)
|
|||
{
|
||||
init();
|
||||
|
||||
if(model)
|
||||
if (model)
|
||||
{
|
||||
setModel(model);
|
||||
}
|
||||
}
|
||||
|
||||
VPropertyTreeView::VPropertyTreeView(VPropertyTreeViewPrivate *d, bool init_, QWidget *parent)
|
||||
: QTreeView(parent), d_ptr(d)
|
||||
{
|
||||
if(init_)
|
||||
if (init_)
|
||||
{
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
VPropertyTreeView::~VPropertyTreeView()
|
||||
|
@ -73,5 +77,3 @@ void VPropertyTreeView::init()
|
|||
|
||||
setEditTriggers(QAbstractItemView::CurrentChanged | QAbstractItemView::SelectedClicked);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
#include <QTreeView>
|
||||
#include "vpropertyexplorer_global.h"
|
||||
|
||||
namespace VPE {
|
||||
namespace VPE
|
||||
{
|
||||
|
||||
class VPropertyTreeViewPrivate;
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
#include <QMap>
|
||||
#include <QString>
|
||||
|
||||
namespace VPE {
|
||||
namespace VPE
|
||||
{
|
||||
|
||||
class VPropertyDelegate;
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,8 @@
|
|||
#include "vproperty.h"
|
||||
#include "vpropertyset.h"
|
||||
|
||||
namespace VPE {
|
||||
namespace VPE
|
||||
{
|
||||
|
||||
|
||||
class VPROPERTYEXPLORERSHARED_EXPORT VSerializedProperty
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
#include "vpropertyexplorer_global.h"
|
||||
#include "vabstractpropertyfactory.h"
|
||||
|
||||
namespace VPE {
|
||||
namespace VPE
|
||||
{
|
||||
|
||||
class VProperty;
|
||||
|
||||
|
|
|
@ -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,9 +46,12 @@ public:
|
|||
: VPropertyPrivate(), Widget(nullptr) {}
|
||||
|
||||
//! Destructor
|
||||
~VWidgetPropertyPrivate() {
|
||||
if(Widget)
|
||||
~VWidgetPropertyPrivate()
|
||||
{
|
||||
if (Widget)
|
||||
{
|
||||
Widget->deleteLater();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user