CMake findQAD miss map

MapItemBase::offset feature
PIValueTreeEdit add custom button to show/hide groups
This commit is contained in:
2023-01-26 23:19:28 +03:00
parent 34d2653744
commit 7188e38072
9 changed files with 59 additions and 14 deletions

View File

@@ -4,7 +4,7 @@ cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default
project(QAD)
set(QAD_MAJOR 2)
set(QAD_MINOR 14)
set(QAD_REVISION 1)
set(QAD_REVISION 2)
set(QAD_SUFFIX )
set(QAD_COMPANY SHS)
set(QAD_DOMAIN org.SHS)

View File

@@ -44,7 +44,7 @@ if(QAD_FIND_VERSION VERSION_GREATER QAD_VERSION)
message(FATAL_ERROR "QAD version ${QAD_VERSION} is available, but ${QAD_FIND_VERSION} requested!")
endif()
set(__libs "utils;widgets;application;blockview;graphic;sql_table;touch_widgets;doc")
set(__libs "utils;widgets;application;blockview;graphic;sql_table;touch_widgets;doc;map")
if (PIP_FOUND OR BUILDING_PIP)
list(APPEND __libs "piqt;piqt_utils")
endif()
@@ -57,6 +57,7 @@ set(__module_graphic Graphic )
set(__module_sql_table SQLTable )
set(__module_touch_widgets TouchWidgets )
set(__module_doc Doc )
set(__module_map Map )
set(__module_piqt PIQt )
set(__module_piqt_utils PIQtUtils )
@@ -71,6 +72,7 @@ set(__deps_application "QAD::Widgets")
set(__deps_blockview "QAD::Widgets")
set(__deps_graphic "QAD::Widgets")
set(__deps_sql_table "QAD::Widgets")
set(__deps_map "QAD::Utils")
set(__deps_piqt "QAD::Widgets;PIP")
set(__deps_piqt_utils "QAD::Blockview;QAD::PIQt")

View File

@@ -60,6 +60,12 @@ void MapItemBase::setPosition(QPointF geo) {
}
void MapItemBase::setOffset(QPointF pixels) {
m_offset = pixels;
updateParent();
}
void MapItemBase::setCursor(const QCursor & newCursor) {
m_cursor = newCursor;
updateParent();

View File

@@ -60,6 +60,10 @@ public:
void setPosition(QPointF geo);
void setPosition(double lat, double lng) { setPosition({lat, lng}); }
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);
@@ -84,7 +88,7 @@ private:
MapView * parent = nullptr;
bool m_visible = true, m_interacive = false;
double m_rotation = 0.;
QPointF m_position, m_scale = {1., 1.};
QPointF m_position, m_scale = {1., 1.}, m_offset;
QRectF m_bounding;
QCursor m_cursor;
QMap<int, QVariant> data_;

View File

@@ -30,7 +30,7 @@ void MapItemText::draw(QPainter * p) {
if (str.isEmpty()) return;
p->setPen(pen());
p->setFont(font());
auto br = p->fontMetrics().boundingRect(str);
auto br = p->fontMetrics().boundingRect(str).adjusted(0, 0, 1, 1);
br.translate(-br.topLeft());
if (m_alignment.testFlag(Qt::AlignHCenter)) {
br.translate(-br.center().x(), 0.);

View File

@@ -80,6 +80,7 @@ void MapView::setZoom(double z) {
void MapView::mousePressEvent(QMouseEvent * e) {
is_pan = false;
press_point = e->pos();
last_click_coord = OSM::xy2geo(mapToNorm(press_point));
}
@@ -187,6 +188,7 @@ void MapView::drawItems(QPainter & p) {
QPointF ipos = mapFromNorm(i->norm_pos);
p.setTransform(src_tr);
p.translate(ipos);
p.translate(i->m_offset.x(), -i->m_offset.y());
p.rotate(i->getRotation());
if (!i->ignore_scale) p.scale(i->getScale().x(), i->getScale().y());
i->draw(&p);
@@ -257,6 +259,7 @@ void MapView::updateMouse(QPoint mouse) {
QTransform mtr;
if (!i->ignore_scale) mtr.scale(1. / i->getScale().x(), 1. / i->getScale().y());
mtr.rotate(-i->getRotation());
mtr.translate(-i->m_offset.x(), i->m_offset.y());
mtr.translate(-ipos.x(), -ipos.y());
QPoint m = mtr.map(mouse);
if (i->m_bounding.contains(m)) {

View File

@@ -52,7 +52,9 @@ public:
double getZoom() const { return zoom_; }
void setZoom(double z);
private:
QPointF clickedCoordinate() const { return last_click_coord; }
protected:
QSize sizeHint() const override { return QSize(200, 200); }
void mousePressEvent(QMouseEvent * e) override;
void mouseReleaseEvent(QMouseEvent * e) override;
@@ -61,6 +63,8 @@ private:
void wheelEvent(QWheelEvent * e) override;
void paintEvent(QPaintEvent *) override;
void resizeEvent(QResizeEvent *) override;
private:
void drawBackground();
void drawItems(QPainter & p);
void checkZoom();
@@ -78,6 +82,7 @@ private:
OSMTileCache * cache = nullptr;
MapItemBase * hover = nullptr;
QPointF center_ = QPointF(0.5, 0.5);
QPointF last_click_coord = center_;
QPoint press_point;
QPixmap background;
QRectF view_rect;

View File

@@ -19,6 +19,35 @@ using Attribute = PIValueTree::Attribute;
const char property_name[] = "__name__";
class GroupBox: public QGroupBox {
public:
GroupBox(QWidget * content = nullptr): QGroupBox() {
icon_show = QIcon(":/icons/layer-visible-on.png");
icon_hide = QIcon(":/icons/layer-visible-off.png");
setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
layout()->addWidget(content);
setAlignment(Qt::AlignCenter);
btn = new QToolButton(this);
btn->setCheckable(true);
btn->show();
connect(btn, &QToolButton::toggled, this, [this, content](bool on) {
btn->setIcon(on ? icon_show : icon_hide);
content->setVisible(on);
});
btn->setChecked(true);
}
private:
void resizeEvent(QResizeEvent * e) {
QGroupBox::resizeEvent(e);
btn->resize(btn->height(), btn->height());
btn->move(btn->height() / 2, 0);
}
QToolButton * btn = nullptr;
QIcon icon_show, icon_hide;
};
PIValueTreeEdit::PIValueTreeEdit(QWidget * parent): QWidget(parent) {
widget_params = new PIValueTreeEditParameters();
widget_reorder = new PIValueTreeEditReorder();
@@ -356,16 +385,10 @@ PIValueTreeEdit * PIValueTreeEdit::addTreeEdit(const PIValueTree & vt) {
switch (real_grouping) {
case Indent: grid->add(vt, vt.name(), ve, vt.comment(), true); break;
case Groups: {
auto * gb = new QGroupBox();
gb->setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
gb->layout()->addWidget(ve);
auto * gb = new GroupBox(ve);
gb->setTitle(PI2QString(vt.name()));
gb->setToolTip(PI2QString(vt.comment()));
gb->setCheckable(true);
gb->setChecked(true);
gb->setAlignment(Qt::AlignCenter);
gb->setProperty(property_name, PI2QString(vt.name()));
connect(gb, &QGroupBox::toggled, ve, &QWidget::setVisible);
grid->add(vt, gb, true);
} break;
case Tabs: {

View File

@@ -10,5 +10,7 @@
<file>../../icons/legend.png</file>
<file>../../icons/document-open.png</file>
<file>../../icons/document-edit.png</file>
<file>../../icons/layer-visible-off.png</file>
<file>../../icons/layer-visible-on.png</file>
</qresource>
</RCC>