geopro/src/app/panels/DatasetDetailPanel.cpp

73 lines
3.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "panels/DatasetDetailPanel.hpp"
#include <utility>
#include "panels/DatasetDetailPage.hpp"
namespace geopro::app {
void DatasetDetailPanel::setColorTemplateRepo(geopro::data::IColorTemplateRepository* repo,
std::function<QString()> projectIdGetter) {
colorTplRepo_ = repo;
projectIdGetter_ = std::move(projectIdGetter);
}
void DatasetDetailPanel::setCommandRepo(geopro::data::IDatasetCommandRepository* repo) {
cmdRepo_ = repo;
}
DatasetDetailPanel::DatasetDetailPanel(QWidget* parent) : QTabWidget(parent) {
setTabsClosable(true);
connect(this, &QTabWidget::tabCloseRequested, this, [this](int i) { widget(i)->deleteLater(); });
connect(this, &QTabWidget::currentChanged, this, [this](int i) {
if (auto* p = qobject_cast<DatasetDetailPage*>(widget(i)))
emit activeDatasetChanged(p->dsId());
});
}
DatasetDetailPage* DatasetDetailPanel::pageFor(const QString& dsId) const {
for (int i = 0; i < count(); ++i)
if (auto* p = qobject_cast<DatasetDetailPage*>(widget(i)))
if (p->dsId() == dsId) return p;
return nullptr;
}
void DatasetDetailPanel::onDatasetOpened(const QString& dsId, const QString& ddCode,
const QString& dsName, const QString& tmObjectId,
const std::vector<geopro::controller::TabSpec>& tabs) {
auto* p = pageFor(dsId);
if (!p) {
p = new DatasetDetailPage(this);
// 注入须在 build 前build 内造视图时即透传给工厂)。
p->setColorTemplateRepo(colorTplRepo_, projectIdGetter_);
p->setCommandRepo(cmdRepo_);
p->setTmObjectId(tmObjectId); // 白化 structParentIdbuild 前设置 → 透传给视图)
p->build(dsId, ddCode, dsName, tabs); // ddCode 透传 → 页内 tabNeeded 携带
const QString title = dsName.isEmpty() ? dsId : dsName; // 页签标题用数据名(空则回退 id
const int idx = addTab(p, title);
setTabToolTip(idx, title); // 名称过长被省略时悬停可见全名
// 页内 lazy 页签首次激活 → 冒泡为面板信号(外部接控制器 loadTab
connect(p, &DatasetDetailPage::tabNeeded, this, &DatasetDetailPanel::tabNeeded);
// 页内分页器翻页 → 冒泡为面板信号(外部接控制器 loadTabPaged
connect(p, &DatasetDetailPage::tabPageNeeded, this, &DatasetDetailPanel::tabPageNeeded);
}
setCurrentWidget(p);
}
void DatasetDetailPanel::onTabReady(const QString& dsId, int tabIndex, const QVariant& payload) {
if (auto* p = pageFor(dsId)) p->setTabPayload(tabIndex, payload);
}
void DatasetDetailPanel::onTabLoadStarted(const QString& dsId, int tabIndex) {
if (auto* p = pageFor(dsId)) p->setTabLoading(tabIndex, true);
}
void DatasetDetailPanel::onLoadFailed(const QString& dsId, const QString&) {
// 失败:清掉该页全部「加载中」遮罩(不假设页签数;幂等:非 lazy/已隐藏皆无害)。
if (auto* p = pageFor(dsId)) p->clearAllLoadingOverlays();
}
void DatasetDetailPanel::focusDataset(const QString& dsId) {
if (auto* p = pageFor(dsId)) setCurrentWidget(p);
}
} // namespace geopro::app