更新批量索引集
This commit is contained in:
parent
529abd14b4
commit
4f511a2a5d
|
|
@ -12,7 +12,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
MapPresent p;
|
||||
p.show();
|
||||
p.zoomTo(1);
|
||||
p.zoomTo(0);
|
||||
|
||||
//QObject::connect(&p, &MapPresent::mouseIn, [=]() {
|
||||
// qDebug() << "Mouse Enter";
|
||||
|
|
|
|||
|
|
@ -20,10 +20,11 @@ MapPresent::MapPresent(QWidget* parent /*= nullptr*/)
|
|||
_type_present_delegate[delegate->unitType()] = delegate;
|
||||
connect(this, &MapPresent::mouseOutNotify, delegate, &BasicUnitDelegate::hotClear);
|
||||
connect(this, &MapPresent::mouseHoverNotify, delegate, &BasicUnitDelegate::hotIndexSet);
|
||||
connect(delegate, &BasicUnitDelegate::updateRequest, [=](const PresentIndex& idx) {
|
||||
if (idx.isValid() && !_updated_index_list.contains(idx)) {
|
||||
_updated_index_list.append(idx);
|
||||
}
|
||||
connect(delegate, &BasicUnitDelegate::updateRequest, [=](const QList<PresentIndex>& list) {
|
||||
for (auto idx : list)
|
||||
if (idx.isValid() && !_updated_index_list.contains(idx)) {
|
||||
_updated_index_list.append(idx);
|
||||
}
|
||||
|
||||
this->update();
|
||||
});
|
||||
|
|
@ -33,7 +34,7 @@ MapPresent::MapPresent(QWidget* parent /*= nullptr*/)
|
|||
|
||||
void MapPresent::zoomTo(double percent)
|
||||
{
|
||||
this->_scale_times = std::max(1.0 / 2, percent);
|
||||
this->_scale_times = std::max(1.0 / 5, percent);
|
||||
this->visible_units_tidy();
|
||||
|
||||
this->update();
|
||||
|
|
@ -63,6 +64,11 @@ void MapPresent::setDataModel(MapDataModel* model)
|
|||
this->update();
|
||||
}
|
||||
|
||||
MapDataModel* MapPresent::dataModel() const
|
||||
{
|
||||
return _map_data_model;
|
||||
}
|
||||
|
||||
PresentIndex MapPresent::indexGet(const QPointF& pos) const
|
||||
{
|
||||
QList<PresentOption> templist;
|
||||
|
|
@ -193,8 +199,9 @@ void MapPresent::mouseReleaseEvent(QMouseEvent* ev)
|
|||
emit this->mouseReleaseNotify(ev);
|
||||
}
|
||||
|
||||
PresentOption AssumeOpt(PresentIndex index, QRectF rf) {
|
||||
PresentOption AssumeOpt(PresentIndex index, QRectF rf, MapDataModel *m) {
|
||||
PresentOption opt;
|
||||
opt.dataModel = m;
|
||||
opt.index = index;
|
||||
opt.outline = rf;
|
||||
return opt;
|
||||
|
|
@ -206,7 +213,7 @@ void MapPresent::visible_units_tidy() {
|
|||
QRectF curr_outline = this->rect();
|
||||
_paint_buffer = QPixmap(curr_outline.toRect().size());
|
||||
|
||||
_visible_units[_center_index] = AssumeOpt(_center_index, outlineGet(_center_index));
|
||||
_visible_units[_center_index] = AssumeOpt(_center_index, outlineGet(_center_index), _map_data_model);
|
||||
int visible_count = 1, deduce_x = 1;
|
||||
while (visible_count) {
|
||||
visible_count = 0;
|
||||
|
|
@ -215,13 +222,13 @@ void MapPresent::visible_units_tidy() {
|
|||
for (auto unit : siblings) {
|
||||
auto visible_rect = outlineGet(unit);
|
||||
if (curr_outline.intersects(visible_rect)) {
|
||||
_visible_units[unit] = AssumeOpt(unit, visible_rect);
|
||||
_visible_units[unit] = AssumeOpt(unit, visible_rect, _map_data_model);
|
||||
visible_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto optx : _visible_units)
|
||||
for (auto &optx : _visible_units)
|
||||
_updated_index_list.append(optx.index);
|
||||
}
|
||||
|
||||
|
|
@ -297,5 +304,6 @@ PresentOption& PresentOption::operator=(const PresentOption& other)
|
|||
{
|
||||
index = other.index;
|
||||
outline = other.outline;
|
||||
dataModel = other.dataModel;
|
||||
return *this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ signals:
|
|||
/// <summary>
|
||||
/// 更新通知/重绘请求
|
||||
/// </summary>
|
||||
void updateRequest(const PresentIndex& idx);
|
||||
void updateRequest(const QList<PresentIndex>& idx_list);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -170,6 +170,7 @@ public:
|
|||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
void setDataModel(MapDataModel* model);
|
||||
MapDataModel* dataModel() const;
|
||||
|
||||
/// <summary>
|
||||
/// 通过widget上定位获取绘制索引
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ void BasicUnitDelegate::hotClear()
|
|||
auto prev_idx = _hot_index;
|
||||
_hot_index = PresentIndex();
|
||||
|
||||
emit this->updateRequest(prev_idx);
|
||||
emit this->updateRequest({ prev_idx });
|
||||
}
|
||||
|
||||
void BasicUnitDelegate::hotIndexSet(const PresentIndex& idx)
|
||||
|
|
@ -81,7 +81,7 @@ void BasicUnitDelegate::hotIndexSet(const PresentIndex& idx)
|
|||
auto prev_idx = _hot_index;
|
||||
_hot_index = idx;
|
||||
|
||||
emit this->updateRequest(prev_idx);
|
||||
emit this->updateRequest(idx);
|
||||
emit this->updateRequest({ prev_idx });
|
||||
emit this->updateRequest({ idx });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue