MCPcopy Create free account
hub / github.com/MITK/MITK / PopulateTasks

Method PopulateTasks

Modules/PythonSegmentationUI/src/QmitkTotalSegmentatorToolGUI.cpp:253–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251}
252
253void QmitkTotalSegmentatorToolGUI::PopulateTasks()
254{
255 // Preserve the current selection across the rebuild: PopulateTasks runs on every
256 // RefreshInstallState (e.g. after merely opening Settings), so without this the
257 // user's chosen task would silently reset to "total".
258 const QString previousTask = m_Ui->taskComboBox->currentData(TaskRole).toString();
259 const int previousSpeed = m_Ui->taskComboBox->currentData(SpeedRole).toInt();
260
261 const bool hasLicense = m_Preferences != nullptr && m_Preferences->GetBool("TotalSeg/hasLicense", false);
262
263 // Rebuild without emitting currentIndexChanged for each intermediate state; the
264 // final UpdateRunButtonState() below reflects the restored selection once.
265 m_Ui->taskComboBox->blockSignals(true);
266 m_Ui->taskComboBox->clear();
267
268 auto addItem = [&](const QString& label, const QString& task, int speed, bool licensed)
269 {
270 m_Ui->taskComboBox->addItem(label);
271 const int index = m_Ui->taskComboBox->count() - 1;
272 m_Ui->taskComboBox->setItemData(index, task, TaskRole);
273 m_Ui->taskComboBox->setItemData(index, speed, SpeedRole);
274 m_Ui->taskComboBox->setItemData(index, licensed, LicensedRole);
275
276 // Licensed tasks stay selectable. Disabling them made the drop-down misbehave
277 // (clicking a disabled entry jumped to an arbitrary enabled one); instead they
278 // get a "License required: " prefix and the Run button is gated in
279 // UpdateRunButtonState.
280 if (licensed && !hasLicense)
281 m_Ui->taskComboBox->setItemData(
282 index, QStringLiteral("Requires a TotalSegmentator license. Set it in Settings."), Qt::ToolTipRole);
283 };
284
285 for (const auto& info : TASKS)
286 {
287 const QString task = QString::fromLatin1(info.name);
288
289 // Display-only annotations; the stored task id (TaskRole) stays the bare name
290 // that TotalSegmentator expects.
291 const QString modality = task.endsWith("_mr") ? QStringLiteral(" (MR)") : QString();
292 const QString prefix = info.licensed ? QStringLiteral("License required: ") : QString();
293
294 addItem(prefix + task + modality, task, 0, info.licensed);
295
296 if (info.multiRes)
297 {
298 addItem(prefix + task + " - fast (3 mm)" + modality, task, 1, info.licensed);
299 addItem(prefix + task + " - fastest (6 mm)" + modality, task, 2, info.licensed);
300 }
301 }
302
303 // Restore the previous selection, but not a licensed task that is no longer
304 // runnable (e.g. the license was just removed) - fall back to the first entry.
305 int restored = -1;
306 for (int i = 0; i < m_Ui->taskComboBox->count(); ++i)
307 {
308 if (m_Ui->taskComboBox->itemData(i, TaskRole).toString() == previousTask &&
309 m_Ui->taskComboBox->itemData(i, SpeedRole).toInt() == previousSpeed)
310 {

Callers 1

RefreshInstallStateMethod · 0.95

Calls 6

UpdateRunButtonStateMethod · 0.95
GetBoolMethod · 0.80
countMethod · 0.80
QStringClass · 0.50
toStringMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected