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
|
//
// C++ Implementation: polylinemodel
//
// Description:
//
//
// Author: Thibaut GRIDEL <tgridel@free.fr>
//
// Copyright (c) 2009-2010 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/>.
//
//
#include <iostream>
#include "polylinemodel.h"
#include "commontypes.h"
#include "situationmodel.h"
#include "pointmodel.h"
extern int debugLevel;
PolyLineModel::PolyLineModel(SituationModel* situation, QObject *parent)
: QObject(parent),
m_situation(situation) {
if (debugLevel & 1 << MODEL) std::cout << "new PolyLine " << this << std::endl;
}
PolyLineModel::~PolyLineModel() {
if (debugLevel & 1 << MODEL) std::cout << "delete PolyLine " << this << std::endl;
}
void PolyLineModel::appendDiscardedXml(const QString& theValue) {
if (!m_discardedXml.contains(theValue)) {
m_discardedXml.append(theValue);
}
}
void PolyLineModel::changingPolyLine(PolyLineModel *polyline) {
QPainterPath path;
if (m_points.size() < 1) {
m_path = path;
return;
}
path.moveTo(m_points[0]->position());
foreach(PointModel *point, m_points) {
path.lineTo(point->position());
}
m_path = path;
emit polyLineChanged(polyline);
}
PointModel* PolyLineModel::addPoint(PointModel *point, int order) {
if (order == -1) {
order = m_points.size();
}
m_points.insert(order, point);
m_situation->addingPoint(point);
if (debugLevel & 1 << MODEL) std::cout << "Adding Point " << order+1 << std::endl;
changingPolyLine(this);
return point;
}
int PolyLineModel::deletePoint(PointModel *point) {
int order = m_points.indexOf(point);
m_points.removeOne(point);
if (debugLevel & 1 << MODEL) std::cout << "Removing Point " << order+1 << std::endl;
m_situation->removingPoint(point);
changingPolyLine(this);
return order;
}
void PolyLineModel::displayPoints() {
if (debugLevel & 1 << MODEL) std::cout << "Displaying points" << std::endl;
foreach (PointModel* point, m_points) {
m_situation->addingPoint(point);
}
}
void PolyLineModel::hidePoints() {
if (debugLevel & 1 << MODEL) std::cout << "Hiding points" << std::endl;
foreach (PointModel* point, m_points) {
m_situation->removingPoint(point);
}
}
|