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 101 102 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 149 150 151 152 153 154 155 156 157 158 159 160
|
/*=========================================================================
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"
#include "vtkEventQtSlotConnect.h"
#include "vtkInformation.h"
#include "vtkInformationIntegerKey.h"
#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);
// 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;
QObject::connect(this->View->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
this,
SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));
}
//----------------------------------------------------------------------------
vtkQtAnnotationView::~vtkQtAnnotationView()
{
delete this->View;
delete this->Adapter;
}
//----------------------------------------------------------------------------
QWidget* vtkQtAnnotationView::GetWidget()
{
return this->View;
}
//----------------------------------------------------------------------------
void vtkQtAnnotationView::slotQtSelectionChanged(const QItemSelection& vtkNotUsed(s1),
const QItemSelection& vtkNotUsed(s2))
{
vtkDataObject* data = this->Adapter->GetVTKDataObject();
if(!data)
return;
QModelIndexList qmi = this->View->selectionModel()->selectedRows();
vtkAnnotationLayers* curLayers = this->GetRepresentation()->GetAnnotationLink()->GetAnnotationLayers();
for(unsigned int i=0; i<curLayers->GetNumberOfAnnotations(); ++i)
{
vtkAnnotation* a = curLayers->GetAnnotation(i);
vtkAnnotation::ENABLE()->Set(a->GetInformation(),0);
}
for(int j=0; j<qmi.count(); ++j)
{
vtkAnnotation* a = curLayers->GetAnnotation(qmi[j].row());
vtkAnnotation::ENABLE()->Set(a->GetInformation(),1);
}
//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();
}
//----------------------------------------------------------------------------
void vtkQtAnnotationView::Update()
{
vtkDataRepresentation* rep = this->GetRepresentation();
if (!rep)
{
this->Adapter->reset();
this->View->update();
return;
}
// Make sure the input connection is up to date.
vtkDataObject *a = rep->GetAnnotationLink()->GetAnnotationLayers();
if (a->GetMTime() != this->LastInputMTime)
{
this->LastInputMTime = a->GetMTime();
this->Adapter->SetVTKDataObject(0);
this->Adapter->SetVTKDataObject(a);
}
this->View->update();
this->View->resizeColumnToContents(0);
this->View->resizeColumnToContents(1);
}
//----------------------------------------------------------------------------
void vtkQtAnnotationView::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
|