Commit f60dee46 authored by Jeff Baumes's avatar Jeff Baumes

ENH: QtView class cleanup.

 - ENH: The adapter now handles vtk/qt selection conversion.

 - ENH: Removed lots of 'maps'

 - COMP: Fix ambiguous calls to createIndex by casting vtkIdType to int.

 - BUG: Fixing an over aggressive error message.

 - COMP: Use new selection conversion api in vtkQtAbstractModelAdapter.
parent 4389e571
......@@ -15,6 +15,7 @@
#include <vtkDataObjectToTable.h>
#include <vtkDataRepresentation.h>
#include <vtkGraphLayoutView.h>
#include <vtkQtColumnView.h>
#include <vtkQtTableModelAdapter.h>
#include <vtkQtTableView.h>
#include <vtkQtTreeModelAdapter.h>
......@@ -49,7 +50,7 @@ EasyView::EasyView()
this->GraphView = vtkSmartPointer<vtkGraphLayoutView>::New();
this->TreeView = vtkSmartPointer<vtkQtTreeView>::New();
this->TableView = vtkSmartPointer<vtkQtTableView>::New();
this->ColumnView = vtkSmartPointer<vtkQtTreeView>::New();
this->ColumnView = vtkSmartPointer<vtkQtColumnView>::New();
// Set widgets for the tree and table views
QVBoxLayout *layout1 = new QVBoxLayout;
......@@ -87,13 +88,14 @@ void EasyView::SetupSelectionLink()
VTK_CREATE(vtkSelectionLink,selectionLink);
this->TreeView->GetRepresentation()->SetSelectionLink(selectionLink);
this->TableView->GetRepresentation()->SetSelectionLink(selectionLink);
this->ColumnView->GetRepresentation()->SetSelectionLink(selectionLink);
this->GraphView->GetRepresentation()->SetSelectionLink(selectionLink);
VTK_CREATE(vtkViewUpdater,updater);
updater->AddView(this->TreeView);
updater->AddView(this->TableView);
updater->AddView(this->ColumnView);
updater->AddView(this->GraphView);
}
EasyView::~EasyView()
......@@ -153,7 +155,6 @@ void EasyView::slotOpenXMLFile()
// Now hand off tree to the tree view
this->TreeView->SetRepresentationFromInputConnection(this->XMLReader->GetOutputPort());
this->ColumnView->SetRepresentationFromInputConnection(this->XMLReader->GetOutputPort());
qobject_cast<QTreeView*>(this->TreeView->GetWidget())->expandAll();
// Extract a table and give to table view
VTK_CREATE(vtkDataObjectToTable, toTable);
......
......@@ -27,6 +27,7 @@ class Ui_EasyView;
// Forward VTK class declarations
class vtkXMLTreeReader;
class vtkGraphLayoutView;
class vtkQtColumnView;
class vtkQtTableView;
class vtkQtTreeView;
......@@ -61,7 +62,7 @@ private:
vtkSmartPointer<vtkGraphLayoutView> GraphView;
vtkSmartPointer<vtkQtTreeView> TreeView;
vtkSmartPointer<vtkQtTableView> TableView;
vtkSmartPointer<vtkQtTreeView> ColumnView;
vtkSmartPointer<vtkQtColumnView> ColumnView;
// Designer form
Ui_EasyView *ui;
......
......@@ -58,12 +58,14 @@ int TestQtTableModelAdapter(int, char*[])
for (int i = 0; i < numRows; ++i)
{
QModelIndex ind = adapter.index(i, 0);
#if 0 // FIXME to work with new selection conversion routines
QModelIndex pind = adapter.PedigreeToQModelIndex(i);
if (ind != pind)
{
cerr << "ERROR: Pedigree lookup failed." << endl;
++errors;
}
#endif
if (adapter.rowCount(ind) != 0)
{
cerr << "ERROR: Row should have zero sub-rows." << endl;
......
......@@ -97,12 +97,14 @@ int TestQtTreeModelAdapter(int, char*[])
parent = ind1;
rows = 0;
}
#if 0 // FIXME to work with new selection conversion routines
QModelIndex pind = adapter.PedigreeToQModelIndex(i);
if (ind != pind)
{
cerr << "ERROR: Pedigree lookup failed." << endl;
++errors;
}
#endif
if (adapter.rowCount(ind) != rows)
{
cerr << "ERROR: Row should have zero sub-rows." << endl;
......
......@@ -38,8 +38,7 @@
class vtkDataObject;
#include <QAbstractItemModel>
class QModelIndex;
#include <QItemSelection>
class QVTK_EXPORT vtkQtAbstractModelAdapter : public QAbstractItemModel
{
......@@ -59,8 +58,7 @@ public:
ViewType(FULL_VIEW),
KeyColumn(-1),
DataStartColumn(-1),
DataEndColumn(-1),
ViewRows(true)
DataEndColumn(-1)
{ }
// Description:
......@@ -69,11 +67,11 @@ public:
virtual vtkDataObject* GetVTKDataObject() const = 0;
// Description:
// Mapping methods for converting from VTK land to Qt land
virtual vtkIdType IdToPedigree(vtkIdType id) const = 0;
virtual vtkIdType PedigreeToId(vtkIdType pedigree) const = 0;
virtual QModelIndex PedigreeToQModelIndex(vtkIdType id) const = 0;
virtual vtkIdType QModelIndexToPedigree(QModelIndex index) const = 0;
// Selection conversion from VTK land to Qt land
virtual vtkSelection* QModelIndexListToVTKIndexSelection(
const QModelIndexList qmil) const = 0;
virtual QItemSelection VTKIndexSelectionToQItemSelection(
vtkSelection *vtksel) const = 0;
// Description:
// Set/Get the view type.
......@@ -101,22 +99,11 @@ public:
virtual void SetDataColumnRange(int c1, int c2)
{ this->DataStartColumn = c1; this->DataEndColumn = c2; }
virtual bool GetViewRows()
{ return this->ViewRows; }
// We make the reset() method public because it isn't always possible for
// an adapter to know when its input has changed, so it must be callable
// by an outside entity.
void reset() { QAbstractItemModel::reset(); }
public slots:
// Description:
// Sets the view to either rows (standard) or columns.
// When viewing columns, each row in the item model will contain the name
// of a column in the underlying data object.
// This essentially flips the table on its side.
void SetViewRows(bool b)
{ this->ViewRows = b; this->reset(); emit this->modelChanged(); }
signals:
void modelChanged();
......@@ -128,7 +115,6 @@ protected:
int KeyColumn;
int DataStartColumn;
int DataEndColumn;
bool ViewRows;
};
#endif
......@@ -37,7 +37,7 @@
#include "vtkSmartPointer.h"
#include "vtkTree.h"
vtkCxxRevisionMacro(vtkQtColumnView, "1.2");
vtkCxxRevisionMacro(vtkQtColumnView, "1.3");
vtkStandardNewMacro(vtkQtColumnView);
......@@ -47,13 +47,14 @@ vtkQtColumnView::vtkQtColumnView()
this->ColumnView = new QColumnView();
this->TreeAdapter = new vtkQtTreeModelAdapter();
this->ColumnView->setModel(this->TreeAdapter);
this->ColumnView->setSelectionMode(QAbstractItemView::SingleSelection);
this->ColumnView->setSelectionMode(QAbstractItemView::ExtendedSelection);
this->ColumnView->setSelectionBehavior(QAbstractItemView::SelectRows);
this->Selecting = false;
QObject::connect(this->ColumnView->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
this,
SLOT(slotSelectionChanged(const QItemSelection&,const QItemSelection&)));
SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));
}
//----------------------------------------------------------------------------
......@@ -73,9 +74,9 @@ QWidget* vtkQtColumnView::GetWidget()
}
//----------------------------------------------------------------------------
vtkQtAbstractModelAdapter* vtkQtColumnView::GetItemModelAdapter()
void vtkQtColumnView::SetAlternatingRowColors(bool state)
{
return this->TreeAdapter;
this->ColumnView->setAlternatingRowColors(state);
}
//----------------------------------------------------------------------------
......@@ -91,7 +92,7 @@ void vtkQtColumnView::AddInputConnection( int vtkNotUsed(port), int vtkNotUsed(i
// Enforce input
if (!tree)
{
vtkErrorMacro("vtkQtERMView requires a vtkTree as input (for now)");
vtkErrorMacro("vtkQtColumnView requires a vtkTree as input");
return;
}
......@@ -118,40 +119,66 @@ void vtkQtColumnView::RemoveInputConnection(int vtkNotUsed(port), int vtkNotUsed
}
//----------------------------------------------------------------------------
void vtkQtColumnView::slotSelectionChanged(const QItemSelection& vtkNotUsed(s1), const QItemSelection& vtkNotUsed(s2))
void vtkQtColumnView::slotQtSelectionChanged(const QItemSelection& vtkNotUsed(s1), const QItemSelection& vtkNotUsed(s2))
{
this->Selecting = true;
// Create index selection
vtkSmartPointer<vtkSelection> selection =
vtkSmartPointer<vtkSelection>::New();
vtkSmartPointer<vtkSelectionNode> node =
vtkSmartPointer<vtkSelectionNode>::New();
node->SetContentType(vtkSelectionNode::INDICES);
node->SetFieldType(vtkSelectionNode::VERTEX);
vtkSmartPointer<vtkIdTypeArray> idarr =
vtkSmartPointer<vtkIdTypeArray>::New();
node->SetSelectionList(idarr);
selection->AddNode(node);
const QModelIndexList list = this->ColumnView->selectionModel()->selectedRows();
// For index selection do this odd little dance with two maps :)
for (int i = 0; i < list.size(); i++)
{
vtkIdType pid = this->TreeAdapter->QModelIndexToPedigree(list.at(i));
idarr->InsertNextValue(this->TreeAdapter->PedigreeToId(pid));
}
// Convert from a QModelIndexList to an index based vtkSelection
const QModelIndexList qmil = this->ColumnView->selectionModel()->selectedRows();
vtkSelection *VTKIndexSelectList = this->TreeAdapter->QModelIndexListToVTKIndexSelection(qmil);
// Convert to the correct type of selection
vtkDataObject* data = this->TreeAdapter->GetVTKDataObject();
vtkSmartPointer<vtkSelection> converted;
converted.TakeReference(vtkConvertSelection::ToSelectionType(
selection, data, this->SelectionType, this->SelectionArrayNames));
VTKIndexSelectList, data, this->SelectionType, this->SelectionArrayNames));
// Call select on the representation
this->GetRepresentation()->Select(this, converted);
this->Selecting = false;
// Delete the selection list
VTKIndexSelectList->Delete();
}
//----------------------------------------------------------------------------
void vtkQtColumnView::SetVTKSelection()
{
// Make the selection current
if (this->Selecting)
{
// If we initiated the selection, do nothing.
return;
}
// See if the selection has changed in any way
vtkDataRepresentation* rep = this->GetRepresentation();
vtkDataObject *d = this->TreeAdapter->GetVTKDataObject();
vtkSelection* s = rep->GetSelectionLink()->GetSelection();
if (s->GetMTime() != this->CurrentSelectionMTime)
{
this->CurrentSelectionMTime = s->GetMTime();
vtkSmartPointer<vtkSelection> selection;
selection.TakeReference(vtkConvertSelection::ToIndexSelection(s, d));
QItemSelection qisList = this->TreeAdapter->
VTKIndexSelectionToQItemSelection(selection);
// Here we want the qt model to have it's selection changed
// but we don't want to emit the selection.
QObject::disconnect(this->ColumnView->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
this, SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));
this->ColumnView->selectionModel()->select(qisList,
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
QObject::connect(this->ColumnView->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
this, SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));
}
}
//----------------------------------------------------------------------------
......@@ -176,30 +203,10 @@ void vtkQtColumnView::Update()
return;
}
vtkSelection* s = rep->GetSelectionLink()->GetSelection();
vtkSmartPointer<vtkSelection> selection;
selection.TakeReference(vtkConvertSelection::ToIndexSelection(s, d));
QItemSelection list;
vtkSelectionNode* node = selection->GetNode(0);
if (node)
{
vtkIdTypeArray* arr = vtkIdTypeArray::SafeDownCast(node->GetSelectionList());
if (arr)
{
for (vtkIdType i = 0; i < arr->GetNumberOfTuples(); i++)
{
vtkIdType id = arr->GetValue(i);
QModelIndex index =
this->TreeAdapter->PedigreeToQModelIndex(
this->TreeAdapter->IdToPedigree(id));
list.select(index, index);
}
}
}
this->ColumnView->selectionModel()->select(list,
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
// Update the VTK selection
this->SetVTKSelection();
// Refresh the view
this->ColumnView->update();
}
......
......@@ -31,6 +31,7 @@
#include "QVTKWin32Header.h"
#include "vtkQtView.h"
#include <QPointer>
#include "vtkQtAbstractModelAdapter.h"
......@@ -55,9 +56,8 @@ public:
virtual QWidget* GetWidget();
// Description:
// Pointer to the internal model adapter used convert the
// vtkDataObject to a QAbstractItemModel.
vtkQtAbstractModelAdapter* GetItemModelAdapter();
// Have the view alternate its row colors
void SetAlternatingRowColors(bool);
// Description:
// Updates the view.
......@@ -81,18 +81,18 @@ protected:
vtkAlgorithmOutput* selectionConn);
private slots:
void slotSelectionChanged(const QItemSelection&,const QItemSelection&);
void slotQtSelectionChanged(const QItemSelection&,const QItemSelection&);
private:
vtkQtColumnView(const vtkQtColumnView&); // Not implemented.
void operator=(const vtkQtColumnView&); // Not implemented.
// Description:
// We need to keep track of whether were in selection mode
bool Selecting;
void SetVTKSelection();
unsigned long CurrentSelectionMTime;
QPointer<QColumnView> ColumnView;
vtkQtTreeModelAdapter* TreeAdapter;
bool Selecting;
vtkQtColumnView(const vtkQtColumnView&); // Not implemented.
void operator=(const vtkQtColumnView&); // Not implemented.
};
#endif
......@@ -42,7 +42,7 @@
#include "vtkSmartPointer.h"
#include "vtkVariant.h"
vtkCxxRevisionMacro(vtkQtItemView, "1.7");
vtkCxxRevisionMacro(vtkQtItemView, "1.8");
vtkStandardNewMacro(vtkQtItemView);
......@@ -209,31 +209,15 @@ void vtkQtItemView::QtSelectionChanged(const QItemSelection&, const QItemSelecti
this->Selecting = true;
// Create index selection
vtkSmartPointer<vtkSelection> selection =
vtkSmartPointer<vtkSelection>::New();
vtkSmartPointer<vtkSelectionNode> node =
vtkSmartPointer<vtkSelectionNode>::New();
node->SetContentType(vtkSelectionNode::INDICES);
node->SetFieldType(vtkSelectionNode::VERTEX);
vtkSmartPointer<vtkIdTypeArray> idarr =
vtkSmartPointer<vtkIdTypeArray>::New();
node->SetSelectionList(idarr);
selection->AddNode(node);
const QModelIndexList list = this->GetSelectionModel()->selectedRows();
// Convert from a QModelIndexList to an index based vtkSelection
const QModelIndexList qmil = this->ItemViewPtr->selectionModel()->selectedRows();
vtkSelection *VTKIndexSelectList = this->ModelAdapterPtr->QModelIndexListToVTKIndexSelection(qmil);
// For index selection do this odd little dance with two maps :)
for (int i = 0; i < list.size(); i++)
{
vtkIdType pid = this->ModelAdapterPtr->QModelIndexToPedigree(list.at(i));
idarr->InsertNextValue(this->ModelAdapterPtr->PedigreeToId(pid));
}
// Convert to the correct type of selection
vtkDataObject* data = this->ModelAdapterPtr->GetVTKDataObject();
vtkSmartPointer<vtkSelection> converted;
converted.TakeReference(vtkConvertSelection::ToSelectionType(
selection, data, this->SelectionType, this->SelectionArrayNames));
VTKIndexSelectList, data, this->SelectionType, this->SelectionArrayNames));
// Call select on the representation
this->GetRepresentation()->Select(this, converted);
......@@ -274,29 +258,14 @@ void vtkQtItemView::Update()
{
// If we initiated the selection, do nothing.
return;
}
}
vtkSelection* s = rep->GetSelectionLink()->GetSelection();
vtkSmartPointer<vtkSelection> selection;
selection.TakeReference(vtkConvertSelection::ToIndexSelection(s, d));
QItemSelection list;
vtkSelectionNode* node = selection->GetNode(0);
if (node)
{
vtkIdTypeArray* arr = vtkIdTypeArray::SafeDownCast(node->GetSelectionList());
if (arr)
{
for (vtkIdType i = 0; i < arr->GetNumberOfTuples(); i++)
{
vtkIdType id = arr->GetValue(i);
QModelIndex index =
this->ModelAdapterPtr->PedigreeToQModelIndex(
this->ModelAdapterPtr->IdToPedigree(id));
list.select(index, index);
}
}
}
this->GetSelectionModel()->select(list,
QItemSelection qisList = this->ModelAdapterPtr->
VTKIndexSelectionToQItemSelection(selection);
this->GetSelectionModel()->select(qisList,
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
// Sub-classes might use their own views, so don't assume the view has been set
......
......@@ -37,7 +37,7 @@
#include "vtkSmartPointer.h"
#include "vtkTable.h"
vtkCxxRevisionMacro(vtkQtListView, "1.4");
vtkCxxRevisionMacro(vtkQtListView, "1.5");
vtkStandardNewMacro(vtkQtListView);
......@@ -47,13 +47,14 @@ vtkQtListView::vtkQtListView()
this->ListView = new QListView();
this->ListAdapter = new vtkQtTableModelAdapter();
this->ListView->setModel(this->ListAdapter);
this->ListView->setSelectionMode(QAbstractItemView::SingleSelection);
this->ListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
this->ListView->setSelectionBehavior(QAbstractItemView::SelectRows);
this->Selecting = false;
QObject::connect(this->ListView->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
this,
SLOT(slotSelectionChanged(const QItemSelection&,const QItemSelection&)));
SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));
}
//----------------------------------------------------------------------------
......@@ -73,9 +74,9 @@ QWidget* vtkQtListView::GetWidget()
}
//----------------------------------------------------------------------------
vtkQtAbstractModelAdapter* vtkQtListView::GetItemModelAdapter()
void vtkQtListView::SetAlternatingRowColors(bool state)
{
return this->ListAdapter;
this->ListView->setAlternatingRowColors(state);
}
//----------------------------------------------------------------------------
......@@ -118,35 +119,19 @@ void vtkQtListView::RemoveInputConnection(int vtkNotUsed(port), int vtkNotUsed(i
}
//----------------------------------------------------------------------------
void vtkQtListView::slotSelectionChanged(const QItemSelection& vtkNotUsed(s1), const QItemSelection& vtkNotUsed(s2))
void vtkQtListView::slotQtSelectionChanged(const QItemSelection& vtkNotUsed(s1), const QItemSelection& vtkNotUsed(s2))
{
this->Selecting = true;
// Create index selection
vtkSmartPointer<vtkSelection> selection =
vtkSmartPointer<vtkSelection>::New();
vtkSmartPointer<vtkSelectionNode> node =
vtkSmartPointer<vtkSelectionNode>::New();
node->SetContentType(vtkSelectionNode::INDICES);
node->SetFieldType(vtkSelectionNode::VERTEX);
vtkSmartPointer<vtkIdTypeArray> idarr =
vtkSmartPointer<vtkIdTypeArray>::New();
node->SetSelectionList(idarr);
selection->AddNode(node);
const QModelIndexList list = this->ListView->selectionModel()->selectedRows();
// For index selection do this odd little dance with two maps :)
for (int i = 0; i < list.size(); i++)
{
vtkIdType pid = this->ListAdapter->QModelIndexToPedigree(list.at(i));
idarr->InsertNextValue(this->ListAdapter->PedigreeToId(pid));
}
// Convert from a QModelIndexList to an index based vtkSelection
const QModelIndexList qmil = this->ListView->selectionModel()->selectedRows();
vtkSelection *VTKIndexSelectList = this->ListAdapter->QModelIndexListToVTKIndexSelection(qmil);
// Convert to the correct type of selection
vtkDataObject* data = this->ListAdapter->GetVTKDataObject();
vtkSmartPointer<vtkSelection> converted;
converted.TakeReference(vtkConvertSelection::ToSelectionType(
selection, data, this->SelectionType, this->SelectionArrayNames));
VTKIndexSelectList, data, this->SelectionType, this->SelectionArrayNames));
// Call select on the representation
this->GetRepresentation()->Select(this, converted);
......@@ -154,6 +139,45 @@ void vtkQtListView::slotSelectionChanged(const QItemSelection& vtkNotUsed(s1), c
this->Selecting = false;
}
//----------------------------------------------------------------------------
void vtkQtListView::SetVTKSelection()
{
// Make the selection current
if (this->Selecting)
{
// If we initiated the selection, do nothing.
return;
}
// See if the selection has changed in any way
vtkDataRepresentation* rep = this->GetRepresentation();
vtkDataObject *d = this->ListAdapter->GetVTKDataObject();
vtkSelection* s = rep->GetSelectionLink()->GetSelection();
if (s->GetMTime() != this->CurrentSelectionMTime)
{
this->CurrentSelectionMTime = s->GetMTime();
vtkSmartPointer<vtkSelection> selection;
selection.TakeReference(vtkConvertSelection::ToIndexSelection(s, d));
QItemSelection qisList = this->ListAdapter->
VTKIndexSelectionToQItemSelection(selection);
// Here we want the qt model to have it's selection changed
// but we don't want to emit the selection.
QObject::disconnect(this->ListView->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
this, SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));
this->ListView->selectionModel()->select(qisList,
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
QObject::connect(this->ListView->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
this, SLOT(slotQtSelectionChanged(const QItemSelection&,const QItemSelection&)));
}
}
//----------------------------------------------------------------------------
void vtkQtListView::Update()
{
......@@ -169,36 +193,8 @@ void vtkQtListView::Update()
vtkDataObject *d = alg->GetOutputDataObject(0);
this->ListAdapter->SetVTKDataObject(d);
// Make the selection current
if (this->Selecting)
{
// If we initiated the selection, do nothing.
return;
}
vtkSelection* s = rep->GetSelectionLink()->GetSelection();
vtkSmartPointer<vtkSelection> selection;
selection.TakeReference(vtkConvertSelection::ToIndexSelection(s, d));
QItemSelection list;
vtkSelectionNode* node = selection->GetNode(0);
if (node)
{
vtkIdTypeArray* arr = vtkIdTypeArray::SafeDownCast(node->GetSelectionList());
if (arr)
{
for (vtkIdType i = 0; i < arr->GetNumberOfTuples(); i++)
{
vtkIdType id = arr->GetValue(i);
QModelIndex index =
this->ListAdapter->PedigreeToQModelIndex(
this->ListAdapter->IdToPedigree(id));
list.select(index, index);
}
}
}
this->ListView->selectionModel()->select(list,
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
// Update the VTK selection
this->SetVTKSelection();
this->ListView->update();
}
......
......@@ -31,6 +31,7 @@
#include "QVTKWin32Header.h"
#include "vtkQtView.h"
#include <QPointer>
#include "vtkQtAbstractModelAdapter.h"
......@@ -55,16 +56,14 @@ public:
virtual QWidget* GetWidget();
// Description:
// Pointer to the internal model adapter used convert the
// vtkDataObject to a QAbstractItemModel.
vtkQtAbstractModelAdapter* GetItemModelAdapter();
// Have the view alternate its row colors
void SetAlternatingRowColors(bool);
// Description:
// Updates the view.
virtual void Update();
protected:
vtkQtListView();
~vtkQtListView();
......@@ -81,17 +80,17 @@ protected:
vtkAlgorithmOutput* conn,
vtkAlgorithmOutput* selectionConn);
// Description:
// We need to keep track of whether were in selection mode
bool Selecting;
QPointer<QListView> ListView;
vtkQtTableModelAdapter* ListAdapter;
private slots:
void slotSelectionChanged(const QItemSelection&,const QItemSelection&);
void slotQtSelectionChanged(const QItemSelection&,const QItemSelection&);
private:
void SetVTKSelection();
unsigned long CurrentSelectionMTime;
QPointer<QListView> ListView;
vtkQtTableModelAdapter* ListAdapter;
bool Selecting;
vtkQtListView(const vtkQtListView&); // Not implemented.
void operator=(const vtkQtListView&); // Not implemented.
......
......@@ -23,6 +23,8 @@
#include "vtkTable.h"
#include "vtkIdList.h"
#include "vtkIdTypeArray.h"
#include "vtkSelectionNode.h"
#include "vtkSmartPointer.h"
#include "vtkStdString.h"
#include "vtkVariant.h"
......@@ -41,7 +43,6 @@ vtkQtTableModelAdapter::vtkQtTableModelAdapter(vtkTable* t, QObject* p)
if (this->Table != NULL)
{
this->Table->Register(0);
this->GenerateHashMap();
}
}
......@@ -73,36 +74,6 @@ void vtkQtTableModelAdapter::SetKeyColumnName(const char* name)
}
}
void vtkQtTableModelAdapter::GenerateHashMap()
{
vtkAbstractArray *pedigreeIds = this->Table->GetRowData()->GetPedigreeIds();
this->IdToPedigreeHash.clear();
this->PedigreeToIndexHash.clear();
this->IndexToIdHash.clear();
for (vtkIdType i = 0; i < this->Table->GetNumberOfRows(); i++)
{
QModelIndex idx = this->createIndex(i, 0, static_cast<int>(i));
vtkIdType pedigree = -1;
if (pedigreeIds != NULL)
{
vtkVariant v(0);
switch (pedigreeIds->GetDataType())
{
vtkExtraExtendedTemplateMacro(v = *static_cast<VTK_TT*>(pedigreeIds->GetVoidPointer(i)));
}
pedigree = v.ToInt();
}
else
{
pedigree = i;
}
this->IdToPedigreeHash[i] = pedigree;
this->PedigreeToIndexHash[pedigree] = idx;
this->IndexToIdHash[idx] = i;
}
}
void vtkQtTableModelAdapter::SetVTKDataObject(vtkDataObject *obj)
{
vtkTable *t = vtkTable::SafeDownCast(obj);
......@@ -114,7 +85,6 @@ void vtkQtTableModelAdapter::SetVTKDataObject(vtkDataObject *obj)
// Okay it's a table so set it :)
this->setTable(t);
}