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

View File

@ -36,7 +36,7 @@ namespace Ui
class DialogLine; class DialogLine;
} }
class VGraphicsLineItem; class VisToolLine;
/** /**
* @brief The DialogLine class dialog for ToolLine. Help create line and edit option. * @brief The DialogLine class dialog for ToolLine. Help create line and edit option.
@ -84,7 +84,7 @@ private:
/** @brief typeLine type of line */ /** @brief typeLine type of line */
QString typeLine; QString typeLine;
VGraphicsLineItem *line; VisToolLine *line;
/** /**
* @brief SaveData Put dialog data in local variables * @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 "../container/vcontainer.h"
#include "../geometry/vpointf.h" #include "../geometry/vpointf.h"
#include "../widgets/vapplication.h" #include "../widgets/vapplication.h"
#include "../tools/drawTools/vdrawtool.h" #include "../tools/drawTools/vdrawtool.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VGraphicsLineItem::VGraphicsLineItem(const VContainer *data, QGraphicsItem *parent) VisToolLine::VisToolLine(const VContainer *data, QGraphicsItem *parent)
:QObject(), QGraphicsLineItem(parent), data(data), point1Id(0), point2Id(0), factor(VDrawTool::factor), :VisLine(data, parent), point1Id(0), point2Id(0)
scenePos(QPointF()), color(Qt::red), lineStyle(Qt::SolidLine) {
{} 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) QGraphicsItem *parent)
:QObject(), QGraphicsLineItem(parent), data(data), point1Id(pointId), point2Id(0), factor(VDrawTool::factor), :VisLine(data, parent), point1Id(pointId), point2Id(0)
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)
{ {
this->color = Qt::black;
this->scenePos = scenePos; this->scenePos = scenePos;
RefreshGeometry(); RefreshGeometry();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VGraphicsLineItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) VisToolLine::~VisToolLine()
{ {}
QGraphicsLineItem::mouseMoveEvent(event);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VGraphicsLineItem::setPoint2Id(const quint32 &value) void VisToolLine::setPoint2Id(const quint32 &value)
{ {
point2Id = value; point2Id = value;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VGraphicsLineItem::setPoint1Id(const quint32 &value) void VisToolLine::setPoint1Id(const quint32 &value)
{ {
point1Id = value; point1Id = value;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VGraphicsLineItem::setLineStyle(const Qt::PenStyle &value) void VisToolLine::RefreshGeometry()
{
lineStyle = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VGraphicsLineItem::RefreshGeometry()
{ {
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id); const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
if (point2Id == 0) if (point2Id == 0)

View File

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

View File

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