Refactoring visualization tool line.

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-21 15:52:15 +03:00
parent 84beb053c3
commit 6d0029324b
7 changed files with 157 additions and 69 deletions

View File

@ -31,7 +31,7 @@
#include "../../geometry/vpointf.h"
#include "../../container/vcontainer.h"
#include "../../visualization/vgraphicslineitem.h"
#include "../../visualization/vistoolline.h"
#include "../../widgets/vapplication.h"
#include "../../widgets/vmaingraphicsscene.h"
#include "../../tools/vabstracttool.h"
@ -60,7 +60,7 @@ DialogLine::DialogLine(const VContainer *data, QWidget *parent)
connect(ui->comboBoxSecondPoint, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &DialogLine::PointNameChanged);
line = new VGraphicsLineItem(data);
line = new VisToolLine(data);
}
//---------------------------------------------------------------------------------------------------------------------
@ -155,7 +155,7 @@ void DialogLine::UpdateList()
void DialogLine::ShowVisualization()
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
connect(scene, &VMainGraphicsScene::NewFactor, line, &VGraphicsLineItem::SetFactor);
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();
}
@ -188,10 +188,10 @@ void DialogLine::ChosenObject(quint32 id, const SceneObject &type)
{ // -1 for not found
VMainGraphicsScene *scene = qApp->getCurrentScene();
line = new VGraphicsLineItem(data, id, scene->getScenePos());
line = new VisToolLine(data, id, scene->getScenePos());
scene->addItem(line);
connect(scene, &VMainGraphicsScene::NewFactor, line, &VGraphicsLineItem::SetFactor);
connect(scene, &VMainGraphicsScene::mouseMove, line, &VGraphicsLineItem::MousePos);
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolLine::SetFactor);
connect(scene, &VMainGraphicsScene::mouseMove, line, &VisToolLine::MousePos);
ui->comboBoxFirstPoint->setCurrentIndex(index);
number++;

View File

@ -36,7 +36,7 @@ namespace Ui
class DialogLine;
}
class VGraphicsLineItem;
class VisToolLine;
/**
* @brief The DialogLine class dialog for ToolLine. Help create line and edit option.
@ -84,7 +84,7 @@ private:
/** @brief typeLine type of line */
QString typeLine;
VGraphicsLineItem *line;
VisToolLine *line;
/**
* @brief SaveData Put dialog data in local variables
*/

View File

@ -0,0 +1,62 @@
/************************************************************************
**
** @file visline.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 21 7, 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 "visline.h"
#include "../container/vcontainer.h"
#include "../widgets/vapplication.h"
#include "../tools/drawTools/vdrawtool.h"
//---------------------------------------------------------------------------------------------------------------------
VisLine::VisLine(const VContainer *data, QGraphicsItem *parent)
:QObject(), QGraphicsLineItem(parent), data(data), factor(VDrawTool::factor), scenePos(QPointF()),
color(Qt::red), lineStyle(Qt::SolidLine)
{}
//---------------------------------------------------------------------------------------------------------------------
VisLine::~VisLine()
{}
//---------------------------------------------------------------------------------------------------------------------
void VisLine::SetFactor(qreal factor)
{
VApplication::CheckFactor(this->factor, factor);
RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
void VisLine::setLineStyle(const Qt::PenStyle &value)
{
lineStyle = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VisLine::MousePos(const QPointF &scenePos)
{
this->scenePos = scenePos;
RefreshGeometry();
}

View File

@ -0,0 +1,60 @@
/************************************************************************
**
** @file visline.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 21 7, 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/>.
**
*************************************************************************/
#ifndef VISLINE_H
#define VISLINE_H
#include <QObject>
#include <QGraphicsLineItem>
#include <QPointF>
class VContainer;
class VisLine: public QObject, public QGraphicsLineItem
{
Q_OBJECT
public:
VisLine(const VContainer *data, QGraphicsItem *parent = 0);
virtual ~VisLine();
void setLineStyle(const Qt::PenStyle &value);
virtual void RefreshGeometry()=0;
public slots:
void SetFactor(qreal factor);
void MousePos(const QPointF &scenePos);
protected:
const VContainer *data;
qreal factor;
QPointF scenePos;
QColor color;
Qt::PenStyle lineStyle;
private:
Q_DISABLE_COPY(VisLine)
};
#endif // VISLINE_H

View File

@ -26,71 +26,47 @@
**
*************************************************************************/
#include "vgraphicslineitem.h"
#include "vistoolline.h"
#include "../container/vcontainer.h"
#include "../geometry/vpointf.h"
#include "../widgets/vapplication.h"
#include "../tools/drawTools/vdrawtool.h"
//---------------------------------------------------------------------------------------------------------------------
VGraphicsLineItem::VGraphicsLineItem(const VContainer *data, QGraphicsItem *parent)
:QObject(), QGraphicsLineItem(parent), data(data), point1Id(0), point2Id(0), factor(VDrawTool::factor),
scenePos(QPointF()), color(Qt::red), lineStyle(Qt::SolidLine)
{}
VisToolLine::VisToolLine(const VContainer *data, QGraphicsItem *parent)
:VisLine(data, parent), point1Id(0), point2Id(0)
{
this->color = Qt::red;
}
//---------------------------------------------------------------------------------------------------------------------
VGraphicsLineItem::VGraphicsLineItem(const VContainer *data, const quint32 &pointId, const QPointF &scenePos,
VisToolLine::VisToolLine(const VContainer *data, const quint32 &pointId, const QPointF &scenePos,
QGraphicsItem *parent)
:QObject(), QGraphicsLineItem(parent), data(data), point1Id(pointId), point2Id(0), factor(VDrawTool::factor),
scenePos(scenePos), color(Qt::black), lineStyle(Qt::SolidLine)
{
RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
VGraphicsLineItem::~VGraphicsLineItem()
{}
//---------------------------------------------------------------------------------------------------------------------
void VGraphicsLineItem::SetFactor(qreal factor)
{
VApplication::CheckFactor(this->factor, factor);
RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
void VGraphicsLineItem::MousePos(const QPointF &scenePos)
:VisLine(data, parent), point1Id(pointId), point2Id(0)
{
this->color = Qt::black;
this->scenePos = scenePos;
RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
void VGraphicsLineItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsLineItem::mouseMoveEvent(event);
}
VisToolLine::~VisToolLine()
{}
//---------------------------------------------------------------------------------------------------------------------
void VGraphicsLineItem::setPoint2Id(const quint32 &value)
void VisToolLine::setPoint2Id(const quint32 &value)
{
point2Id = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VGraphicsLineItem::setPoint1Id(const quint32 &value)
void VisToolLine::setPoint1Id(const quint32 &value)
{
point1Id = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VGraphicsLineItem::setLineStyle(const Qt::PenStyle &value)
{
lineStyle = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VGraphicsLineItem::RefreshGeometry()
void VisToolLine::RefreshGeometry()
{
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
if (point2Id == 0)

View File

@ -29,36 +29,24 @@
#ifndef VGRAPHICSLINEITEM_H
#define VGRAPHICSLINEITEM_H
#include <QGraphicsLineItem>
class VContainer;
#include "visline.h"
class VGraphicsLineItem : public QObject, public QGraphicsLineItem
class VisToolLine : public VisLine
{
Q_OBJECT
public:
VGraphicsLineItem(const VContainer *data, QGraphicsItem * parent = 0);
VGraphicsLineItem(const VContainer *data, const quint32 &pointId, const QPointF &scenePos,
VisToolLine(const VContainer *data, QGraphicsItem *parent = 0);
VisToolLine(const VContainer *data, const quint32 &pointId, const QPointF &scenePos,
QGraphicsItem * parent = 0);
virtual ~VGraphicsLineItem();
virtual ~VisToolLine();
void setLineStyle(const Qt::PenStyle &value);
void setPoint1Id(const quint32 &value);
void setPoint2Id(const quint32 &value);
void RefreshGeometry();
public slots:
void SetFactor(qreal factor);
void MousePos(const QPointF &scenePos);
protected:
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
virtual void RefreshGeometry();
private:
Q_DISABLE_COPY(VGraphicsLineItem)
const VContainer *data;
Q_DISABLE_COPY(VisToolLine)
quint32 point1Id;
quint32 point2Id;
qreal factor;
QPointF scenePos;
const QColor color;
Qt::PenStyle lineStyle;
};
#endif // VGRAPHICSLINEITEM_H

View File

@ -3,11 +3,13 @@ HEADERS += \
visualization/vcontrolpointspline.h \
visualization/vsimplesplinepath.h \
visualization/vsimplecurve.h \
visualization/vgraphicslineitem.h
visualization/visline.h \
visualization/vistoolline.h
SOURCES += \
visualization/vgraphicssimpletextitem.cpp \
visualization/vcontrolpointspline.cpp \
visualization/vsimplesplinepath.cpp \
visualization/vsimplecurve.cpp \
visualization/vgraphicslineitem.cpp
visualization/visline.cpp \
visualization/vistoolline.cpp