Skip to content
Snippets Groups Projects
Commit f6480607 authored by MelanieCarriere's avatar MelanieCarriere
Browse files

Merge branch 'FixSpreadsheetView' into 'master'

Fix spreadsheet view

See merge request !140
parents 30b0d327 5eaf5a0b
No related branches found
No related tags found
1 merge request!140Fix spreadsheet view
Pipeline #199294 canceled
Pipeline: LidarView

#199295

    ......@@ -17,13 +17,23 @@
    #include <pqObjectBuilder.h>
    #include <pqApplicationCore.h>
    #include <pqActiveObjects.h>
    #include <pqSettings.h>
    #include <vtkEventQtSlotConnect.h>
    #include "vtkSMProperty.h"
    #include <vtkSMPropertyHelper.h>
    #include <vtkSMViewProxy.h>
    #include <assert.h>
    //-----------------------------------------------------------------------------
    lqSpreadSheetManager::lqSpreadSheetManager(QObject* parent) : QObject(parent)
    {
    this->Settings = pqApplicationCore::instance()->settings();
    // we disable the "show only selection" because otherwise if you quit LidarView with this option ON
    // when you will open Lidarview again the Spreadsheet will be empty because no points are selected.
    // This can be misleading for the user so we set this property to false on opening of lidarview
    this->Settings->setValue("ShowOnlySelectedElement", false);
    }
    //-----------------------------------------------------------------------------
    ......@@ -66,6 +76,12 @@ void lqSpreadSheetManager::constructSpreadSheet()
    QObject::connect(this->SpreadSheetView, SIGNAL(endRender()), this, SLOT(onSpreadSheetEndRender()));
    QObject::connect(this, SIGNAL(saveColumnSelection()), this, SLOT(onSaveColumnSelection()));
    // Connect the "Selection only" property to a slot to save this property information
    vtkEventQtSlotConnect* connector = vtkEventQtSlotConnect::New();
    vtkSMViewProxy* viewModule = this->SpreadSheetView->getViewProxy();
    connector->Connect(viewModule->GetProperty("SelectionOnly"), vtkCommand::ModifiedEvent,
    this, SLOT(onSpreadSheetSelectionOnly()));
    this->SpreadSheetViewDec = new pqSpreadSheetViewDecorator(this->SpreadSheetView);
    this->SpreadSheetViewDec->setPrecision(3);
    this->SpreadSheetViewDec->setFixedRepresentation(true);
    ......@@ -164,19 +180,18 @@ void lqSpreadSheetManager::conditionnallyHideColumn(const std::string& condition
    //-----------------------------------------------------------------------------
    void lqSpreadSheetManager::onSpreadSheetEndRender()
    {
    // endRender may not be the best signal to use because it will be called at
    // each frame whereas we would prefer to update only when the source is
    // changed. However I tried pqSpreadSheetView::showing and
    // pqSpreadSheetView::viewportUpdated but none worked because column names
    // are not yet updated
    if (this->getCurrentShownObjectName() != this->lastShownObjectName)
    {
    conditionnallyHideColumn("Data", "Points_m_XYZ"); // hide dupe of pt coords
    conditionnallyHideColumn("TrailingFrame", "Points_m_XYZ");
    // Every time the spreadsheet has to be rendered:
    // - we hide the column "Points_m_XYZ" because it's too wide.
    // - we check which columns have to be displayed (some of them could have been hidden by the user
    // We do this every time (not only for each new frame)
    // Because if the user opens and closes the spreadsheet on the same frame, it should display the same things.
    this->restoreColumnSelection();
    }
    this->lastShownObjectName = this->getCurrentShownObjectName();
    conditionnallyHideColumn("Data", "Points_m_XYZ"); // hide dupe of pt coords
    conditionnallyHideColumn("TrailingFrame", "Points_m_XYZ");
    this->restoreShowOnlySelectedElement();
    this->restoreColumnSelection();
    }
    //-----------------------------------------------------------------------------
    ......@@ -215,8 +230,6 @@ void lqSpreadSheetManager::onSaveColumnSelection()
    return;
    }
    pqSettings* settings = pqApplicationCore::instance()->settings();
    const int cols = this->SpreadSheetView->getViewModel()->columnCount();
    QStringList hiddenArrays;
    for (int i = 0; i < cols; i++)
    ......@@ -229,22 +242,37 @@ void lqSpreadSheetManager::onSaveColumnSelection()
    }
    std::string key = getHiddenArraysKey(this->getCurrentShownObjectName());
    settings->setValue(key.c_str(), hiddenArrays);
    this->Settings->setValue(key.c_str(), hiddenArrays);
    }
    //-----------------------------------------------------------------------------
    void lqSpreadSheetManager::restoreColumnSelection()
    {
    pqSettings* settings = pqApplicationCore::instance()->settings();
    std::string objectName = this->getCurrentShownObjectName();
    std::string key = getHiddenArraysKey(objectName);
    QStringList hiddenArrays = settings->value(key.c_str()).toStringList();
    QStringList hiddenArrays = this->Settings->value(key.c_str()).toStringList();
    foreach (QString array, hiddenArrays)
    {
    this->conditionnallyHideColumn(objectName, array.toStdString());
    }
    }
    //-----------------------------------------------------------------------------
    void lqSpreadSheetManager::onSpreadSheetSelectionOnly()
    {
    // Save if "Show only selected elements" is enabled
    int showOnlySelectedElement = vtkSMPropertyHelper(this->SpreadSheetView->getProxy(), "SelectionOnly").GetAsInt();
    this->Settings->setValue("ShowOnlySelectedElement", showOnlySelectedElement);
    }
    //-----------------------------------------------------------------------------
    void lqSpreadSheetManager::restoreShowOnlySelectedElement()
    {
    int showOnlySelectedElement = this->Settings->value("ShowOnlySelectedElement").toInt();
    vtkSMPropertyHelper(this->SpreadSheetView->getProxy(), "SelectionOnly").Set(showOnlySelectedElement);
    this->SpreadSheetView->getProxy()->UpdateProperty("SelectionOnly", true);
    }
    //-----------------------------------------------------------------------------
    std::string lqSpreadSheetManager::getCurrentShownObjectName()
    {
    ......
    ......@@ -16,6 +16,7 @@
    #define __lqSpreadSheetManager_h
    #include <pqRenderView.h>
    #include <pqSettings.h>
    #include <pqSpreadSheetView.h>
    #include <pqSpreadSheetViewModel.h>
    #include <pqSpreadSheetViewDecorator.h>
    ......@@ -48,6 +49,7 @@ protected slots:
    // only the list of hidden columns is saved
    void onSaveColumnSelection();
    void onSpreadSheetSelectionOnly();
    private:
    QDockWidget* spreadSheetDock = nullptr;
    pqRenderView* mainView = nullptr;
    ......@@ -55,14 +57,16 @@ private:
    pqSpreadSheetView* SpreadSheetView = nullptr;
    pqSpreadSheetViewDecorator* SpreadSheetViewDec = nullptr;
    pqSettings* Settings;
    void constructSpreadSheet();
    void destructSpreadSheet();
    bool isSpreadSheetOpen();
    void conditionnallyHideColumn(const std::string& conditionSrcName,
    const std::string& columnName);
    void restoreColumnSelection();
    void restoreShowOnlySelectedElement();
    std::string getCurrentShownObjectName();
    std::string lastShownObjectName = "";
    };
    #endif // __lqSpreadSheetManager_h
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment