2014-08-26 19:23:08 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vtooloptionspropertybrowser.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 22 8, 2014
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2014 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vtooloptionspropertybrowser.h"
|
|
|
|
#include "tools/drawTools/drawtools.h"
|
|
|
|
#include "widgets/vapplication.h"
|
|
|
|
#include "widgets/vmaingraphicsview.h"
|
|
|
|
#include "visualization/vgraphicssimpletextitem.h"
|
|
|
|
#include "visualization/vcontrolpointspline.h"
|
2014-08-28 13:05:58 +02:00
|
|
|
#include "../libs/vpropertyexplorer/vproperties.h"
|
2014-08-29 11:19:11 +02:00
|
|
|
#include "vformulaproperty.h"
|
|
|
|
#include "../container/vformula.h"
|
2014-08-26 19:23:08 +02:00
|
|
|
|
|
|
|
#include <QDockWidget>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
|
|
|
using namespace VPE;
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VToolOptionsPropertyBrowser::VToolOptionsPropertyBrowser(QDockWidget *parent)
|
|
|
|
:QObject(parent),
|
|
|
|
currentItem(nullptr),
|
|
|
|
propertyToId(QMap<VProperty *, QString>()),
|
|
|
|
idToProperty(QMap<QString, VProperty *>())
|
|
|
|
{
|
|
|
|
PropertyModel = new VPropertyModel(this);
|
2014-08-26 20:31:28 +02:00
|
|
|
TreeView = new VPropertyFormView(PropertyModel, parent);
|
2014-08-26 19:23:08 +02:00
|
|
|
TreeView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
2014-08-26 20:31:28 +02:00
|
|
|
QScrollArea *scroll = new QScrollArea(parent);
|
2014-08-26 19:23:08 +02:00
|
|
|
scroll->setWidgetResizable(true);
|
|
|
|
scroll->setWidget(TreeView);
|
|
|
|
|
2014-08-26 20:31:28 +02:00
|
|
|
parent->setWidget(scroll);
|
2014-08-26 19:23:08 +02:00
|
|
|
|
|
|
|
connect(PropertyModel, SIGNAL(onDataChangedByEditor(VProperty*)), this, SLOT(userChangedData(VProperty*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item)
|
|
|
|
{
|
2014-08-26 21:34:27 +02:00
|
|
|
if (currentItem == item)
|
|
|
|
{
|
|
|
|
UpdateOptions();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-26 22:04:01 +02:00
|
|
|
PropertyModel->clear();
|
2014-08-26 19:23:08 +02:00
|
|
|
propertyToId.clear();
|
|
|
|
idToProperty.clear();
|
|
|
|
|
|
|
|
currentItem = item;
|
2014-08-26 22:04:01 +02:00
|
|
|
|
2014-08-26 19:23:08 +02:00
|
|
|
if (currentItem == nullptr)
|
|
|
|
{
|
2014-08-27 09:24:41 +02:00
|
|
|
QDockWidget *parent = qobject_cast<QDockWidget *>(this->parent());
|
|
|
|
parent->setWindowTitle(tr("Tool options"));
|
2014-08-26 19:23:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowItemOptions(currentItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolOptionsPropertyBrowser::userChangedData(VProperty *property)
|
|
|
|
{
|
2014-08-27 14:39:54 +02:00
|
|
|
VProperty *prop = property;
|
|
|
|
if (!propertyToId.contains(prop))
|
2014-08-26 19:23:08 +02:00
|
|
|
{
|
2014-08-27 14:39:54 +02:00
|
|
|
if (!propertyToId.contains(prop->getParent()))// Maybe we know parent
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prop = prop->getParent();
|
|
|
|
}
|
2014-08-26 19:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!currentItem)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-28 13:05:58 +02:00
|
|
|
QVariant variant = prop->data(VProperty::DPC_Data, Qt::DisplayRole);
|
2014-08-26 19:23:08 +02:00
|
|
|
|
2014-08-27 14:39:54 +02:00
|
|
|
QString id = propertyToId[prop];
|
2014-08-26 19:23:08 +02:00
|
|
|
switch (currentItem->type())
|
|
|
|
{
|
|
|
|
case VToolSinglePoint::Type:
|
|
|
|
{
|
|
|
|
if (id == QLatin1String("name"))
|
|
|
|
{
|
2014-08-28 13:05:58 +02:00
|
|
|
SetPointName<VToolSinglePoint>(variant.toString());
|
2014-08-26 19:23:08 +02:00
|
|
|
}
|
2014-08-27 14:39:54 +02:00
|
|
|
else if (id == QLatin1String("position"))
|
2014-08-26 19:23:08 +02:00
|
|
|
{
|
2014-08-27 14:39:54 +02:00
|
|
|
currentItem->setPos(variant.toPointF());
|
2014-08-26 19:23:08 +02:00
|
|
|
}
|
2014-08-28 10:17:36 +02:00
|
|
|
// else if (id == QLatin1String("list"))
|
|
|
|
// {
|
|
|
|
// qDebug()<<prop->data(VProperty::DPC_Data, Qt::DisplayRole);
|
|
|
|
// }
|
2014-08-26 19:23:08 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-08-28 13:05:58 +02:00
|
|
|
case VToolEndLine::Type:
|
|
|
|
{
|
2014-08-28 13:23:28 +02:00
|
|
|
VToolEndLine *i = qgraphicsitem_cast<VToolEndLine *>(currentItem);
|
2014-08-28 13:05:58 +02:00
|
|
|
if (id == QLatin1String("name"))
|
|
|
|
{
|
|
|
|
SetPointName<VToolEndLine>(variant.toString());
|
|
|
|
}
|
|
|
|
else if (id == QLatin1String("basePoint"))
|
|
|
|
{
|
|
|
|
i->setBasePointId(variant.toUInt());
|
|
|
|
}
|
2014-08-28 13:23:28 +02:00
|
|
|
else if (id == QLatin1String("lineType"))
|
|
|
|
{
|
|
|
|
i->setTypeLine(variant.toString());
|
|
|
|
}
|
2014-08-29 11:19:11 +02:00
|
|
|
else if (id == QLatin1String("formulaLength"))
|
|
|
|
{
|
|
|
|
VFormula formula = variant.value<VFormula>();
|
|
|
|
if (formula.error() == false)
|
|
|
|
{
|
|
|
|
i->setFormulaLength(variant.value<VFormula>().getFormula());
|
|
|
|
}
|
|
|
|
}
|
2014-08-28 13:05:58 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-08-26 19:23:08 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
qApp->getSceneView()->update();
|
|
|
|
}
|
|
|
|
|
2014-08-28 13:05:58 +02:00
|
|
|
template<class Tool>
|
|
|
|
void VToolOptionsPropertyBrowser::SetPointName(const QString &name)
|
|
|
|
{
|
|
|
|
if (Tool *i = qgraphicsitem_cast<Tool *>(currentItem))
|
|
|
|
{
|
|
|
|
if (name == i->name())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name.isEmpty())
|
|
|
|
{
|
|
|
|
idToProperty[QLatin1String("name")]->setValue(i->name());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//TODO check if label name is unique
|
|
|
|
i->setName(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning()<<"Can't cast item";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-26 19:23:08 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolOptionsPropertyBrowser::UpdateOptions()
|
|
|
|
{
|
|
|
|
if (currentItem == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (currentItem->type())
|
|
|
|
{
|
|
|
|
case VToolSinglePoint::Type:
|
|
|
|
{
|
|
|
|
VToolSinglePoint *i = qgraphicsitem_cast<VToolSinglePoint *>(currentItem);
|
|
|
|
idToProperty[QLatin1String("name")]->setValue(i->name());
|
2014-08-27 14:39:54 +02:00
|
|
|
idToProperty[QLatin1String("position")]->setValue(i->pos());
|
2014-08-26 19:23:08 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-08-28 13:05:58 +02:00
|
|
|
case VToolEndLine::Type:
|
|
|
|
{
|
|
|
|
VToolEndLine *i = qgraphicsitem_cast<VToolEndLine *>(currentItem);
|
|
|
|
idToProperty[QLatin1String("name")]->setValue(i->name());
|
|
|
|
idToProperty[QLatin1String("basePoint")]->setValue(i->getBasePointId());
|
|
|
|
|
2014-08-28 13:23:28 +02:00
|
|
|
QStringList styles = VAbstractTool::Styles();
|
|
|
|
qint32 index = styles.indexOf(i->getLineType());
|
|
|
|
idToProperty[QLatin1String("lineType")]->setValue(index);
|
|
|
|
|
2014-08-29 11:19:11 +02:00
|
|
|
VFormula formula(i->getFormulaLength(), i->getData());
|
|
|
|
formula.setCheckZero(true);
|
|
|
|
formula.setToolId(i->getId());
|
|
|
|
formula.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit()));
|
|
|
|
QVariant value;
|
|
|
|
value.setValue(formula);
|
|
|
|
idToProperty[QLatin1String("formulaLength")]->setValue(value);
|
|
|
|
|
2014-08-28 13:05:58 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-08-26 19:23:08 +02:00
|
|
|
case VGraphicsSimpleTextItem::Type:
|
|
|
|
ShowItemOptions(currentItem->parentItem());
|
|
|
|
break;
|
|
|
|
case VControlPointSpline::Type:
|
|
|
|
ShowItemOptions(currentItem->parentItem());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolOptionsPropertyBrowser::AddProperty(VProperty *property, const QString &id)
|
|
|
|
{
|
|
|
|
propertyToId[property] = id;
|
|
|
|
idToProperty[id] = property;
|
2014-08-27 14:39:54 +02:00
|
|
|
PropertyModel->addProperty(property, id);
|
2014-08-26 19:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item)
|
|
|
|
{
|
|
|
|
switch (item->type())
|
|
|
|
{
|
|
|
|
case VToolSinglePoint::Type:
|
|
|
|
{
|
|
|
|
VToolSinglePoint *i = qgraphicsitem_cast<VToolSinglePoint *>(item);
|
2014-08-27 09:24:41 +02:00
|
|
|
QDockWidget *parent = qobject_cast<QDockWidget *>(this->parent());
|
|
|
|
parent->setWindowTitle(tr("Tool options (Base point)"));
|
2014-08-26 19:23:08 +02:00
|
|
|
|
|
|
|
VProperty* itemName = new VProperty(tr("Point name"));
|
|
|
|
itemName->setValue(i->name());
|
|
|
|
AddProperty(itemName, QLatin1String("name"));
|
|
|
|
|
2014-08-27 14:39:54 +02:00
|
|
|
VPointFProperty* itemPosition = new VPointFProperty(tr("Position"));
|
|
|
|
itemPosition->setValue(i->pos());
|
|
|
|
AddProperty(itemPosition, QLatin1String("position"));
|
2014-08-28 10:17:36 +02:00
|
|
|
|
2014-08-28 13:05:58 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VToolEndLine::Type:
|
|
|
|
{
|
|
|
|
VToolEndLine *i = qgraphicsitem_cast<VToolEndLine *>(item);
|
|
|
|
QDockWidget *parent = qobject_cast<QDockWidget *>(this->parent());
|
2014-08-28 13:23:28 +02:00
|
|
|
parent->setWindowTitle(tr("Tool options (Point at distance and angle)"));
|
2014-08-28 13:05:58 +02:00
|
|
|
|
|
|
|
VProperty* itemName = new VProperty(tr("Point name"));
|
|
|
|
itemName->setValue(i->name());
|
|
|
|
AddProperty(itemName, QLatin1String("name"));
|
|
|
|
|
|
|
|
VObjectProperty *pointsProperty = new VObjectProperty(tr("Base point"));
|
|
|
|
QMap<QString, quint32> pointsList = i->PointsList();
|
|
|
|
pointsProperty->setObjectsList(pointsList);
|
|
|
|
pointsProperty->setValue(i->getBasePointId());
|
|
|
|
AddProperty(pointsProperty, QLatin1String("basePoint"));
|
|
|
|
|
2014-08-28 13:23:28 +02:00
|
|
|
VEnumProperty *lineTypeProperty = new VEnumProperty(tr("Line type"));
|
|
|
|
lineTypeProperty->setLiterals(VAbstractTool::Styles());
|
|
|
|
QStringList styles = VAbstractTool::Styles();
|
|
|
|
qint32 index = styles.indexOf(i->getLineType());
|
|
|
|
lineTypeProperty->setValue(index);
|
|
|
|
AddProperty(lineTypeProperty, QLatin1String("lineType"));
|
2014-08-29 11:19:11 +02:00
|
|
|
|
|
|
|
VFormulaProperty* itemLength = new VFormulaProperty(tr("Length"));
|
|
|
|
VFormula formula(i->getFormulaLength(), i->getData());
|
|
|
|
formula.setCheckZero(true);
|
|
|
|
formula.setToolId(i->getId());
|
|
|
|
formula.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit()));
|
|
|
|
itemLength->setFormula(formula);
|
|
|
|
AddProperty(itemLength, QLatin1String("formulaLength"));
|
2014-08-26 19:23:08 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VGraphicsSimpleTextItem::Type:
|
|
|
|
currentItem = item->parentItem();
|
|
|
|
ShowItemOptions(currentItem);
|
|
|
|
break;
|
|
|
|
case VControlPointSpline::Type:
|
|
|
|
currentItem = item->parentItem();
|
|
|
|
ShowItemOptions(currentItem);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|