File: trackmodel.h

package info (click to toggle)
boats 202008-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,572 kB
  • sloc: cpp: 11,129; xml: 10; makefile: 9
file content (183 lines) | stat: -rw-r--r-- 6,095 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//
// C++ Interface: trackmodel
//
// Description:
//
//
// Author: Thibaut GRIDEL <tgridel@free.fr>
//
// Copyright (c) 2008-2019 Thibaut GRIDEL
//
// This program 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.
//
// This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
//
//
#ifndef TRACKMODEL_H
#define TRACKMODEL_H

#include <QtGui>
#ifdef QML
#include <QQmlListProperty>
#endif
#include "boats.h"

class SituationModel;
class BoatModel;

/**
    \class TrackModel

    \brief The Model for the Track of a Boat

    The class represents the Model for a Track, according to an
    Observer Pattern.

    TrackModel contains data which describe one boat, like the series of
    the boat, the color it is drawn and the List of Positions where the boat
    navigates.

    It shall not be mistaken with BoatModel, which holds one position at
    a given time. More exactly, a TrackModel will hold a List of BoatModels.

    \sa SituationModel, BoatModel

*/

class TrackModel : public QObject {
        Q_OBJECT
    public:

        Q_PROPERTY(int order READ order WRITE setOrder NOTIFY orderChanged)
        Q_PROPERTY(QColor trackColor READ color WRITE setColor NOTIFY colorChanged)
        Q_PROPERTY(int series READ series WRITE setSeries NOTIFY seriesChanged)
        Q_PROPERTY(bool showPath READ showPath WRITE setShowPath NOTIFY showPathChanged)
        Q_PROPERTY(bool followTrack READ followTrack WRITE setFollowTrack NOTIFY followTrackChanged)
#ifdef QML
        Q_PROPERTY(QQmlListProperty<BoatModel> boatList READ boatList NOTIFY boatsChanged)
#endif
        Q_PROPERTY(int size READ size NOTIFY boatsChanged)

        TrackModel(SituationModel* situation = 0, QObject *parent = 0);
        ~TrackModel();

        BoatModel * addBoat(BoatModel *boat, int order = -1);
        int deleteBoat(BoatModel *boat);

        void displayBoats();
        void hideBoats();

        // Setters and Getters for Model Data
        int order() const { return m_order; }
        void setOrder(const int theValue);

        QColor color() const { return m_color;}
        void setColor(const QColor& theValue);

        int series() const { return m_series;}
        void setSeries(const int theValue);

        bool showPath() const { return m_showPath;}
        void setShowPath(const bool theValue);

        bool followTrack() const { return m_followTrack; }
        void setFollowTrack(bool theValue);

        int size() const { return m_boats.size();}
        const QList<BoatModel*> boats() const { return m_boats; }
#ifdef QML
        QQmlListProperty<BoatModel> boatList();
#endif
        const QPainterPath path() const { return m_path; }

        // Setters and Getters for Non model Data
        SituationModel* situation() const { return m_situation; }

        int length() const { return m_length; }
        bool hasSpin() const {return m_hasSpin; }
        qreal maxNormalSailAngle() const {return m_maxNormalSailAngle; }
        qreal maxNormalJibAngle() const {return m_maxNormalJibAngle; }
        qreal maxWithSpinSailAngle() const {return m_maxWithSpinSailAngle; }
        qreal maxWithSpinJibAngle() const {return m_maxWithSpinJibAngle; }

        QStringList discardedXml() const { return m_discardedXml; }
        void appendDiscardedXml(const QString& theValue);

        Q_INVOKABLE qreal headingForNext(int index, QPointF point);

        void changingTrack(TrackModel *track);

        Q_INVOKABLE void setSelected(bool selected);

    signals:
        // Signals for TrackModel parameters
        void orderChanged(int order);
        void colorChanged(QColor color);
        void seriesChanged(int series);
        void showPathChanged(bool showPath);
        void followTrackChanged(bool followTrack);
        void trackChanged(TrackModel *track);
        void boatsChanged();
        void trackSelected(bool selected);

    private:
        // Model Data
        /// \a m_order holds the stacking order of the Track
        int m_order;

        /// \a m_color holds the color of the Track
        QColor m_color;

        /// \a m_series holds the series of the Track
        int m_series;

        /// \a m_boats holds the List of Boat Positions of the Track
        QList<BoatModel*> m_boats;

        /// \a m_showPath holds whether the track path will be displayed
        bool m_showPath;

        /// \a m_followTrack holds whether this track will be followed
        /// during the animation
        bool m_followTrack;

        // Non model Data
        /// \a m_situation keeps a pointer to the SituationModel to which
        /// it belongs
        SituationModel *m_situation;

        /// \a m_length holds the size of the Boat in World Coordinates
        int m_length;

        /// \a m_hasSpin holds whether this type of boat has a spinnaker (or gennaker)
        bool m_hasSpin;

        /// \a m_maxNormalSailAngle holds the max sail angle to use when sailing without a spinnaker
        qreal m_maxNormalSailAngle;

        /// \a m_maxNormalJibAngle holds the max jib angle to use when sailing without a spinnaker
        qreal m_maxNormalJibAngle;

        /// \a m_maxWithSpinSailAngle holds the max sail angle to use when sailing with a spinnaker
        qreal m_maxWithSpinSailAngle;

        /// \a m_maxWithSpinJibAngle holds the max jib angle to use when sailing with a spinnaker
        qreal m_maxWithSpinJibAngle;

        /// \a m_path holds the QPainterPath of the Track
        QPainterPath m_path;

        /// \a m_discardedXml keeps all unparsed xml tags
        QStringList m_discardedXml;
};

#endif