41 #include "../model/data3Dtreemodel.h"
53 #include <QDoubleSpinBox>
55 #include <QPushButton>
66 using namespace UTILSLIB;
67 using namespace DISP3DLIB;
68 using namespace DISPLIB;
69 using namespace Eigen;
75 Data3DTreeDelegate::Data3DTreeDelegate(QObject* parent)
76 : QStyledItemDelegate(parent)
82 QWidget *Data3DTreeDelegate::createEditor(QWidget* parent,
const QStyleOptionViewItem& option ,
const QModelIndex& index)
const
89 switch(pAbstractItem->type()) {
90 case MetaTreeItemTypes::SurfaceColorGyri: {
91 QColorDialog *pColorDialog =
new QColorDialog(parent);
92 connect(pColorDialog, &QColorDialog::currentColorChanged,
93 this, &Data3DTreeDelegate::onEditorEdited);
94 pColorDialog->setWindowTitle(
"Select Gyri Color");
99 case MetaTreeItemTypes::SurfaceColorSulci: {
100 QColorDialog *pColorDialog =
new QColorDialog(parent);
101 connect(pColorDialog, &QColorDialog::currentColorChanged,
102 this, &Data3DTreeDelegate::onEditorEdited);
103 pColorDialog->setWindowTitle(
"Select Sulci Color");
104 pColorDialog->show();
108 case MetaTreeItemTypes::ColormapType: {
109 QComboBox* pComboBox =
new QComboBox(parent);
110 connect(pComboBox,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
111 this, &Data3DTreeDelegate::onEditorEdited);
112 pComboBox->addItem(
"HotNegative1");
113 pComboBox->addItem(
"HotNegative2");
114 pComboBox->addItem(
"Hot");
115 pComboBox->addItem(
"Jet");
116 pComboBox->addItem(
"RedBlue");
117 pComboBox->addItem(
"Bone");
118 pComboBox->addItem(
"Cool");
119 pComboBox->addItem(
"Viridis");
120 pComboBox->addItem(
"ViridisNegated");
124 case MetaTreeItemTypes::DataThreshold: {
126 connect(pSpline,
static_cast<void (
Spline::*)(
double,
double,
double)
>(&Spline::borderChanged),
127 this, &Data3DTreeDelegate::onEditorEdited);
128 pSpline->setWindowFlags(Qt::Window);
129 pSpline->setWindowTitle(
"Set Threshold");
134 case MetaTreeItemTypes::StreamingTimeInterval: {
135 QSpinBox* pSpinBox =
new QSpinBox(parent);
136 connect(pSpinBox,
static_cast<void (QSpinBox::*)(
int)
>(&QSpinBox::valueChanged),
137 this, &Data3DTreeDelegate::onEditorEdited);
138 pSpinBox->setSuffix(
" mSec");
139 pSpinBox->setMinimum(1);
140 pSpinBox->setMaximum(50000);
141 pSpinBox->setSingleStep(1);
145 case MetaTreeItemTypes::VisualizationType: {
146 QComboBox* pComboBox =
new QComboBox(parent);
147 pComboBox->addItem(
"Interpolation based");
148 pComboBox->addItem(
"Annotation based");
152 case MetaTreeItemTypes::Color: {
153 QColorDialog *pColorDialog =
new QColorDialog(parent);
154 connect(pColorDialog, &QColorDialog::currentColorChanged,
155 this, &Data3DTreeDelegate::onEditorEdited);
156 pColorDialog->setWindowTitle(
"Select Color");
157 pColorDialog->show();
161 case MetaTreeItemTypes::NumberAverages: {
162 QSpinBox* pSpinBox =
new QSpinBox(parent);
163 connect(pSpinBox,
static_cast<void (QSpinBox::*)(
int)
>(&QSpinBox::valueChanged),
164 this, &Data3DTreeDelegate::onEditorEdited);
165 pSpinBox->setMinimum(1);
166 pSpinBox->setMaximum(100);
167 pSpinBox->setSingleStep(1);
171 case MetaTreeItemTypes::AlphaValue: {
172 QDoubleSpinBox* pDoubleSpinBox =
new QDoubleSpinBox(parent);
173 connect(pDoubleSpinBox,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
174 this, &Data3DTreeDelegate::onEditorEdited);
175 pDoubleSpinBox->setMinimum(0.01);
176 pDoubleSpinBox->setMaximum(1.0);
177 pDoubleSpinBox->setSingleStep(0.01);
178 return pDoubleSpinBox;
181 case MetaTreeItemTypes::SurfaceTessInner: {
182 QDoubleSpinBox* pDoubleSpinBox =
new QDoubleSpinBox(parent);
183 connect(pDoubleSpinBox,
static_cast<void (QDoubleSpinBox::*)()
>(&QDoubleSpinBox::editingFinished),
184 this, &Data3DTreeDelegate::onEditorEdited);
185 pDoubleSpinBox->setMinimum(1.0);
186 pDoubleSpinBox->setMaximum(100.0);
187 pDoubleSpinBox->setSingleStep(1.0);
188 return pDoubleSpinBox;
191 case MetaTreeItemTypes::SurfaceTessOuter: {
192 QDoubleSpinBox* pDoubleSpinBox =
new QDoubleSpinBox(parent);
193 connect(pDoubleSpinBox,
static_cast<void (QDoubleSpinBox::*)()
>(&QDoubleSpinBox::editingFinished),
194 this, &Data3DTreeDelegate::onEditorEdited);
195 pDoubleSpinBox->setMinimum(1.0);
196 pDoubleSpinBox->setMaximum(100.0);
197 pDoubleSpinBox->setSingleStep(1.0);
198 return pDoubleSpinBox;
201 case MetaTreeItemTypes::SurfaceTriangleScale: {
202 QDoubleSpinBox* pDoubleSpinBox =
new QDoubleSpinBox(parent);
203 connect(pDoubleSpinBox,
static_cast<void (QDoubleSpinBox::*)()
>(&QDoubleSpinBox::editingFinished),
204 this, &Data3DTreeDelegate::onEditorEdited);
205 pDoubleSpinBox->setMinimum(0.01);
206 pDoubleSpinBox->setMaximum(100.0);
207 pDoubleSpinBox->setSingleStep(0.01);
208 return pDoubleSpinBox;
211 case MetaTreeItemTypes::TranslateX: {
212 QDoubleSpinBox* pDoubleSpinBox =
new QDoubleSpinBox(parent);
213 connect(pDoubleSpinBox,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
214 this, &Data3DTreeDelegate::onEditorEdited);
215 pDoubleSpinBox->setMinimum(-10000.0);
216 pDoubleSpinBox->setMaximum(10000.0);
217 pDoubleSpinBox->setSingleStep(0.001);
218 pDoubleSpinBox->setDecimals(5);
219 return pDoubleSpinBox;
222 case MetaTreeItemTypes::TranslateY: {
223 QDoubleSpinBox* pDoubleSpinBox =
new QDoubleSpinBox(parent);
224 connect(pDoubleSpinBox,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
225 this, &Data3DTreeDelegate::onEditorEdited);
226 pDoubleSpinBox->setMinimum(-10000.0);
227 pDoubleSpinBox->setMaximum(10000.0);
228 pDoubleSpinBox->setSingleStep(0.001);
229 pDoubleSpinBox->setDecimals(5);
230 return pDoubleSpinBox;
233 case MetaTreeItemTypes::TranslateZ: {
234 QDoubleSpinBox* pDoubleSpinBox =
new QDoubleSpinBox(parent);
235 connect(pDoubleSpinBox,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
236 this, &Data3DTreeDelegate::onEditorEdited);
237 pDoubleSpinBox->setMinimum(-10000.0);
238 pDoubleSpinBox->setMaximum(10000.0);
239 pDoubleSpinBox->setSingleStep(0.001);
240 pDoubleSpinBox->setDecimals(5);
241 return pDoubleSpinBox;
244 case MetaTreeItemTypes::Scale: {
245 QDoubleSpinBox* pDoubleSpinBox =
new QDoubleSpinBox(parent);
246 connect(pDoubleSpinBox,
static_cast<void (QDoubleSpinBox::*)(
double)
>(&QDoubleSpinBox::valueChanged),
247 this, &Data3DTreeDelegate::onEditorEdited);
248 pDoubleSpinBox->setMinimum(-10000.0);
249 pDoubleSpinBox->setMaximum(10000.0);
250 pDoubleSpinBox->setSingleStep(0.01);
251 pDoubleSpinBox->setDecimals(3);
252 return pDoubleSpinBox;
255 case MetaTreeItemTypes::NetworkMatrix: {
257 QModelIndex indexParent = pData3DTreeModel->indexFromItem(pParentItem);
258 MatrixXd matRTData = index.model()->
data(indexParent, Data3DTreeModelItemRoles::Data).value<MatrixXd>();
261 pPlotLA->resize(400,300);
262 pPlotLA->setWindowFlags(Qt::Window);
265 QList<QStandardItem*> pColormapItem = pParentItem->findChildren(MetaTreeItemTypes::ColormapType);
266 for(
int i = 0; i < pColormapItem.size(); ++i) {
267 if(pColormapItem.at(i)) {
268 QModelIndex indexColormapItem = pData3DTreeModel->indexFromItem(pColormapItem.at(i));
269 QString colorMap = index.model()->
data(indexColormapItem, MetaTreeItemRoles::ColormapType).value<QString>();
270 pPlotLA->setColorMap(colorMap);
278 case MetaTreeItemTypes::MaterialType: {
279 QComboBox* pComboBox =
new QComboBox(parent);
280 pComboBox->addItem(
"Phong Alpha Tesselation");
281 pComboBox->addItem(
"Phong Alpha");
282 pComboBox->addItem(
"Show normals");
283 pComboBox->addItem(
"GPU Interpolation");
287 case MetaTreeItemTypes::CancelDistance: {
288 QDoubleSpinBox* pDoubleSpinBox =
new QDoubleSpinBox(parent);
289 pDoubleSpinBox->setMinimum(0.001);
290 pDoubleSpinBox->setMaximum(1.0);
291 pDoubleSpinBox->setSingleStep(0.01);
292 pDoubleSpinBox->setSuffix(
"m");
293 return pDoubleSpinBox;
296 case MetaTreeItemTypes::InterpolationFunction: {
297 QComboBox* pComboBox =
new QComboBox(parent);
298 connect(pComboBox,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
299 this, &Data3DTreeDelegate::onEditorEdited);
300 pComboBox->addItem(
"Linear");
301 pComboBox->addItem(
"Square");
302 pComboBox->addItem(
"Cubic");
303 pComboBox->addItem(
"Gaussian");
312 return QStyledItemDelegate::createEditor(parent, option, index);
317 void Data3DTreeDelegate::setEditorData(QWidget* editor,
const QModelIndex& index)
const
323 switch(pAbstractItem->type()) {
324 case MetaTreeItemTypes::SurfaceColorGyri: {
325 QColor color = index.model()->data(index, MetaTreeItemRoles::SurfaceColorGyri).value<QColor>();
326 QColorDialog* pColorDialog =
static_cast<QColorDialog*
>(editor);
327 pColorDialog->setCurrentColor(color);
331 case MetaTreeItemTypes::SurfaceColorSulci: {
332 QColor color = index.model()->data(index, MetaTreeItemRoles::SurfaceColorSulci).value<QColor>();
333 QColorDialog* pColorDialog =
static_cast<QColorDialog*
>(editor);
334 pColorDialog->setCurrentColor(color);
338 case MetaTreeItemTypes::Color: {
339 QColor color = index.model()->data(index, MetaTreeItemRoles::Color).value<QColor>();
340 QColorDialog* pColorDialog =
static_cast<QColorDialog*
>(editor);
341 pColorDialog->setCurrentColor(color);
345 case MetaTreeItemTypes::DataThreshold: {
349 QModelIndex indexParent = pData3DTreeModel->indexFromItem(pParentItem);
355 data = index.model()->data(indexParent, Data3DTreeModelItemRoles::Data);
357 if(data.canConvert<MatrixXd>()) {
358 matRTData = data.value<MatrixXd>();
359 matRTData = matRTData.cwiseAbs();
362 Eigen::VectorXd resultClassLimit;
363 Eigen::VectorXi resultFrequency;
364 MNEMath::histcounts(matRTData,
false, 50, resultClassLimit, resultFrequency, 0.0, 0.0);
367 pSpline->setData(resultClassLimit, resultFrequency);
368 QVector3D vecThresholdValues = index.model()->data(index, MetaTreeItemRoles::DataThreshold).value<QVector3D>();
369 pSpline->setThreshold(vecThresholdValues);
371 QList<QStandardItem*> pColormapItem = pParentItem->findChildren(MetaTreeItemTypes::ColormapType);
372 for(
int i = 0; i < pColormapItem.size(); ++i) {
373 if(pColormapItem.at(i)) {
374 QModelIndex indexColormapItem = pData3DTreeModel->indexFromItem(pColormapItem.at(i));
375 QString colorMap = index.model()->
data(indexColormapItem, MetaTreeItemRoles::ColormapType).value<QString>();
376 pSpline->setColorMap(colorMap);
382 pSpline->resize(600,400);
391 QStyledItemDelegate::setEditorData(editor, index);
398 void Data3DTreeDelegate::setModelData(QWidget* editor, QAbstractItemModel* model,
const QModelIndex& index)
const
404 switch(pAbstractItem->type()) {
405 case MetaTreeItemTypes::SurfaceColorGyri: {
406 QColorDialog* pColorDialog =
static_cast<QColorDialog*
>(editor);
407 QColor color = pColorDialog->currentColor();
409 data.setValue(color);
411 model->setData(index, data, MetaTreeItemRoles::SurfaceColorGyri);
412 model->setData(index, data, Qt::DecorationRole);
416 case MetaTreeItemTypes::SurfaceColorSulci: {
417 QColorDialog* pColorDialog =
static_cast<QColorDialog*
>(editor);
418 QColor color = pColorDialog->currentColor();
420 data.setValue(color);
422 model->setData(index, data, MetaTreeItemRoles::SurfaceColorSulci);
423 model->setData(index, data, Qt::DecorationRole);
427 case MetaTreeItemTypes::ColormapType: {
428 QComboBox* pColorMapType =
static_cast<QComboBox*
>(editor);
430 data.setValue(pColorMapType->currentText());
432 model->setData(index, data, MetaTreeItemRoles::ColormapType);
433 model->setData(index, data, Qt::DisplayRole);
437 case MetaTreeItemTypes::DataThreshold: {
439 QVector3D returnVector;
440 returnVector = pSpline->getThreshold();
442 QString displayThreshold;
443 displayThreshold = QString(
"%1,%2,%3").arg(returnVector.x()).arg(returnVector.y()).arg(returnVector.z());
445 data.setValue(displayThreshold);
446 model->setData(index, data, Qt::DisplayRole);
447 data.setValue(returnVector);
448 model->setData(index, data, MetaTreeItemRoles::DataThreshold);
453 case MetaTreeItemTypes::StreamingTimeInterval: {
454 QSpinBox* pSpinBox =
static_cast<QSpinBox*
>(editor);
457 data.setValue(pSpinBox->value());
459 model->setData(index, data, MetaTreeItemRoles::StreamingTimeInterval);
460 model->setData(index, data, Qt::DisplayRole);
464 case MetaTreeItemTypes::VisualizationType: {
465 QComboBox* pVisType =
static_cast<QComboBox*
>(editor);
467 data.setValue(pVisType->currentText());
469 model->setData(index, data, MetaTreeItemRoles::VisualizationType);
470 model->setData(index, data, Qt::DisplayRole);
474 case MetaTreeItemTypes::Color: {
475 QColorDialog* pColorDialog =
static_cast<QColorDialog*
>(editor);
476 QColor color = pColorDialog->currentColor();
478 data.setValue(color);
480 model->setData(index, data, MetaTreeItemRoles::Color);
481 model->setData(index, data, Qt::DecorationRole);
485 case MetaTreeItemTypes::NumberAverages: {
486 QSpinBox* pSpinBox =
static_cast<QSpinBox*
>(editor);
489 data.setValue(pSpinBox->value());
491 model->setData(index, data, MetaTreeItemRoles::NumberAverages);
492 model->setData(index, data, Qt::DisplayRole);
496 case MetaTreeItemTypes::AlphaValue: {
497 QDoubleSpinBox* pDoubleSpinBox =
static_cast<QDoubleSpinBox*
>(editor);
499 data.setValue(pDoubleSpinBox->value());
501 model->setData(index, data, MetaTreeItemRoles::AlphaValue);
502 model->setData(index, data, Qt::DisplayRole);
506 case MetaTreeItemTypes::SurfaceTessInner: {
507 QDoubleSpinBox* pDoubleSpinBox =
static_cast<QDoubleSpinBox*
>(editor);
509 data.setValue(pDoubleSpinBox->value());
511 model->setData(index, data, MetaTreeItemRoles::SurfaceTessInner);
512 model->setData(index, data, Qt::DisplayRole);
516 case MetaTreeItemTypes::SurfaceTessOuter: {
517 QDoubleSpinBox* pDoubleSpinBox =
static_cast<QDoubleSpinBox*
>(editor);
519 data.setValue(pDoubleSpinBox->value());
521 model->setData(index, data, MetaTreeItemRoles::SurfaceTessOuter);
522 model->setData(index, data, Qt::DisplayRole);
526 case MetaTreeItemTypes::SurfaceTriangleScale: {
527 QDoubleSpinBox* pDoubleSpinBox =
static_cast<QDoubleSpinBox*
>(editor);
529 data.setValue(pDoubleSpinBox->value());
531 model->setData(index, data, MetaTreeItemRoles::SurfaceTriangleScale);
532 model->setData(index, data, Qt::DisplayRole);
536 case MetaTreeItemTypes::TranslateX: {
537 QDoubleSpinBox* pDoubleSpinBox =
static_cast<QDoubleSpinBox*
>(editor);
539 data.setValue(pDoubleSpinBox->value());
541 model->setData(index, data, MetaTreeItemRoles::TranslateX);
542 model->setData(index, data, Qt::DisplayRole);
546 case MetaTreeItemTypes::TranslateY: {
547 QDoubleSpinBox* pDoubleSpinBox =
static_cast<QDoubleSpinBox*
>(editor);
549 data.setValue(pDoubleSpinBox->value());
551 model->setData(index, data, MetaTreeItemRoles::TranslateY);
552 model->setData(index, data, Qt::DisplayRole);
556 case MetaTreeItemTypes::TranslateZ: {
557 QDoubleSpinBox* pDoubleSpinBox =
static_cast<QDoubleSpinBox*
>(editor);
559 data.setValue(pDoubleSpinBox->value());
561 model->setData(index, data, MetaTreeItemRoles::TranslateZ);
562 model->setData(index, data, Qt::DisplayRole);
566 case MetaTreeItemTypes::Scale: {
567 QDoubleSpinBox* pDoubleSpinBox =
static_cast<QDoubleSpinBox*
>(editor);
569 data.setValue(pDoubleSpinBox->value());
571 model->setData(index, data, MetaTreeItemRoles::Scale);
572 model->setData(index, data, Qt::DisplayRole);
576 case MetaTreeItemTypes::MaterialType: {
577 QComboBox* pComboBox =
static_cast<QComboBox*
>(editor);
579 data.setValue(pComboBox->currentText());
581 model->setData(index, data, MetaTreeItemRoles::SurfaceMaterial);
582 model->setData(index, data, Qt::DisplayRole);
586 case MetaTreeItemTypes::CancelDistance: {
587 QDoubleSpinBox* pDoubleSpinBox =
static_cast<QDoubleSpinBox*
>(editor);
589 data.setValue(pDoubleSpinBox->value());
591 model->setData(index, data, MetaTreeItemRoles::CancelDistance);
592 model->setData(index, data, Qt::DisplayRole);
596 case MetaTreeItemTypes::InterpolationFunction: {
597 QComboBox* pColorMapType =
static_cast<QComboBox*
>(editor);
599 data.setValue(pColorMapType->currentText());
601 model->setData(index, data, MetaTreeItemRoles::InterpolationFunction);
602 model->setData(index, data, Qt::DisplayRole);
608 QStyledItemDelegate::setModelData(editor, model, index);
616 void Data3DTreeDelegate::updateEditorGeometry(QWidget* editor,
const QStyleOptionViewItem &option,
const QModelIndex& index)
const
618 QStyledItemDelegate::updateEditorGeometry(editor, option, index);
624 void Data3DTreeDelegate::onEditorEdited()
626 if(QWidget* editor = qobject_cast<QWidget*>(QObject::sender())) {
627 emit commitData(editor);