Skip to content

Commit

Permalink
Split many thing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Harinlen committed Jun 1, 2015
1 parent 32592d1 commit 6e299fc
Show file tree
Hide file tree
Showing 16 changed files with 531 additions and 176 deletions.
14 changes: 10 additions & 4 deletions Robot.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ SOURCES += \
robotmanagement.cpp \
paneldock.cpp \
robotaddwidget.cpp \
groundpreviewwidget.cpp \
generateground.cpp \
groundeditor.cpp \
generategroundbase.cpp \
barrackseditor.cpp \
barrackseditorbase.cpp
barrackseditorbase.cpp \
pointeditor.cpp \
groundpreviewer.cpp \
groundrealtimepreviewer.cpp \
groundglobal.cpp

HEADERS += \
mainwindow.h \
Expand All @@ -31,9 +34,12 @@ HEADERS += \
robotmanagement.h \
paneldock.h \
robotaddwidget.h \
groundpreviewwidget.h \
generateground.h \
groundeditor.h \
generategroundbase.h \
barrackseditor.h \
barrackseditorbase.h
barrackseditorbase.h \
pointeditor.h \
groundpreviewer.h \
groundrealtimepreviewer.h \
groundglobal.h
82 changes: 35 additions & 47 deletions ground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "robot.h"
#include "menubar.h"
#include "generategroundbase.h"
#include "groundglobal.h"

#include "ground.h"

Expand All @@ -38,9 +39,6 @@ Ground::Ground(QWidget *parent) :
GroundBase(parent),
m_border(QPolygonF()),
m_barracks(QPolygonF()),
m_borderColor(QColor(0,0,255)),
m_barracksColor(QColor(255,127,0)),
m_referenceLineColor(QColor(200,200,200)),
m_filePath(QString()),
m_fileName(QString()),
m_changed(false),
Expand All @@ -53,6 +51,9 @@ Ground::Ground(QWidget *parent) :
connect(m_timeline, &QTimer::timeout,
this, &Ground::onActionUpdateRobot);

//Initial the ground global.
m_groundGlobal=GroundGlobal::instance();

//Initial the actions.
for(int i=0; i<GroundActionsCount; i++)
{
Expand Down Expand Up @@ -162,7 +163,7 @@ void Ground::paintEvent(QPaintEvent *event)
QPainter::SmoothPixmapTransform, true);
painter.translate(Robot::detectRadius(), Robot::detectRadius());
//Draw the reference line.
painter.setPen(m_referenceLineColor);
painter.setPen(m_groundGlobal->referenceLineColor());
painter.setBrush(QColor(0,0,0,0));
for(int i=0; i<=height(); i+=30)
{
Expand All @@ -173,11 +174,11 @@ void Ground::paintEvent(QPaintEvent *event)
painter.drawLine(i, 0, i, height());
}
//Draw the border.
painter.setPen(m_borderColor);
painter.setPen(m_groundGlobal->borderColor());
painter.drawPolygon(m_border);

//Draw the barracks.
painter.setPen(m_barracksColor);
painter.setPen(m_groundGlobal->barracksColor());
painter.drawPolygon(m_barracks);

//Draw all the robot.
Expand All @@ -198,33 +199,37 @@ void Ground::retranslate()

void Ground::onActionUpdateRobot()
{
QList<Robot *>::iterator beforeLastRobot=m_robotList.end()-1;
//Give all the robot the detect information.
for(QList<Robot *>::iterator robot=m_robotList.begin();
robot!=beforeLastRobot;
++robot)
//If there're more than 1 robot, we will going to detect the robot.
if(m_robotList.size()>1)
{
for(QList<Robot *>::iterator target=robot+1;
target!=m_robotList.end();
++target)
QList<Robot *>::iterator beforeLastRobot=m_robotList.end()-1;
//Give all the robot the detect information.
for(QList<Robot *>::iterator robot=m_robotList.begin();
robot!=beforeLastRobot;
++robot)
{
//Ignore the current robot.
if(robot==target)
{
continue;
}
//If we have detected one of another robot, add them into the both
//detect list.
if(inDetectRange(*robot, *target))
{
(*robot)->addToDetectList(*target);
(*target)->addToDetectList(*robot);
}
else
for(QList<Robot *>::iterator target=robot+1;
target!=m_robotList.end();
++target)
{
//Or else remove them from each other's detect list.
(*robot)->removeFromDetectList(*target);
(*target)->removeFromDetectList(*robot);
//Ignore the current robot.
if(robot==target)
{
continue;
}
//If we have detected one of another robot, add them into the both
//detect list.
if(inDetectRange(*robot, *target))
{
(*robot)->addToDetectList(*target);
(*target)->addToDetectList(*robot);
}
else
{
//Or else remove them from each other's detect list.
(*robot)->removeFromDetectList(*target);
(*target)->removeFromDetectList(*robot);
}
}
}
}
Expand Down Expand Up @@ -614,11 +619,6 @@ QPolygonF Ground::barracks() const
return m_barracks;
}

QColor Ground::barracksColor() const
{
return m_barracksColor;
}

bool Ground::addRobot(Robot *robot)
{
//Check the robot.
Expand Down Expand Up @@ -690,18 +690,6 @@ void Ground::setBarracks(const QPolygonF &barracks)
emit barracksChanged();
}

QColor Ground::borderColor() const
{
return m_borderColor;
}

void Ground::setBorderColor(const QColor &borderColor)
{
m_borderColor = borderColor;
//Update the widget.
update();
}

void Ground::pause()
{
//Stop the timer.
Expand Down
20 changes: 4 additions & 16 deletions ground.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "groundbase.h"

class QTimer;
class GroundGlobal;
/*!
* \brief The Ground class a default realization of the GroundBase class.
*/
Expand All @@ -41,21 +42,11 @@ class Ground : public GroundBase
*/
QPolygonF border() const;

/*!
* \brief Reimplemented from GroundBase::borderColor().
*/
QColor borderColor() const;

/*!
* \brief Reimplemented from GroundBase::barracks().
*/
QPolygonF barracks() const;

/*!
* \brief Reimplemented from GroundBase::barracksColor().
*/
QColor barracksColor() const;

/*!
* \brief Reimplemented from GroundBase::addRobot().
*/
Expand Down Expand Up @@ -88,11 +79,6 @@ public slots:
*/
void setBarracks(const QPolygonF &barracks);

/*!
* \brief Reimplemented from GroundBase::setBorderColor(const QColor &).
*/
void setBorderColor(const QColor &borderColor);

/*!
* \brief Reimplemented from GroundBase::pause().
*/
Expand Down Expand Up @@ -155,7 +141,6 @@ private slots:
QAction *m_actions[GroundActionsCount];

QPolygonF m_border, m_barracks;
QColor m_borderColor, m_barracksColor, m_referenceLineColor;
QList<Robot *> m_robotList;

//Project file status.
Expand All @@ -170,6 +155,9 @@ private slots:

QTimer *m_timeline;
GenerateGroundBase *m_generator;

//Ground Global data.
GroundGlobal *m_groundGlobal;
};

#endif // GROUND_H
22 changes: 2 additions & 20 deletions groundbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class GenerateGroundBase;
* interfaces which a ground class should be realized.\n
* A Ground class is the widget which is going to show up the robots,
* borders and barracks. It has to detected all the robots and set the
* information to all the robots. The Ground class should contains all the
* information to all the robots. The Ground class should contain all the
* environmental information.
*/
class GroundBase : public QWidget
Expand All @@ -50,25 +50,13 @@ class GroundBase : public QWidget
*/
virtual QPolygonF border() const=0;

/*!
* \brief Get the color of the border.
* \return The QColor of the border.
*/
virtual QColor borderColor() const=0;

/*!
* \brief The barracks border which all the robots is going to be set at
* beginning.
* \return The border QPolygonF class of the barracks.
*/
virtual QPolygonF barracks() const=0;

/*!
* \brief Get the color of the barracks border.
* \return The QColor of the barracks border.
*/
virtual QColor barracksColor() const=0;

/*!
* \brief Add a robot to the ground. It will detect the start position of
* the robot. If the robot is out side the barracks, will delete the robot.
Expand All @@ -78,7 +66,7 @@ class GroundBase : public QWidget
virtual bool addRobot(Robot *robot)=0;

/*!
* \brief Add a lots of robots to the ground. It will call addRobot()
* \brief Add a lot of robots to the ground. It will call addRobot()
* function for several times.
* \param robots
*/
Expand Down Expand Up @@ -126,12 +114,6 @@ public slots:
*/
virtual void setBarracks(const QPolygonF &barracks)=0;

/*!
* \brief Sets the color of the border.
* \param borderColor The prefer color of the border.
*/
virtual void setBorderColor(const QColor &borderColor)=0;

/*!
* \brief Pause the main time line.
*/
Expand Down
Loading

0 comments on commit 6e299fc

Please sign in to comment.