21 #include <QTreeWidget> 22 #include <QTreeWidgetItem> 23 #include <QStringList> 24 #include <QVBoxLayout> 25 #include <QHeaderView> 50 BaseWidget(parent,
"metric_widget",
"Metrics/3D ruler"),
51 mVerticalLayout(new QVBoxLayout(this)),
52 mTable(new QTableWidget(this)),
57 int lowUpdateRate = 100;
58 mLocalModified =
false;
59 mDelayedUpdateTimer =
new QTimer(
this);
60 connect(mDelayedUpdateTimer, SIGNAL(timeout()),
this, SLOT(
delayedUpdate()));
61 mDelayedUpdateTimer->start(lowUpdateRate);
62 this->setToolTip(
"3D measurements");
66 mMetricManager.reset(
new MetricManager(services->view(), services->patient(), services->tracking(), services->spaceProvider(), services->file()));
67 connect(mMetricManager.get(), SIGNAL(activeMetricChanged()),
this, SLOT(
setModified()));
68 connect(mMetricManager.get(), SIGNAL(metricsChanged()),
this, SLOT(
setModified()));
72 connect(mTable, SIGNAL(cellChanged(
int,
int)),
this, SLOT(
cellChangedSlot(
int,
int)));
73 connect(mTable, SIGNAL(cellClicked(
int,
int)),
this, SLOT(
cellClickedSlot(
int,
int)));
75 this->setLayout(mVerticalLayout);
77 mEditWidgets =
new QStackedWidget;
79 QActionGroup* group =
new QActionGroup(
this);
80 this->createActions(group);
85 QWidget* toolBar =
new QWidget(
this);
86 QHBoxLayout* toolLayout =
new QHBoxLayout(toolBar);
87 toolLayout->setMargin(0);
88 toolLayout->setSpacing(0);
89 QList<QAction*> actions = group->actions();
90 for (
unsigned i=0; i<actions.size(); ++i)
92 if (actions[i]->isSeparator())
94 toolLayout->addSpacing(4);
95 QFrame* frame =
new QFrame();
96 frame->setFrameStyle(QFrame::Sunken + QFrame::VLine);
97 toolLayout->addWidget(frame);
98 toolLayout->addSpacing(4);
103 button->setDefaultAction(actions[i]);
104 button->setIconSize(QSize(32,32));
105 toolLayout->addWidget(button);
109 QHBoxLayout* buttonLayout =
new QHBoxLayout;
110 buttonLayout->addWidget(toolBar);
111 buttonLayout->addStretch();
114 mVerticalLayout->addLayout(buttonLayout);
115 mVerticalLayout->addWidget(mTable, 1);
116 mVerticalLayout->addWidget(mEditWidgets, 0);
122 void MetricWidget::createActions(QActionGroup* group)
128 this->createAction(group,
":/icons/metric_angle.png",
"Angle",
"Create a new Angle Metric", SLOT(
addAngleButtonClickedSlot()));
129 this->createAction(group,
":/icons/metric_plane.png",
"Plane",
"Create a new Plane Metric", SLOT(
addPlaneButtonClickedSlot()));
130 this->createAction(group,
":/icons/metric_sphere.png",
"Sphere",
"Create a new Sphere Metric", SLOT(
addSphereButtonClickedSlot()));
131 this->createAction(group,
":/icons/metric_torus.png",
"Torus",
"Create a new Torus Metric", SLOT(
addDonutButtonClickedSlot()));
132 this->createAction(group,
":/icons/metric_custom.png",
"Custom",
"Create a new Custom Metric", SLOT(
addCustomButtonClickedSlot()));
133 this->createAction(group,
":/icons/metric.png",
"ROI",
"Create a new Region of Interest Metric", SLOT(
addROIButtonClickedSlot()));
135 this->createAction(group,
"",
"",
"", NULL)->setSeparator(
true);
136 mRemoveAction = this->createAction(group,
":/icons/metric_remove.png",
"Remove",
"Remove currently selected metric", SLOT(
removeButtonClickedSlot()));
137 mRemoveAction->setDisabled(
true);
138 mLoadReferencePointsAction = this->createAction(group,
":/icons/metric_reference.png",
"Import",
"Import reference points from reference tool", SLOT(
loadReferencePointsSlot()));
139 mLoadReferencePointsAction->setDisabled(
true);
140 this->createAction(group,
"",
"",
"", NULL)->setSeparator(
true);
146 QAction* MetricWidget::createAction(QActionGroup* group, QString iconName, QString text, QString tip,
const char* slot)
148 QAction* action =
new QAction(QIcon(iconName), text, group);
149 action->setStatusTip(tip);
150 action->setToolTip(tip);
153 connect(action, SIGNAL(triggered()),
this, slot);
162 QTableWidgetItem* item = mTable->item(row,col);
163 DataPtr data =
mServices->patient()->getData(item->data(Qt::UserRole).toString());
165 data->setName(item->text());
172 if (row < 0 || column < 0)
175 QTableWidgetItem* item = mTable->item(row,column);
176 QString uid = item->data(Qt::UserRole).toString();
177 mMetricManager->moveToMetric(uid);
182 QTableWidgetItem* item = mTable->currentItem();
184 mMetricManager->setActiveUid(item->data(Qt::UserRole).toString());
185 mEditWidgets->setCurrentIndex(mTable->currentRow());
187 mMetricManager->setSelection(this->getSelectedUids());
192 void MetricWidget::showEvent(QShowEvent* event)
194 QWidget::showEvent(event);
198 void MetricWidget::hideEvent(QHideEvent* event)
200 QWidget::hideEvent(event);
203 void MetricWidget::prePaintEvent()
213 bool rebuild = !this->checkEqual(newMetrics, mMetrics);
216 this->resetWrappersAndEditWidgets(newMetrics);
217 this->initializeTable();
220 this->updateMetricWrappers();
221 this->updateTableContents();
225 this->expensizeColumnResize();
228 this->enablebuttons();
233 void MetricWidget::expensizeColumnResize()
236 mTable->resizeColumnToContents(valueColumn);
239 void MetricWidget::initializeTable()
241 mTable->blockSignals(
true);
245 mTable->setRowCount(mMetrics.size());
246 mTable->setColumnCount(4);
247 QStringList headerItems(QStringList() <<
"Name" <<
"Value" <<
"Arguments" <<
"Type");
248 mTable->setHorizontalHeaderLabels(headerItems);
250 mTable->setSelectionBehavior(QAbstractItemView::SelectRows);
251 mTable->verticalHeader()->hide();
253 for (
unsigned i = 0; i < mMetrics.size(); ++i)
257 for (
unsigned j = 0; j < 4; ++j)
259 QTableWidgetItem* item =
new QTableWidgetItem(
"empty");
260 item->setData(Qt::UserRole, current->getData()->getUid());
261 mTable->setItem(i, j, item);
264 mTable->blockSignals(
false);
267 void MetricWidget::updateMetricWrappers()
269 for (
unsigned i = 0; i < mMetrics.size(); ++i)
271 mMetrics[i]->update();
275 void MetricWidget::updateTableContents()
277 mTable->blockSignals(
true);
282 for (
unsigned i = 0; i < mMetrics.size(); ++i)
285 if (!mTable->item(i,0))
287 std::cout <<
"no qitem for:: " << i <<
" " << current->getData()->getName() << std::endl;
290 QString name = current->getData()->getName();
291 QString value = current->getValue();
292 QString arguments = current->getArguments();
293 QString type = current->getType();
295 mTable->item(i,0)->setText(name);
296 mTable->item(i,1)->setText(value);
297 mTable->item(i,2)->setText(arguments);
298 mTable->item(i,3)->setText(type);
301 if (current->getData()->getUid() == mMetricManager->getActiveUid())
303 mTable->setCurrentCell(i,1);
304 mEditWidgets->setCurrentIndex(i);
307 mTable->blockSignals(
false);
312 mLocalModified =
true;
322 mLocalModified =
false;
326 void MetricWidget::resetWrappersAndEditWidgets(std::vector<MetricBasePtr> wrappers)
328 while (mEditWidgets->count())
330 mEditWidgets->removeWidget(mEditWidgets->widget(0));
333 for (
unsigned i=0; i<mMetrics.size(); ++i)
335 disconnect(mMetrics[i]->getData().
get(), SIGNAL(transformChanged()),
this, SLOT(
setModified()));
340 for (
unsigned i=0; i<mMetrics.size(); ++i)
342 connect(mMetrics[i]->getData().
get(), SIGNAL(transformChanged()),
this, SLOT(
setModified()));
345 for (
unsigned i=0; i<mMetrics.size(); ++i)
348 QGroupBox* groupBox =
new QGroupBox(wrapper->getData()->getName(),
this);
349 groupBox->setFlat(
true);
350 QVBoxLayout* gbLayout =
new QVBoxLayout(groupBox);
351 gbLayout->setMargin(4);
352 gbLayout->addWidget(wrapper->createWidget());
353 mEditWidgets->addWidget(groupBox);
356 mEditWidgets->setCurrentIndex(-1);
359 bool MetricWidget::checkEqual(
const std::vector<MetricBasePtr>& a,
const std::vector<MetricBasePtr>& b)
const 361 if (a.size()!=b.size())
364 for (
unsigned i=0; i<a.size(); ++i)
366 if (a[i]->getData()!=b[i]->getData())
373 void MetricWidget::enablebuttons()
375 mRemoveAction->setEnabled(!mMetricManager->getActiveUid().isEmpty());
376 mLoadReferencePointsAction->setEnabled(
mServices->tracking()->getReferenceTool() ?
true :
false);
381 mMetricManager->loadReferencePointsSlot();
385 mMetricManager->addPointButtonClickedSlot();
389 mMetricManager->addFrameButtonClickedSlot();
393 mMetricManager->addToolButtonClickedSlot();
397 mMetricManager->addPlaneButtonClickedSlot();
401 mMetricManager->addAngleButtonClickedSlot();
405 mMetricManager->addDistanceButtonClickedSlot();
409 mMetricManager->addROIButtonClickedSlot();
413 mMetricManager->addSphereButtonClickedSlot();
417 mMetricManager->addDonutButtonClickedSlot();
421 mMetricManager->addCustomButtonClickedSlot();
424 std::set<QString> MetricWidget::getSelectedUids()
426 QList<QTableWidgetItem*> selection = mTable->selectedItems();
428 std::set<QString> selectedUids;
429 for (
int i=0; i<selection.size(); ++i)
431 selectedUids.insert(selection[i]->data(Qt::UserRole).
toString());
438 int nextIndex = mTable->currentRow() + 1;
440 if (nextIndex < mTable->rowCount())
442 QTableWidgetItem* nextItem = mTable->item(nextIndex, 0);
443 nextUid = nextItem->data(Qt::UserRole).toString();
446 mServices->patient()->removeData(mMetricManager->getActiveUid());
448 if (!nextUid.isEmpty())
449 mMetricManager->setActiveUid(nextUid);
454 QString suggestion = QString(
"%1/Logs/metrics_%2.xml")
455 .arg(
mServices->patient()->getActivePatientFolder())
458 QString filename = QFileDialog::getSaveFileName(
this,
459 "Select the file to export the metrics to",
461 if(!filename.isEmpty())
462 mMetricManager->exportMetricsToXMLFile(filename);
467 QString suggestion = QString(
"%1/Logs/")
468 .arg(
mServices->patient()->getActivePatientFolder());
470 QString fileName = QFileDialog::getOpenFileName(
this,
471 "Select the file to import metrics from (can be a patient file)",
475 if(!fileName.isEmpty() && fileName.endsWith(
".xml"))
476 mMetricManager->importMetricsFromXMLFile(fileName);
boost::shared_ptr< class VisServices > VisServicesPtr
std::string toString(T const &value)
converts any type to a string
std::vector< MetricBasePtr > createMetricWrappers()
QString timestampSecondsFormat()
boost::shared_ptr< class Data > DataPtr
boost::shared_ptr< class MetricBase > MetricBasePtr
Namespace for all CustusX production code.