Property browser for tool Rotation.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-05-18 14:32:51 +03:00
parent 84a56545ea
commit 291c19d5a2
4 changed files with 185 additions and 20 deletions

View File

@ -490,7 +490,6 @@ void VToolOptionsPropertyBrowser::AddPropertyObjectName(Tool *i, const QString &
AddProperty(itemName, AttrName);
}
//---------------------------------------------------------------------------------------------------------------------
template<class Tool>
void VToolOptionsPropertyBrowser::AddPropertyPointName1(Tool *i, const QString &propertyName)
@ -511,6 +510,17 @@ void VToolOptionsPropertyBrowser::AddPropertyPointName2(Tool *i, const QString &
AddProperty(itemName, AttrName2);
}
//---------------------------------------------------------------------------------------------------------------------
template<class Tool>
void VToolOptionsPropertyBrowser::AddPropertyOperationSuffix(Tool *i, const QString &propertyName, bool readOnly)
{
auto itemSuffix = new VStringProperty(propertyName);
itemSuffix->setClearButtonEnable(true);
itemSuffix->setValue(i->Suffix());
itemSuffix->setReadOnly(readOnly);
AddProperty(itemSuffix, AttrSuffix);
}
//---------------------------------------------------------------------------------------------------------------------
template<class Tool>
void VToolOptionsPropertyBrowser::AddPropertyCrossPoint(Tool *i, const QString &propertyName)
@ -654,6 +664,43 @@ void VToolOptionsPropertyBrowser::SetPointName2(const QString &name)
}
}
//---------------------------------------------------------------------------------------------------------------------
template<class Tool>
void VToolOptionsPropertyBrowser::SetOperationSuffix(const QString &suffix)
{
if (Tool *item = qgraphicsitem_cast<Tool *>(currentItem))
{
if (suffix == item->Suffix())
{
return;
}
if (suffix.isEmpty())
{
idToProperty[AttrSuffix]->setValue(item->Suffix());
return;
}
QRegularExpression rx(NameRegExp());
const QVector<QString> names = item->GetNames(suffix);
for (int i=0; i < names.size(); ++i)
{
if (not rx.match(names.at(i)).hasMatch() || not VContainer::IsUnique(names.at(i)))
{
idToProperty[AttrSuffix]->setValue(item->Suffix());
}
else
{
item->SetSuffix(suffix);
}
}
}
else
{
qWarning()<<"Can't cast item";
}
}
//---------------------------------------------------------------------------------------------------------------------
template<class Type>
Type VToolOptionsPropertyBrowser::GetCrossPoint(const QVariant &value)
@ -1538,6 +1585,24 @@ void VToolOptionsPropertyBrowser::ChangeDataToolCurveIntersectAxis(VProperty *pr
void VToolOptionsPropertyBrowser::ChangeDataToolRotation(VProperty *property)
{
SCASSERT(property != nullptr)
QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole);
const QString id = propertyToId[property];
VToolRotation *i = qgraphicsitem_cast<VToolRotation *>(currentItem);
SCASSERT(i != nullptr);
switch (PropertiesList().indexOf(id))
{
case 38: // AttrSuffix
SetOperationSuffix<VToolRotation>(value.toString());
break;
case 5: // AttrAngle
i->SetFormulaAngle(value.value<VFormula>());
break;
default:
qWarning()<<"Unknown property type. id = "<<id;
break;
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -1927,6 +1992,10 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolRotation(QGraphicsItem *item)
{
VToolRotation *i = qgraphicsitem_cast<VToolRotation *>(item);
i->ShowVisualization(true);
formView->setTitle(tr("Tool rotation"));
AddPropertyOperationSuffix(i, tr("Suffix"));
AddPropertyFormula(tr("Angle"), i->GetFormulaAngle(), AttrAngle);
}
//---------------------------------------------------------------------------------------------------------------------
@ -2390,7 +2459,12 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCurveIntersectAxis()
//---------------------------------------------------------------------------------------------------------------------
void VToolOptionsPropertyBrowser::UpdateOptionsToolRotation()
{
VToolRotation *i = qgraphicsitem_cast<VToolRotation *>(currentItem);
idToProperty[AttrSuffix]->setValue(i->Suffix());
QVariant valueAngle;
valueAngle.setValue(i->GetFormulaAngle());
idToProperty[AttrAngle]->setValue(valueAngle);
}
//---------------------------------------------------------------------------------------------------------------------
@ -2433,6 +2507,7 @@ QStringList VToolOptionsPropertyBrowser::PropertiesList() const
<< AttrVCrossPoint /* 34 */
<< AttrHCrossPoint /* 35 */
<< AttrLength1 /* 36 */
<< AttrLength2; /* 37 */
<< AttrLength2 /* 37 */
<< AttrSuffix; /* 38 */
return attr;
}

View File

@ -74,6 +74,9 @@ private:
template<class Tool>
void SetPointName2(const QString &name);
template<class Tool>
void SetOperationSuffix(const QString &suffix);
template<class Type>
Type GetCrossPoint(const QVariant &value);
@ -95,6 +98,9 @@ private:
template<class Tool>
void AddPropertyPointName2(Tool *i, const QString &propertyName);
template<class Tool>
void AddPropertyOperationSuffix(Tool *i, const QString &propertyName, bool readOnly = false);
template<class Tool>
void AddPropertyCrossPoint(Tool *i, const QString &propertyName);

View File

@ -39,6 +39,7 @@
#include "../vwidgets/vsimplepoint.h"
#include "../vwidgets/vsimplecurve.h"
#include "../../../undocommands/label/rotationmovelabel.h"
#include "../vpatterndb/vformula.h"
const QString VToolRotation::ToolType = QStringLiteral("rotation");
const QString VToolRotation::TagItem = QStringLiteral("item");
@ -53,7 +54,7 @@ VToolRotation::VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id
: VDrawTool(doc, data, id),
QGraphicsItem(parent),
origPointId(origPointId),
angle(angle),
formulaAngle(angle),
suffix(suffix),
source(source),
destination(destination),
@ -142,7 +143,7 @@ void VToolRotation::setDialog()
DialogRotation *dialogTool = qobject_cast<DialogRotation*>(dialog);
SCASSERT(dialogTool != nullptr);
dialogTool->SetOrigPointId(origPointId);
dialogTool->SetAngle(angle);
dialogTool->SetAngle(formulaAngle);
dialogTool->SetSuffix(suffix);
}
@ -350,6 +351,52 @@ void VToolRotation::ExtractData(VAbstractPattern *doc, const QDomElement &domEle
}
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QString> VToolRotation::GetNames(const QString &suffix) const
{
QVector<QString> names;
for (int i = 0; i < source.size(); ++i)
{
const QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(source.at(i));
// This check helps to find missed objects in the switch
Q_STATIC_ASSERT_X(static_cast<int>(GOType::Unknown) == 7, "Not all objects were handled.");
#if defined(Q_CC_GNU)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default"
#endif
switch(static_cast<GOType>(obj->getType()))
{
case GOType::Point:
{
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(source.at(i));
names.append(point->name() + suffix);
break;
}
case GOType::Arc:
case GOType::EllipticalArc:
case GOType::Spline:
case GOType::SplinePath:
case GOType::CubicBezier:
case GOType::CubicBezierPath:
{
const QSharedPointer<VAbstractCurve> curve =
VAbstractTool::data.GeometricObject<VAbstractCurve>(source.at(i));
names.append(curve->name() + suffix);
break;
}
case GOType::Unknown:
break;
}
#if defined(Q_CC_GNU)
#pragma GCC diagnostic pop
#endif
}
return names;
}
//---------------------------------------------------------------------------------------------------------------------
QString VToolRotation::getTagName() const
{
@ -362,12 +409,43 @@ void VToolRotation::SetEnabled(bool enabled)
this->setEnabled(enabled);
}
//---------------------------------------------------------------------------------------------------------------------
VFormula VToolRotation::GetFormulaAngle() const
{
VFormula fAngle(formulaAngle, getData());
fAngle.setCheckZero(false);
fAngle.setToolId(id);
fAngle.setPostfix(degreeSymbol);
return fAngle;
}
//---------------------------------------------------------------------------------------------------------------------
void VToolRotation::SetFormulaAngle(const VFormula &value)
{
if (value.error() == false)
{
formulaAngle = value.GetFormula(FormulaType::FromUser);
QSharedPointer<VGObject> obj = VAbstractTool::data.GetFakeGObject(id);
SaveOption(obj);
}
}
//---------------------------------------------------------------------------------------------------------------------
QString VToolRotation::Suffix() const
{
return suffix;
}
//---------------------------------------------------------------------------------------------------------------------
void VToolRotation::SetSuffix(const QString &suffix)
{
// Don't know if need check name here.
this->suffix = suffix;
QSharedPointer<VGObject> obj = VAbstractTool::data.GetFakeGObject(id);
SaveOption(obj);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolRotation::GroupVisibility(quint32 object, bool visible)
{
@ -620,7 +698,7 @@ void VToolRotation::SetVisualization()
visual->SetObjects(source);
visual->SetOriginPointId(origPointId);
visual->SetAngle(qApp->TrVars()->FormulaToUser(angle));
visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle));
visual->RefreshGeometry();
}
}
@ -718,7 +796,7 @@ void VToolRotation::SaveDialog(QDomElement &domElement)
void VToolRotation::ReadToolAttributes(const QDomElement &domElement)
{
origPointId = doc->GetParametrUInt(domElement, AttrCenter, NULL_ID_STR);
angle = doc->GetParametrString(domElement, AttrAngle, "0");
formulaAngle = doc->GetParametrString(domElement, AttrAngle, "0");
suffix = doc->GetParametrString(domElement, AttrSuffix);
}
@ -729,7 +807,7 @@ void VToolRotation::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
doc->SetAttribute(tag, AttrType, ToolType);
doc->SetAttribute(tag, AttrCenter, QString().setNum(origPointId));
doc->SetAttribute(tag, AttrAngle, angle);
doc->SetAttribute(tag, AttrAngle, formulaAngle);
doc->SetAttribute(tag, AttrSuffix, suffix);
QDomElement tagObjects = doc->createElement(TagSource);

View File

@ -40,6 +40,7 @@ struct DestinationItem
class VAbstractSimple;
class VSimpleCurve;
class VFormula;
class VToolRotation : public VDrawTool, public QGraphicsItem
{
@ -52,12 +53,13 @@ public:
virtual void setDialog() Q_DECL_OVERRIDE;
static VToolRotation* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data);
static VToolRotation* Create(const quint32 _id, const quint32 &origin, QString &angle, const QString &suffix,
static VToolRotation* Create(const quint32 _id, const quint32 &origin, QString &formulaAngle, const QString &suffix,
const QVector<quint32> &source, const QVector<DestinationItem> &destination,
VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data,
const Document &parse, const Source &typeCreation);
static void ExtractData(VAbstractPattern *doc, const QDomElement &domElement, QVector<quint32> &source,
QVector<DestinationItem> &destination);
QVector<QString> GetNames(const QString &suffix) const;
static const QString ToolType;
static const QString TagItem;
static const QString TagSource;
@ -68,7 +70,11 @@ public:
void SetEnabled(bool enabled);
VFormula GetFormulaAngle() const;
void SetFormulaAngle(const VFormula &value);
QString Suffix() const;
void SetSuffix(const QString &suffix);
virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE;
virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE;
@ -118,7 +124,7 @@ private slots:
private:
Q_DISABLE_COPY(VToolRotation)
quint32 origPointId;
QString angle;
QString formulaAngle;
QString suffix;
QVector<quint32> source;
@ -127,39 +133,39 @@ private:
QMap<quint32, VAbstractSimple *> rObjects;
VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId,
const QString &angle, const QString &suffix, const QVector<quint32> &source,
const QString &formulaAngle, const QString &suffix, const QVector<quint32> &source,
const QVector<DestinationItem> &destination, const Source &typeCreation,
QGraphicsItem *parent = nullptr);
void UpdateNamePosition(quint32 id);
static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle,
const QString &suffix, VContainer *data);
template <class Item>
static DestinationItem CreateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
static DestinationItem CreateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle,
const QString &suffix, VContainer *data);
static DestinationItem CreateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
static DestinationItem CreateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle,
const QString &suffix, VContainer *data);
template <class Item>
static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle,
const QString &suffix, VContainer *data);
template <class Item>
static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle,
const QString &suffix, VContainer *data);
static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle,
const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my);
template <class Item>
static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle,
const QString &suffix, VContainer *data, quint32 id);
static void UpdateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
static void UpdateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle,
const QString &suffix, VContainer *data, quint32 id);
template <class Item>
static void UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
static void UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle,
const QString &suffix, VContainer *data, quint32 id);
template <class Item>
static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle,
static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal formulaAngle,
const QString &suffix, VContainer *data, quint32 id);
template <typename T>