qMRMLTractographyDisplayTreeView.cxx 8.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
/*==============================================================================

  Program: 3D Slicer

  Copyright (c) Kitware Inc.

  See COPYRIGHT.txt
  or http://www.slicer.org/copyright/copyright.txt for details.

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

  This file was originally developed by Julien Finet, Kitware Inc.
  and was partially funded by NIH grant 3P41RR013218-12S1

==============================================================================*/

// Qt includes
#include <QDebug>
#include <QHeaderView>
#include <QMessageBox>
#include <QMouseEvent>

// CTK includes
//#include "ctkModelTester.h"

// qMRML includes
//#include "qMRMLSortFilterProxyModel.h"
//#include "qMRMLSceneTransformModel.h"
//#include "qMRMLTreeView.h"

// TractographyDisplays includes
#include "qMRMLTractographyDisplayTreeView.h"
#include "qMRMLSceneTractographyDisplayModel.h"
#include "vtkMRMLFiberBundleNode.h"
#include "vtkMRMLFiberBundleDisplayNode.h"
#include "vtkMRMLFiberBundleLineDisplayNode.h"
#include "vtkMRMLFiberBundleGlyphDisplayNode.h"
#include "vtkMRMLFiberBundleTubeDisplayNode.h"

// MRML includes


//------------------------------------------------------------------------------
/// \ingroup Slicer_QtModules_TractographyDisplay
class qMRMLTractographyDisplayTreeViewPrivate
{
  Q_DECLARE_PUBLIC(qMRMLTractographyDisplayTreeView);
protected:
  qMRMLTractographyDisplayTreeView* const q_ptr;
public:
  qMRMLTractographyDisplayTreeViewPrivate(qMRMLTractographyDisplayTreeView& object);
  void init();

  qMRMLSceneTractographyDisplayModel*           SceneModel;
  qMRMLSortFilterProxyModel* SortFilterModel;
};

//------------------------------------------------------------------------------
qMRMLTractographyDisplayTreeViewPrivate::qMRMLTractographyDisplayTreeViewPrivate(qMRMLTractographyDisplayTreeView& object)
  : q_ptr(&object)
{
  this->SceneModel = 0;
  this->SortFilterModel = 0;
}

//------------------------------------------------------------------------------
void qMRMLTractographyDisplayTreeViewPrivate::init()
{
  Q_Q(qMRMLTractographyDisplayTreeView);
  //p->qMRMLTreeView::setModel(new qMRMLItemModel(p));
  //this->SceneModel = new qMRMLSceneTractographyDisplayModel(q);
  //this->SceneModel->setColumnCount(6);

  this->SceneModel = new qMRMLSceneTractographyDisplayModel(q);
  q->setSceneModel(this->SceneModel, "TractographyDisplay");

  //this->SortFilterModel = new qMRMLSortFilterProxyModel(q);
  // we only want to show vtkMRMLTractographyDisplayNodes and vtkMRMLTractographyDisplayHierarchyNodes
  QStringList nodeTypes = QStringList();
  nodeTypes.append("vtkMRMLFiberBundleNode");
  //nodeTypes.append("vtkMRMLTractographyDisplayHierarchyNode");

  //this->SortFilterModel->setNodeTypes(nodeTypes);
  q->setNodeTypes(nodeTypes);
  this->SortFilterModel = q->sortFilterProxyModel();

  q->header()->setStretchLastSection(false);
  q->header()->setResizeMode(QHeaderView::ResizeToContents);
  q->header()->setResizeMode(0, QHeaderView::Stretch);

  //this->SortFilterModel->setSourceModel(this->SceneModel);
  //q->qMRMLTreeView::setModel(this->SortFilterModel);

  //ctkModelTester * tester = new ctkModelTester(p);
  //tester->setModel(this->SortFilterModel);

101 102
  //QObject::connect(q, SIGNAL(clicked(QModelIndex)),
  //                 q, SLOT(onClicked(QModelIndex)));
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

  /***
  QObject::connect( q->selectionModel(),
        SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
        q,
        SLOT(onSelectionChanged(QItemSelection,QItemSelection)),
        Qt::DirectConnection );
  ***/

  q->setUniformRowHeights(true);
}

//------------------------------------------------------------------------------
qMRMLTractographyDisplayTreeView::qMRMLTractographyDisplayTreeView(QWidget *_parent)
  :qMRMLTreeView(_parent)
  , d_ptr(new qMRMLTractographyDisplayTreeViewPrivate(*this))
{
  Q_D(qMRMLTractographyDisplayTreeView);
  d->init();

  // we need to enable mouse tracking to set the appropriate cursor while mouseMove occurs
  this->setMouseTracking(true);
}

//------------------------------------------------------------------------------
qMRMLTractographyDisplayTreeView::~qMRMLTractographyDisplayTreeView()
{
}

#ifndef QT_NO_CURSOR
//------------------------------------------------------------------------------
bool qMRMLTractographyDisplayTreeView::viewportEvent(QEvent* e)
{

  // reset the cursor if we leave the viewport
  if(e->type() == QEvent::Leave)
    {
    setCursor(QCursor());
    }

  return QTreeView::viewportEvent(e);
}


#endif

149 150 151 152 153 154 155
//------------------------------------------------------------------------------
void qMRMLTractographyDisplayTreeView::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight )
{
  qMRMLTreeView::dataChanged(topLeft, bottomRight);
  if (~this->currentIndex().isValid())
    this->setCurrentIndex(topLeft);
}
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177

//------------------------------------------------------------------------------
void qMRMLTractographyDisplayTreeView::onVisibilityColumnClicked(vtkMRMLNode* node)
{

  if (!node)
    {
    // no node found!
    return;
    }
}

//-----------------------------------------------------------------------------
/// Set and observe the logic
//-----------------------------------------------------------------------------
void qMRMLTractographyDisplayTreeView::setLogic(vtkSlicerFiberBundleLogic* logic)
{
  if (!logic)
    {
    return;
    }

alexy's avatar
alexy committed
178
  //Q_D(qMRMLTractographyDisplayTreeView);
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203

  this->m_Logic = logic;

  // propagate down to model
  //d->SceneModel->setLogic(this->m_Logic);

}

//------------------------------------------------------------------------------
void qMRMLTractographyDisplayTreeView::setMRMLScene(vtkMRMLScene* scene)
{
  this->Superclass::setMRMLScene(scene);
  this->setRootIndex(this->sortFilterProxyModel()->mrmlSceneIndex());
}

//------------------------------------------------------------------------------
bool qMRMLTractographyDisplayTreeView::clickDecoration(const QModelIndex& index)
{
  bool res = false;
  int type = -1;
  QModelIndex sourceIndex = this->sortFilterProxyModel()->mapToSource(index);

  vtkMRMLFiberBundleNode* fbNode = vtkMRMLFiberBundleNode::SafeDownCast(
          this->sortFilterProxyModel()->mrmlNodeFromIndex(index));

204 205 206 207
  vtkMRMLFiberBundleDisplayNode* lineDisplayNode = fbNode->GetLineDisplayNode();
  vtkMRMLFiberBundleDisplayNode* tubeDisplayNode = fbNode->GetTubeDisplayNode();
  vtkMRMLFiberBundleDisplayNode* glyphDisplayNode = fbNode->GetGlyphDisplayNode();

208 209 210 211 212 213 214 215 216
  qMRMLSceneTractographyDisplayModel* model = dynamic_cast< qMRMLSceneTractographyDisplayModel* >(this->sceneModel());
  
  if (!(sourceIndex.flags() & Qt::ItemIsEnabled))
    {
    res = false;
    }
  else if (sourceIndex.column() == model->lineVisibilityColumn())
    {
    type = 0;
217
    if (lineDisplayNode)
218
      {
219
      lineDisplayNode->SetVisibility(lineDisplayNode->GetVisibility() ? 0 : 1);
220 221 222 223 224 225
      res = true;
      }
  }
  else if (sourceIndex.column() == model->tubeVisibilityColumn())
    {
    type = 1;
226
    if (tubeDisplayNode)
227
      {
228
      tubeDisplayNode->SetVisibility(tubeDisplayNode->GetVisibility() ? 0 : 1);
229 230 231 232 233
      res = true;
      }
  }
  else if (sourceIndex.column() == model->tubeIntersectionVisibilityColumn())
    {
234
    if (tubeDisplayNode)
235
      {
236
      tubeDisplayNode->SetSliceIntersectionVisibility(tubeDisplayNode->GetSliceIntersectionVisibility() ? 0 : 1);
237 238 239 240 241 242
      res = true;
      }
  }
  else if (sourceIndex.column() == model->glyphVisibilityColumn())
    {
    type = 2;
243
    if (glyphDisplayNode)
244
      {
245
      glyphDisplayNode->SetVisibility(glyphDisplayNode->GetVisibility() ? 0 : 1);
246 247 248 249
      res = true;
      }
  }

250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
  if (glyphDisplayNode->GetVisibility() == 0 &&
      tubeDisplayNode->GetVisibility() == 0  &&
      lineDisplayNode->GetVisibility() == 1)
    {
    type = 0;
    }
  if (glyphDisplayNode->GetVisibility() == 0 &&
      tubeDisplayNode->GetVisibility() == 1  &&
      lineDisplayNode->GetVisibility() == 0)
    {
    type = 1;
    }
  if (glyphDisplayNode->GetVisibility() == 1 &&
      tubeDisplayNode->GetVisibility() == 0  &&
      lineDisplayNode->GetVisibility() == 0)
    {
    type = 2;
    }

269 270 271 272 273 274 275 276 277 278
  if (res)
    {
    emit decorationClicked(index);
    }
  if (type > -1)
    {
    emit visibilityChanged(type);
    }
  return res;
}