添加Model设置接口
This commit is contained in:
parent
4b04982fc9
commit
529abd14b4
|
|
@ -21,8 +21,8 @@ MapPresent::MapPresent(QWidget* parent /*= nullptr*/)
|
||||||
connect(this, &MapPresent::mouseOutNotify, delegate, &BasicUnitDelegate::hotClear);
|
connect(this, &MapPresent::mouseOutNotify, delegate, &BasicUnitDelegate::hotClear);
|
||||||
connect(this, &MapPresent::mouseHoverNotify, delegate, &BasicUnitDelegate::hotIndexSet);
|
connect(this, &MapPresent::mouseHoverNotify, delegate, &BasicUnitDelegate::hotIndexSet);
|
||||||
connect(delegate, &BasicUnitDelegate::updateRequest, [=](const PresentIndex& idx) {
|
connect(delegate, &BasicUnitDelegate::updateRequest, [=](const PresentIndex& idx) {
|
||||||
if (idx.isValid() && !_updated_units.contains(idx)) {
|
if (idx.isValid() && !_updated_index_list.contains(idx)) {
|
||||||
_updated_units.append(idx);
|
_updated_index_list.append(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->update();
|
this->update();
|
||||||
|
|
@ -44,6 +44,25 @@ double MapPresent::zoomTimes() const
|
||||||
return _scale_times;
|
return _scale_times;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MapPresent::setDelegate(UnitPresentDelegate* ins)
|
||||||
|
{
|
||||||
|
if (_type_present_delegate.contains(ins->unitType()))
|
||||||
|
return false;
|
||||||
|
_type_present_delegate[ins->unitType()] = ins;
|
||||||
|
|
||||||
|
this->visible_units_tidy();
|
||||||
|
this->update();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapPresent::setDataModel(MapDataModel* model)
|
||||||
|
{
|
||||||
|
this->_map_data_model = model;
|
||||||
|
|
||||||
|
this->visible_units_tidy();
|
||||||
|
this->update();
|
||||||
|
}
|
||||||
|
|
||||||
PresentIndex MapPresent::indexGet(const QPointF& pos) const
|
PresentIndex MapPresent::indexGet(const QPointF& pos) const
|
||||||
{
|
{
|
||||||
QList<PresentOption> templist;
|
QList<PresentOption> templist;
|
||||||
|
|
@ -95,13 +114,13 @@ void MapPresent::paintEvent(QPaintEvent* ev)
|
||||||
{
|
{
|
||||||
QWidget::paintEvent(ev);
|
QWidget::paintEvent(ev);
|
||||||
|
|
||||||
if (_updated_units.size()) {
|
if (_updated_index_list.size()) {
|
||||||
QPainter pic_painter(&_paint_buffer);
|
QPainter pic_painter(&_paint_buffer);
|
||||||
|
|
||||||
for (auto idx : _updated_units) {
|
for (auto unit_idx : _updated_index_list) {
|
||||||
pic_painter.save();
|
pic_painter.save();
|
||||||
|
|
||||||
auto opt = _visible_units[idx];
|
auto opt = _visible_units[unit_idx];
|
||||||
auto rect = opt.outline;
|
auto rect = opt.outline;
|
||||||
pic_painter.translate(rect.topLeft());
|
pic_painter.translate(rect.topLeft());
|
||||||
rect.moveTo(0, 0);
|
rect.moveTo(0, 0);
|
||||||
|
|
@ -110,13 +129,19 @@ void MapPresent::paintEvent(QPaintEvent* ev)
|
||||||
pic_painter.setClipPath(clip_path);
|
pic_painter.setClipPath(clip_path);
|
||||||
|
|
||||||
opt.outline = rect;
|
opt.outline = rect;
|
||||||
UnitPresentDelegate& t = *_type_present_delegate[0];
|
|
||||||
|
int unit_type = 0;
|
||||||
|
if (_map_data_model) {
|
||||||
|
unit_type = _map_data_model->mapData(MapDataModel::DataType::UnitType, unit_idx).toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
UnitPresentDelegate& t = *_type_present_delegate[unit_type];
|
||||||
t.paint(&pic_painter, opt);
|
t.paint(&pic_painter, opt);
|
||||||
|
|
||||||
pic_painter.restore();
|
pic_painter.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
_updated_units.clear();
|
_updated_index_list.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPainter widget_painter(this);
|
QPainter widget_painter(this);
|
||||||
|
|
@ -197,7 +222,7 @@ void MapPresent::visible_units_tidy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto optx : _visible_units)
|
for (auto optx : _visible_units)
|
||||||
_updated_units.append(optx.index);
|
_updated_index_list.append(optx.index);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<PresentIndex> MapPresent::siblingsGet(const PresentIndex& center, uint16_t dist) const
|
QList<PresentIndex> MapPresent::siblingsGet(const PresentIndex& center, uint16_t dist) const
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -27,6 +28,24 @@ struct MAPPRESENT_EXPORT PresentIndex {
|
||||||
bool operator<(const PresentIndex& other) const;
|
bool operator<(const PresentIndex& other) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 地图数据模型
|
||||||
|
/// </summary>
|
||||||
|
class MapDataModel : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum class DataType {
|
||||||
|
UnitType,
|
||||||
|
AltMeters
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual QVariant mapData(DataType type, const PresentIndex& idx) const = 0;
|
||||||
|
virtual void mapDataSet(DataType type, const PresentIndex& idx, const QVariant& val) = 0;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void dataChanged(const PresentIndex& idx);
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 绘制选项
|
/// 绘制选项
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -39,6 +58,10 @@ struct MAPPRESENT_EXPORT PresentOption {
|
||||||
/// 当前绘制外缘
|
/// 当前绘制外缘
|
||||||
/// </summary>
|
/// </summary>
|
||||||
QRectF outline;
|
QRectF outline;
|
||||||
|
/// <summary>
|
||||||
|
/// 数据模型指针
|
||||||
|
/// </summary>
|
||||||
|
MapDataModel* dataModel = nullptr;
|
||||||
|
|
||||||
PresentOption& operator=(const PresentOption& other);
|
PresentOption& operator=(const PresentOption& other);
|
||||||
};
|
};
|
||||||
|
|
@ -68,7 +91,7 @@ signals:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新通知/重绘请求
|
/// 更新通知/重绘请求
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void updateRequest(const PresentIndex &idx);
|
void updateRequest(const PresentIndex& idx);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -78,6 +101,12 @@ class MAPPRESENT_EXPORT MapPresent : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
/// <summary>
|
||||||
|
/// 地图数据模型
|
||||||
|
/// </summary>
|
||||||
|
MapDataModel* _map_data_model = nullptr;
|
||||||
|
|
||||||
|
// ===================================
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初级区域矩形变长
|
/// 初级区域矩形变长
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -103,7 +132,7 @@ private:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 被更新的单元索引
|
/// 被更新的单元索引
|
||||||
/// </summary>
|
/// </summary>
|
||||||
QList<PresentIndex> _updated_units;
|
QList<PresentIndex> _updated_index_list;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 可视化单元整理
|
/// 可视化单元整理
|
||||||
|
|
@ -130,6 +159,18 @@ public:
|
||||||
void zoomTo(double percent);
|
void zoomTo(double percent);
|
||||||
double zoomTimes() const;
|
double zoomTimes() const;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置绘制委托
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ins"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool setDelegate(UnitPresentDelegate* ins);
|
||||||
|
/// <summary>
|
||||||
|
/// 设置地图数据模型
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
void setDataModel(MapDataModel* model);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通过widget上定位获取绘制索引
|
/// 通过widget上定位获取绘制索引
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue