Files
qad/libs/map/mapitembase.h
peri4 083dc3edf5 MapItemBase visible API
MapItemEllipse::rebuild fix
2024-07-10 12:55:42 +03:00

105 lines
2.9 KiB
C++

/*
QAD - Qt ADvanced
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef mapitembase_h
#define mapitembase_h
#include "qad_map_export.h"
#include <QCursor>
#include <QGeoCoordinate>
#include <QMap>
#include <QPainter>
#include <QRectF>
#include <QVariant>
class MapView;
class QAD_MAP_EXPORT MapItemBase {
friend class MapView;
public:
explicit MapItemBase();
virtual ~MapItemBase();
bool isInteracive() const { return m_interacive; }
void setInteracive(bool newInteracive);
bool isVisible() const { return m_visible; }
void setVisible(bool newVisible);
bool isHidden() const { return !isVisible(); }
void setHidden(bool newHidden) { setVisible(!newHidden); }
void show() { setVisible(true); }
void hide() { setVisible(false); }
double getRotation() const { return m_rotation; }
void setRotation(double deg);
void rotate(double deg);
QPointF getScale() const { return m_scale; }
void scale(double s) { scale({s, s}); }
void scale(double sx, double sy) { scale({sx, sy}); }
void scale(QPointF s);
void setScale(double s) { setScale({s, s}); }
void setScale(double sx, double sy) { scale({sx, sy}); }
void setScale(QPointF s);
QPointF position() const { return m_position; }
void setPosition(QPointF geo);
void setPosition(double lat, double lng) { setPosition(QPointF(lat, lng)); }
void setPosition(QGeoCoordinate c) { setPosition(QPointF(c.latitude(), c.longitude())); }
QPointF offset() const { return m_offset; }
void setOffset(QPointF pixels);
void setOffset(double x, double y) { setOffset({x, y}); }
const QCursor & cursor() const { return m_cursor; }
void setCursor(const QCursor & newCursor);
QVariant data(int id) const { return data_.value(id); }
void setData(int id, const QVariant & d) { data_[id] = d; }
protected:
QPointF mapToView(QPointF norm) const;
double scalePx2M(QPointF norm) const;
virtual void draw(QPainter * p) = 0;
void updateParent();
void setBoundingRect(QRectF b);
QPointF norm_pos;
bool ignore_scale = false;
private:
void updatePosition();
virtual void potitionChanged() {}
virtual void zoomChanged() {}
MapView * parent = nullptr;
bool m_visible = true, m_interacive = false;
double m_rotation = 0.;
QPointF m_position, m_scale = {1., 1.}, m_offset;
QRectF m_bounding;
QCursor m_cursor;
QMap<int, QVariant> data_;
};
#endif