src/main.cpp

changeset 299
cf9a854b56a9
parent 296
38f6fad61bad
child 309
d862721d19a3
equal deleted inserted replaced
298:9ca53009bc5c 299:cf9a854b56a9
394 // the sub window with parent=nullptr, and add it manually. 394 // the sub window with parent=nullptr, and add it manually.
395 // c.f. https://bugreports.qt.io/browse/QTBUG-69495 395 // c.f. https://bugreports.qt.io/browse/QTBUG-69495
396 SubWindow* subWindow = new SubWindow{args..., nullptr}; 396 SubWindow* subWindow = new SubWindow{args..., nullptr};
397 mdiArea->addSubWindow(subWindow); 397 mdiArea->addSubWindow(subWindow);
398 return subWindow; 398 return subWindow;
399 }
400
401 static QSet<ModelId> resolveIdsFromSelection(const ModelData* data)
402 {
403 const auto selection = data->itemSelectionModel->selection();
404 QSet<ModelId> selectedIndexes;
405 for (const QModelIndex& qindex : selection.indexes()) {
406 const std::size_t row = unsigned_cast(qindex.row());
407 selectedIndexes.insert(data->model->idAt(row));
408 }
409 return selectedIndexes;
399 } 410 }
400 411
401 int main(int argc, char *argv[]) 412 int main(int argc, char *argv[])
402 { 413 {
403 doQtRegistrations(); 414 doQtRegistrations();
511 data->itemSelectionModel.get(), 522 data->itemSelectionModel.get(),
512 &QItemSelectionModel::selectionChanged, 523 &QItemSelectionModel::selectionChanged,
513 [modelId, &documents, &toolWidgets]{ 524 [modelId, &documents, &toolWidgets]{
514 ModelData* data = findModelData(&documents, modelId); 525 ModelData* data = findModelData(&documents, modelId);
515 if (data != nullptr) { 526 if (data != nullptr) {
516 auto resolveIndex = [&data](const QModelIndex& index){ 527 data->canvas->setSelection(resolveIdsFromSelection(data));
517 return data->model->idAt(unsigned_cast(index.row()));
518 };
519 const auto selection = data->itemSelectionModel->selection();
520 const auto indices = fn::map<QSet<ModelId>>(selection.indexes(), resolveIndex);
521 data->canvas->setSelection(indices);
522 /* 528 /*
523 if (indices.size() == 1) { 529 if (indices.size() == 1) {
524 opt<std::size_t> index = data->model->find(*indices.begin()); 530 opt<std::size_t> index = data->model->find(*indices.begin());
525 if (index.has_value()) { 531 if (index.has_value()) {
526 toolWidgets.objectEditor->setObject((*data->model)[*index]); 532 toolWidgets.objectEditor->setObject((*data->model)[*index]);

mercurial