Commit 31010e74 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Support multi-component arrays in spreadsheet

Spreadsheet view poorly supported mutli-component arrays. This commit
adds support to Spreadsheet view to show mutli-component arrays under a
single header-section which spans all the components. This enables us to
resize the component-section individually, and yet easily realize that
the sections correspond to the same array.

For this we add a new pqMultiColumnHeaderView that combines adjacent
sections with the same `DisplayRole` text.

vtkSpreadSheetRepresentation now splits multi-component arrays so each
component shows up separately. We also add magnitude array
(fixes #18431).

This cleanup header section resize to fix #18430.

Fixes #16126.
parent 851d36d4
......@@ -25,7 +25,8 @@ r = Show()
ExportView(filename)
header = get_header(filename)
assert ("Normals:0" in header and \
print(header)
assert ("Normals_0" in header and \
"Block Number" in header and \
"Elevation" in header and \
"Point ID" in header and \
......@@ -36,7 +37,7 @@ Render()
ExportView(filename)
header = get_header(filename)
assert ("Normals:0" not in header and \
assert ("Normals_0" not in header and \
"Block Number" in header and \
"Elevation" in header and \
"Point ID" in header and \
......
......@@ -13,10 +13,10 @@
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Splitter.2/Frame.6/CentralWidgetFrame/Viewport/pqSpreadSheetViewDecorator/Attribute" command="set_string" arguments="Cell Data" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Splitter.2/Frame.6/CentralWidgetFrame/Viewport/pqSpreadSheetViewDecorator/Attribute" command="set_string" arguments="Point Data" />
<!-- begin sort by RTData -->
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Splitter.2/Frame.6/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0/1QHeaderView1" command="mousePress" arguments="1,1,0,0,0,0" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Splitter.2/Frame.6/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0/1QHeaderView1" command="mouseRelease" arguments="1,0,0,0,0,0" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Splitter.2/Frame.6/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0/1QHeaderView1" command="mousePress" arguments="1,1,0,0,0,0" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Splitter.2/Frame.6/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0/1QHeaderView1" command="mouseRelease" arguments="1,0,0,0,0,0" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Splitter.2/Frame.6/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0/Header" command="mousePress" arguments="1,1,0,0,0,0" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Splitter.2/Frame.6/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0/Header" command="mouseRelease" arguments="1,0,0,0,0,0" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Splitter.2/Frame.6/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0/Header" command="mousePress" arguments="1,1,0,0,0,0" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Splitter.2/Frame.6/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0/Header" command="mouseRelease" arguments="1,0,0,0,0,0" />
<!-- end sort by RTData -->
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Splitter.2/Frame.6/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" command="mousePress" arguments="1,1,0,51,14,/0:0" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Splitter.0/Splitter.2/Frame.6/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" command="mouseRelease" arguments="1,0,0,51,14,/0:0" />
......
......@@ -64,9 +64,9 @@
<pqevent object="pqClientMainWindow/pipelineBrowserDock/pipelineBrowser" command="mouseRelease" arguments="1,0,0,63,8,/0:0/0:0" />
<pqevent object="pqClientMainWindow/menubar" command="activate" arguments="menuFilters" />
<pqevent object="pqClientMainWindow/menubar/menuFilters/Recent" command="activate" arguments="TableToPolyData" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/XColumn/ComboBox" command="set_string" arguments="Points:0" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/YColumn/ComboBox" command="set_string" arguments="Points:1" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/ZColumn/ComboBox" command="set_string" arguments="Points:2" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/XColumn/ComboBox" command="set_string" arguments="Points_0" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/YColumn/ComboBox" command="set_string" arguments="Points_1" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/ZColumn/ComboBox" command="set_string" arguments="Points_2" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/Accept" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/menubar/menuFilters/pqProxyGroupMenuManager0/Glyph" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/Accept" command="activate" arguments="" />
......
# Improvements to viewing multi-component arrays in the Spreadsheet View
* Spreadsheet view can now show mutli-component arrays as multi-columns with a
joined header. Individual component columns are still user-resizable, just
like any other column.
......@@ -28,9 +28,15 @@ vtkSpreadSheetRepresentation::vtkSpreadSheetRepresentation()
{
this->SetNumberOfInputPorts(3);
this->DataConditioner->SetGenerateOriginalIds(1);
this->DataConditioner->SetFlattenTable(true);
this->DataConditioner->SetSplitComponentsNamingMode(
vtkSplitColumnComponents::NUMBERS_WITH_UNDERSCORES);
this->CleanArrays->SetInputConnection(this->DataConditioner->GetOutputPort());
this->ExtractedDataConditioner->SetGenerateOriginalIds(0);
this->ExtractedDataConditioner->SetFlattenTable(true);
this->ExtractedDataConditioner->SetSplitComponentsNamingMode(
vtkSplitColumnComponents::NUMBERS_WITH_UNDERSCORES);
this->ExtractedCleanArrays->SetInputConnection(this->ExtractedDataConditioner->GetOutputPort());
}
......
......@@ -27,6 +27,8 @@
#include "vtkPVClientServerCoreRenderingModule.h" //needed for exports
#include "vtkPVView.h"
#include <string> // for std::string
class vtkCSVExporter;
class vtkClientServerMoveData;
class vtkMarkSelectedRows;
......@@ -99,7 +101,7 @@ public:
void ClearHiddenColumnsByName();
void HideColumnByLabel(const char* columnLabel);
bool IsColumnHiddenByLabel(const char* columnLabel);
bool IsColumnHiddenByLabel(const std::string& columnLabel);
void ClearHiddenColumnsByLabel();
//@}
......@@ -139,8 +141,8 @@ public:
*
* \note CallOnClient
*/
const char* GetColumnLabel(vtkIdType index);
const char* GetColumnLabel(const char* columnName);
std::string GetColumnLabel(vtkIdType index);
std::string GetColumnLabel(const char* columnName);
//@}
/**
......@@ -217,7 +219,7 @@ protected:
void OnRepresentationUpdated();
vtkTable* FetchBlock(vtkIdType blockindex, bool skipCache = false);
vtkTable* FetchBlock(vtkIdType blockindex);
bool ShowExtractedSelection;
bool GenerateCellConnectivity;
......
......@@ -15,7 +15,6 @@
#include "vtkBlockDeliveryPreprocessor.h"
#include "vtkAttributeDataToTableFilter.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkExtractBlock.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
......@@ -25,7 +24,6 @@
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkSmartPointer.h"
#include "vtkSplitColumnComponents.h"
#include "vtkTable.h"
#include "vtkUniformGridAMRDataIterator.h"
......@@ -38,18 +36,20 @@ class vtkBlockDeliveryPreprocessor::CompositeDataSetIndicesType : public std::se
vtkStandardNewMacro(vtkBlockDeliveryPreprocessor);
//----------------------------------------------------------------------------
vtkBlockDeliveryPreprocessor::vtkBlockDeliveryPreprocessor()
: FieldAssociation(vtkDataObject::FIELD_ASSOCIATION_POINTS)
, FlattenTable(0)
, GenerateOriginalIds(true)
, GenerateCellConnectivity(false)
, SplitComponentsNamingMode(vtkSplitColumnComponents::NAMES_WITH_UNDERSCORES)
, CompositeDataSetIndices(new vtkBlockDeliveryPreprocessor::CompositeDataSetIndicesType())
{
this->FieldAssociation = vtkDataObject::FIELD_ASSOCIATION_POINTS;
this->FlattenTable = 0;
this->GenerateOriginalIds = true;
this->GenerateCellConnectivity = false;
this->CompositeDataSetIndices = new CompositeDataSetIndicesType();
}
//----------------------------------------------------------------------------
vtkBlockDeliveryPreprocessor::~vtkBlockDeliveryPreprocessor()
{
delete this->CompositeDataSetIndices;
this->CompositeDataSetIndices = nullptr;
}
//----------------------------------------------------------------------------
......@@ -129,8 +129,7 @@ int vtkBlockDeliveryPreprocessor::RequestData(
return 1;
}
vtkSmartPointer<vtkAttributeDataToTableFilter> adtf =
vtkSmartPointer<vtkAttributeDataToTableFilter>::New();
vtkNew<vtkAttributeDataToTableFilter> adtf;
adtf->SetInputData(inputDO);
adtf->SetAddMetaData(true);
adtf->SetGenerateCellConnectivity(this->GenerateCellConnectivity);
......@@ -140,19 +139,16 @@ int vtkBlockDeliveryPreprocessor::RequestData(
// Create a pointer of the base class type, so that later stages need not be
// concerned with whether the data was flattened or not.
vtkAlgorithm* filter = adtf;
vtkSmartPointer<vtkAlgorithm> filter;
filter = adtf;
vtkSmartPointer<vtkSplitColumnComponents> split;
if (this->FlattenTable)
{
split = vtkSmartPointer<vtkSplitColumnComponents>::New();
vtkCompositeDataPipeline* pipeline = vtkCompositeDataPipeline::New();
split->SetExecutive(pipeline);
pipeline->Delete();
filter = split;
vtkNew<vtkSplitColumnComponents> split;
split->SetInputConnection(adtf->GetOutputPort());
split->SetNamingModeToNamesWithUnderscores();
split->SetNamingMode(this->SplitComponentsNamingMode);
split->Update();
filter = split;
}
vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast(outputDO);
......@@ -202,12 +198,6 @@ int vtkBlockDeliveryPreprocessor::RequestData(
return 1;
}
//----------------------------------------------------------------------------
vtkExecutive* vtkBlockDeliveryPreprocessor::CreateDefaultExecutive()
{
return vtkCompositeDataPipeline::New();
}
//----------------------------------------------------------------------------
void vtkBlockDeliveryPreprocessor::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -27,6 +27,7 @@
#include "vtkDataObjectAlgorithm.h"
#include "vtkPVVTKExtensionsRenderingModule.h" // needed for export macro
#include "vtkSplitColumnComponents.h" // needed for enum
class VTKPVVTKEXTENSIONSRENDERING_EXPORT vtkBlockDeliveryPreprocessor
: public vtkDataObjectAlgorithm
......@@ -78,6 +79,17 @@ public:
vtkGetMacro(FlattenTable, int);
//@}
//@{
/**
* Corresponds to `vtkSplitColumnComponents::NamingMode`. Pick which mode to
* use to name arrays when `FlattenTable` is true. Default is
* `vtkSplitColumnComponents::NAMES_WITH_UNDERSCORES`.
*/
vtkSetClampMacro(SplitComponentsNamingMode, int, vtkSplitColumnComponents::NUMBERS_WITH_PARENS,
vtkSplitColumnComponents::NAMES_WITH_UNDERSCORES);
vtkGetMacro(SplitComponentsNamingMode, int);
//@}
//@{
/**
* When set (default) the vtkOriginalIndices array will be added to the
......@@ -92,8 +104,6 @@ protected:
vtkBlockDeliveryPreprocessor();
~vtkBlockDeliveryPreprocessor() override;
vtkExecutive* CreateDefaultExecutive() VTK_OVERRIDE;
/**
* This is called by the superclass.
* This is the method you should override.
......@@ -107,6 +117,7 @@ protected:
int FlattenTable;
bool GenerateOriginalIds;
bool GenerateCellConnectivity;
int SplitComponentsNamingMode;
private:
vtkBlockDeliveryPreprocessor(const vtkBlockDeliveryPreprocessor&) = delete;
......
......@@ -26,5 +26,8 @@
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/Close" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/EmptyView/scrollArea/qt_scrollarea_viewport/widgetFoo/ConvertActionsFrame/SpreadSheetView" command="activate" arguments="" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="0.1,13" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="0.2,1920, 0, 0" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="0.2,1920" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="0.3,0" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="0.4,0" />
</pqevents>
......@@ -29,7 +29,12 @@
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/EmptyView/scrollArea/qt_scrollarea_viewport/widgetFoo/ConvertActionsFrame/SpreadSheetView" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" command="setCurrent" arguments="0.1" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="0.1,17" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="0.2,1920, 0, 0" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="1.2,1920, 0, 0" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="0.2,1920" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="0.3,0" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="0.4,0" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="1.1,17" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="1.2,1920" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="1.3,0" />
<pqcheck object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport/1pqSpreadSheetViewWidget0" property="modelItemData" arguments="1.4,0" />
</pqevents>
......@@ -147,8 +147,10 @@ static void populateMenu(pqSpreadSheetView* view, QMenu* menu)
model->headerData(col, Qt::Horizontal, Qt::DisplayRole).toString().toLatin1().data();
bool checked =
model->headerData(col, Qt::Horizontal, pqSpreadSheetViewModel::SectionVisible).toBool();
columnLabels.push_back(std::make_pair(label, checked));
columnLabelsSet.insert(label);
if (columnLabelsSet.insert(label).second == true)
{
columnLabels.push_back(std::make_pair(label, checked));
}
}
}
columnLabels.push_back(std::make_pair(std::string(), false));
......@@ -160,10 +162,9 @@ static void populateMenu(pqSpreadSheetView* view, QMenu* menu)
for (unsigned int cc = 0, max = svp->GetNumberOfElements(); cc < max; ++cc)
{
auto txt = svp->GetElement(cc);
if (columnLabelsSet.find(txt) == columnLabelsSet.end())
if (columnLabelsSet.insert(txt).second == true)
{
columnLabels.push_back(std::make_pair(txt, false));
columnLabelsSet.insert(txt);
}
}
......
......@@ -72,12 +72,6 @@ public:
this->Table->setCornerButtonEnabled(false);
this->Table->setSelectionBehavior(QAbstractItemView::SelectRows);
this->Table->setSelectionModel(&this->SelectionModel);
#if QT_VERSION >= 0x050000
this->Table->horizontalHeader()->setSectionsMovable(true);
#else
this->Table->horizontalHeader()->setMovable(true);
#endif
this->SingleColumnMode = false;
// Do not show the sorting arrow as default
this->Table->setSortingEnabled(false);
......@@ -93,8 +87,6 @@ public:
// We use EmptySelectionModel as the selection model for the view when in
// SelectionOnly mode i.e. when we showing only the selected elements.
QItemSelectionModel EmptySelectionModel;
bool SingleColumnMode;
};
//-----------------------------------------------------------------------------
......
......@@ -456,7 +456,7 @@ QVariant pqSpreadSheetViewModel::headerData(
switch (role)
{
case Qt::DisplayRole:
return view->GetColumnLabel(section);
return QString(view->GetColumnLabel(section).c_str());
case SectionInternal:
return view->IsColumnInternal(section);
case SectionVisible:
......
......@@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqNonEditableStyledItemDelegate.h"
#include "pqSpreadSheetViewModel.h"
#include "pqMultiColumnHeaderView.h"
#include <QApplication>
#include <QHeaderView>
#include <QItemDelegate>
......@@ -81,29 +83,30 @@ public:
//-----------------------------------------------------------------------------
pqSpreadSheetViewWidget::pqSpreadSheetViewWidget(QWidget* parentObject)
: Superclass(parentObject)
, SingleColumnMode(false)
, OldColumnCount(0)
{
// setup some defaults.
this->setAlternatingRowColors(true);
this->setCornerButtonEnabled(false);
this->setSelectionBehavior(QAbstractItemView::SelectRows);
#if QT_VERSION >= 0x050000
this->horizontalHeader()->setSectionsMovable(true);
#else
this->horizontalHeader()->setMovable(true);
#endif
this->horizontalHeader()->setHighlightSections(false);
this->SingleColumnMode = false;
auto hheader = new pqMultiColumnHeaderView(Qt::Horizontal, this);
hheader->setObjectName("Header");
hheader->setSectionsClickable(true);
hheader->setSectionsMovable(false);
hheader->setHighlightSections(false);
// limit to using 100 columns when resizing. This addresses performance issues with
// large data. Note visible columns only (0) is not adequate since the widget may
// not be visible at all when being resized and we e
hheader->setResizeContentsPrecision(100);
this->setHorizontalHeader(hheader);
// setup the delegate.
this->setItemDelegate(new pqNonEditableStyledItemDelegate(this));
QObject::connect(this->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), this,
SLOT(onSortIndicatorChanged(int, Qt::SortOrder)));
// limit to using 10 columns when resizing. This addresses performance issues with
// large data. Note visible columns only (0) is not adequate since the widget may
// not be visible at all when being resized and we e
this->horizontalHeader()->setResizeContentsPrecision(10);
}
//-----------------------------------------------------------------------------
......@@ -133,13 +136,21 @@ void pqSpreadSheetViewWidget::onHeaderDataChanged()
{
if (auto amodel = this->model())
{
for (int cc = 0, max = amodel->columnCount(); cc < max; cc++)
const int colcount = amodel->columnCount();
for (int cc = 0; cc < colcount; cc++)
{
bool visible =
amodel->headerData(cc, Qt::Horizontal, pqSpreadSheetViewModel::SectionVisible).toBool();
this->setColumnHidden(cc, !visible);
}
this->resizeColumnsToContents();
if (this->OldColumnCount != colcount)
{
// don't resize column unless the column count really changed.
// this overcomes #18430.
this->resizeColumnsToContents();
this->OldColumnCount = colcount;
}
}
}
......
......@@ -86,12 +86,13 @@ protected:
*/
void paintEvent(QPaintEvent* event) override;
bool SingleColumnMode;
private:
Q_DISABLE_COPY(pqSpreadSheetViewWidget)
class pqDelegate;
bool SingleColumnMode;
int OldColumnCount;
};
#endif
......@@ -100,6 +100,8 @@ set(Module_SRCS
pqListWidgetCheckHelper.h
pqListWidgetItemObject.cxx
pqListWidgetItemObject.h
pqMultiColumnHeaderView.cxx
pqMultiColumnHeaderView.h
pqProgressWidget.cxx
pqProgressWidget.h
pqQuickLaunchDialog.cxx
......@@ -179,6 +181,7 @@ set (QtWidgets_SRCS
pqLineEdit.h
pqListWidgetCheckHelper.h
pqListWidgetItemObject.h
pqMultiColumnHeaderView.h
pqProgressWidget.h
pqQuickLaunchDialog.h
pqScaleByButton.h
......
/*=========================================================================
Program: ParaView
Module: pqMultiColumnHeaderView.cxx
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#include "pqMultiColumnHeaderView.h"
#include <QAbstractItemModel>
#include <QHeaderView>
#include <QtDebug>
//-----------------------------------------------------------------------------
pqMultiColumnHeaderView::pqMultiColumnHeaderView(Qt::Orientation orientation, QWidget* parentObject)
: Superclass(orientation, parentObject)
{
// when a section is resized, for section spanning multiple sections, we
// need to ensure that we repaint all sections in the span otherwise the text
// doesn't render correctly on adjacent section not being resized.
QObject::connect(this, &QHeaderView::sectionResized, [this](int logicalIndex, int, int) {
const auto span = this->sectionSpan(this->visualIndex(logicalIndex));
if (span.first != span.second)
{
const auto lspan =
QPair<int, int>(this->logicalIndex(span.first), this->logicalIndex(span.second));
int start = this->sectionViewportPosition(lspan.first);
int end = this->sectionViewportPosition(lspan.second) + this->sectionSize(lspan.second);
auto viewport = this->viewport();
if (this->orientation() == Qt::Horizontal && viewport != nullptr)
{
viewport->update(start, 0, end, viewport->height());
}
else
{
viewport->update(0, start, viewport->width(), end);
}
}
});
}
//-----------------------------------------------------------------------------
pqMultiColumnHeaderView::~pqMultiColumnHeaderView()
{
}
//-----------------------------------------------------------------------------
QString pqMultiColumnHeaderView::sectionDisplayText(int logicalIndex) const
{
auto amodel = this->model();
if (amodel)
{
return amodel->headerData(logicalIndex, this->orientation(), Qt::DisplayRole).toString();
}
return QString();
}
//-----------------------------------------------------------------------------
QPair<int, int> pqMultiColumnHeaderView::sectionSpan(int visual) const
{
QPair<int, int> vrange(visual, visual);
const int logical = this->logicalIndex(visual);
const auto vlabel = this->sectionDisplayText(logical);
if (vlabel.isEmpty())
{
return vrange;
}
for (int cc = vrange.first - 1; cc >= 0; --cc)
{
const int clogical = this->logicalIndex(cc);
if (this->sectionDisplayText(clogical) == vlabel)
{
vrange.first = cc;
}
else
{
break;
}
}
for (int cc = vrange.second + 1, max = this->count(); cc < max; ++cc)
{
const int clogical = this->logicalIndex(cc);
if (this->sectionDisplayText(clogical) == vlabel)
{
vrange.second = cc;
}
else
{
break;
}
}
return vrange;
}
//-----------------------------------------------------------------------------
void pqMultiColumnHeaderView::paintSection(
QPainter* painter, const QRect& rect, int logicalIndex) const
{
if (!rect.isValid())
{
return;
}
const int visual = this->visualIndex(logicalIndex);
const auto span = this->sectionSpan(visual);
if (span.first == span.second)
{
this->Superclass::paintSection(painter, rect, logicalIndex);
}
else
{
if (this->isSortIndicatorShown())
{
// if sort indicator is shown and the indicator is being shown on one of
// the sections we have grouped together, we have to handle it specially.
// In such a case, we still want to paint the sort indicator for the
// entire section (we're ignoring that it still won't be obvious which
// component is being sorted by, but that's not a huge UX issue). Do do
// that, we just paint the section with the sort indicator instead of the
// one being requested.
const int vSortIndicatorShown = this->visualIndex(this->sortIndicatorSection());
if (span.first <= vSortIndicatorShown && span.second >= vSortIndicatorShown)
{
logicalIndex = this->sortIndicatorSection();
}
}
QRect newrect(rect);
for (int cc = span.first; cc < visual; ++cc)
{
const int cc_size = this->sectionSize(this->logicalIndex(cc));
newrect.adjust(-cc_size, 0, 0, 0);
}
for (int cc = visual + 1; cc <= span.second; ++cc)
{
const int cc_size = this->sectionSize(this->logicalIndex(cc));
newrect.adjust(0, 0, cc_size, 0);
}
this->Superclass::paintSection(painter, newrect, logicalIndex);
}
}
/*=========================================================================
Program: ParaView
Module: pqMultiColumnHeaderView.h
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#ifndef pqMultiColumnHeaderView_h
#define pqMultiColumnHeaderView_h
#include "pqWidgetsModule.h" // for exports
#include <QHeaderView>
/**
* @class pqMultiColumnHeaderView
* @brief QHeaderView that supports showing multiple sections as one.
*
* pqMultiColumnHeaderView extents QHeaderView to support showing multiple
* adjacent sections as a single section. This is useful for showing vector
* quantities, for example. Instead of each component taking up header space
* and making it confusing to understand that the various sections are part of
* the same vector, pqMultiColumnHeaderView can show all those sections under a
* single banner. It still supports resizing individual sections thus does not
* inhibit usability.
*
* pqMultiColumnHeaderView simply combines adjacent sections with same
* (non-empty) `QString` value for Qt::`DisplayRole`. This is done by
* overriding `QHeaderView::paintSection` and custom painting such
* sections spanning multiple sections.
*/
class PQWIDGETS_EXPORT pqMultiColumnHeaderView : public QHeaderView
{
Q_OBJECT;
typedef QHeaderView Superclass;
public:
pqMultiColumnHeaderView(Qt::Orientation orientation, QWidget* parent = nullptr);
~pqMultiColumnHeaderView() override;
protected:
void paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const override;
private:
QPair<int, int> sectionSpan(int visualIndex) const;
QString sectionDisplayText(int logicalIndex) const;
private:
Q_DISABLE_COPY(pqMultiColumnHeaderView);
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment