vtkQtAnnotationView.cxx 5.27 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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkQtAnnotationView.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
/*-------------------------------------------------------------------------
  Copyright 2008 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/

#include "vtkQtAnnotationView.h"

#include <QHeaderView>
#include <QItemSelection>
#include <QTableView>

#include "vtkAbstractArray.h"
#include "vtkAlgorithm.h"
#include "vtkAlgorithmOutput.h"
#include "vtkAnnotation.h"
#include "vtkAnnotationLink.h"
#include "vtkAnnotationLayers.h"
#include "vtkCommand.h"
#include "vtkConvertSelection.h"
#include "vtkDataRepresentation.h"
#include "vtkDataSetAttributes.h"
#include "vtkIdList.h"
#include "vtkIdTypeArray.h"
39
#include "vtkEventQtSlotConnect.h"
40 41
#include "vtkInformation.h"
#include "vtkInformationIntegerKey.h"
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#include "vtkIntArray.h"
#include "vtkObjectFactory.h"
#include "vtkQtAnnotationLayersModelAdapter.h"
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkSmartPointer.h"
#include "vtkTable.h"
#include "vtkVariantArray.h"

vtkStandardNewMacro(vtkQtAnnotationView);

//----------------------------------------------------------------------------
vtkQtAnnotationView::vtkQtAnnotationView()
{
  this->View = new QTableView();
  this->Adapter = new vtkQtAnnotationLayersModelAdapter();
  this->View->setModel(this->Adapter);
59

60 61 62 63 64 65 66 67 68 69 70 71 72 73
  // Set up some default properties
  this->View->setSelectionMode(QAbstractItemView::ExtendedSelection);
  this->View->setSelectionBehavior(QAbstractItemView::SelectRows);
  this->View->setAlternatingRowColors(true);
  this->View->setSortingEnabled(true);
  this->View->setDragEnabled(true);
  this->View->setDragDropMode(QAbstractItemView::InternalMove);
  this->View->setDragDropOverwriteMode(false);
  this->View->setAcceptDrops(true);
  this->View->setDropIndicatorShown(true);
  this->View->horizontalHeader()->show();

  this->LastInputMTime = 0;

74
  QObject::connect(this->View->selectionModel(),
75
      SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
76
      this,
77 78 79 80 81 82
      SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));
}

//----------------------------------------------------------------------------
vtkQtAnnotationView::~vtkQtAnnotationView()
{
83
  delete this->View;
84 85 86 87 88 89 90 91 92 93
  delete this->Adapter;
}

//----------------------------------------------------------------------------
QWidget* vtkQtAnnotationView::GetWidget()
{
  return this->View;
}

//----------------------------------------------------------------------------
94
void vtkQtAnnotationView::slotQtSelectionChanged(const QItemSelection& vtkNotUsed(s1),
95
  const QItemSelection& vtkNotUsed(s2))
96
{
97 98 99 100 101
  vtkDataObject* data = this->Adapter->GetVTKDataObject();
  if(!data)
    return;

  QModelIndexList qmi = this->View->selectionModel()->selectedRows();
102
  vtkAnnotationLayers* curLayers = this->GetRepresentation()->GetAnnotationLink()->GetAnnotationLayers();
103
  for(unsigned int i=0; i<curLayers->GetNumberOfAnnotations(); ++i)
104
  {
105
    vtkAnnotation* a = curLayers->GetAnnotation(i);
106
    vtkAnnotation::ENABLE()->Set(a->GetInformation(),0);
107
  }
108 109

  for(int j=0; j<qmi.count(); ++j)
110
  {
111
    vtkAnnotation* a = curLayers->GetAnnotation(qmi[j].row());
112
    vtkAnnotation::ENABLE()->Set(a->GetInformation(),1);
113
  }
114

115 116 117 118 119 120 121 122 123 124 125
  //vtkSmartPointer<vtkAnnotationLayers> annotations;
  //annotations.TakeReference(this->Adapter->QModelIndexListToVTKAnnotationLayers(qmi));
  //for(int i=0; i<annotations->GetNumberOfAnnotations(); ++i)
  //  {
  //  vtkAnnotation* a = annotations->GetAnnotation(i);
  //  a->ENABLED().Set(1);
  //  }
  //this->GetRepresentation()->GetAnnotationLink()->SetAnnotationLayers(annotations);
  this->InvokeEvent(vtkCommand::AnnotationChangedEvent, reinterpret_cast<void*>(curLayers));

  this->LastInputMTime = this->GetRepresentation()->GetAnnotationLink()->GetAnnotationLayers()->GetMTime();
126 127 128 129 130 131 132
}

//----------------------------------------------------------------------------
void vtkQtAnnotationView::Update()
{
  vtkDataRepresentation* rep = this->GetRepresentation();
  if (!rep)
133
  {
134 135 136
    this->Adapter->reset();
    this->View->update();
    return;
137
  }
138 139 140 141

  // Make sure the input connection is up to date.
  vtkDataObject *a = rep->GetAnnotationLink()->GetAnnotationLayers();
  if (a->GetMTime() != this->LastInputMTime)
142
  {
143
    this->LastInputMTime = a->GetMTime();
144

145
    this->Adapter->SetVTKDataObject(nullptr);
146
    this->Adapter->SetVTKDataObject(a);
147
  }
148 149 150 151 152 153 154 155 156 157 158 159 160

  this->View->update();

  this->View->resizeColumnToContents(0);
  this->View->resizeColumnToContents(1);
}

//----------------------------------------------------------------------------
void vtkQtAnnotationView::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
}