Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft for Issue1123 - Expandable Transfer Function #3698

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions apps/vaporgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ set (SRCS
VolumeIsoEventRouter.h
ParamsMenuItems.cpp
ParamsMenuItems.h
TFEditor.cpp
TFEditor.h
TFOpacityWidget.cpp
TFOpacityWidget.h
TFColorWidget.cpp
Expand Down
67 changes: 64 additions & 3 deletions apps/vaporgui/PTFEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "PTFEditor.h"
#include <vapor/RenderParams.h>
#include <vapor/GUIStateParams.h>
#include "TFColorWidget.h"
#include "TFOpacityWidget.h"
#include "TFHistogramWidget.h"
Expand Down Expand Up @@ -28,22 +29,24 @@ template class PTFMapWidget<TFIsoValueWidget>;

PTFEditor::PTFEditor() : PTFEditor(RenderParams::_variableNameTag) {}

PTFEditor::PTFEditor(const std::string &tag, const std::set<Element> elements, const std::string &label) : PWidget(tag, _section = new VSection(label.empty() ? tag : label))
PTFEditor::PTFEditor(const std::string &tag, const std::set<Element> elements, const std::string &label, bool expandable) : PWidget(tag, _section = new VSection(label.empty() ? tag : label)), _expandable(expandable)
{
_maps = new TFMapGroupWidget;
_histogram = new TFHistogramMap(tag);
_opacityMap = new TFOpacityMap(tag);
_colorMap = new TFColorMap(tag);
_isoMap = new TFIsoValueMap(tag);
_range = new TFMappingRangeSelector(tag);
_elements = elements;
_label = label;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The label parameter should be held by the VSection rather than in the subclass. Also, it is optional which is not being handled.


_maps->Add({_opacityMap, _histogram});
_maps->Add(_isoMap);
_maps->Add(_colorMap);

_section->layout()->addWidget(_maps);
_section->layout()->addWidget(_maps, 1);
_section->layout()->addWidget(_mapsInfo = _maps->CreateInfoGroup());
_section->layout()->addWidget(_range);
_section->layout()->addWidget(_range, 0);
connect(_range, SIGNAL(ValueChangedIntermediate(float, float)), _histogram, SLOT(update()));

int start = 0;
Expand All @@ -63,6 +66,11 @@ PTFEditor::PTFEditor(const std::string &tag, const std::set<Element> elements, c
_histogram->PopulateSettingsMenu(menu);
for (int i = start; i < menu->actions().size(); i++) _histogramActions.push_back(menu->actions()[i]);

if (_expandable) {
_section->setExpandedSection();
connect(_section, &VSection::expandButtonClicked, this, &PTFEditor::showExpandedPTFEditor);
}

_section->setMenu(menu);

_histogram->hide();
Expand Down Expand Up @@ -134,4 +142,57 @@ void PTFEditor::updateGUI() const
for (auto a : _histogramActions) a->setEnabled(_histogram->IsShown());
}

void PTFEditor::Update(VAPoR::ParamsBase *params, VAPoR::ParamsMgr *paramsMgr, VAPoR::DataMgr *dataMgr) {
PWidget::Update(params, paramsMgr, dataMgr);
if (_expandable==true) {
std::string name, inst;
getExpandedPTFEditorInfo(name, inst);

if (_expandedPTFEditor!=nullptr) {
_expandedPTFEditor->setWindowTitle(QString::fromStdString(name));
_expandedPTFEditor->Update(params, paramsMgr, dataMgr);
}
}
}

void PTFEditor::getExpandedPTFEditorInfo(std::string &name, std::string& type) {
ParamsMgr* pm = getParamsMgr();
GUIStateParams* p = dynamic_cast<GUIStateParams *>(pm->GetParams(GUIStateParams::GetClassType()));
type = p->GetActiveRendererInst();
p->GetActiveRenderer(p->GetActiveVizName(), type, name);
if (dynamic_cast<PColormapTFEditor*>(this)) {
name+="_Colormap";
type+="_Colormap";
}
}

void PTFEditor::showExpandedPTFEditor() {
if (_expandedPTFEditor==nullptr) {
_expandedPTFEditor = new PTFEditor(_tag, _elements, _label, false);
connect(_expandedPTFEditor, SIGNAL(closed()), this, SLOT(closeExpandedPTFEditor()));

if (_showColormapBasedOnParam==true) _expandedPTFEditor->ShowColormapBasedOnParam(_showColormapBasedOnParamTag, _showColormapBasedOnParamValue);
if (_showOpacityBasedOnParam==true) _expandedPTFEditor->ShowOpacityBasedOnParam(_showOpacityBasedOnParamTag, _showOpacityBasedOnParamValue);

_expandedPTFEditor->setAttribute(Qt::WA_ShowWithoutActivating);
_expandedPTFEditor->setAttribute(Qt::WA_DeleteOnClose);
}
_expandedPTFEditor->raise();

// It was originally thought to store the open expanded PTFEditors in GUIStateParams.
// This lead to problems and the team agreed that it's not important to restore them if
// they were expanded in a session, so we manually call Update here.
Update(getParams(), getParamsMgr(), getDataMgr());
}

void PTFEditor::closeExpandedPTFEditor() {
_expandedPTFEditor->close();
_expandedPTFEditor=nullptr;
}

void PTFEditor::closeEvent(QCloseEvent* event) {
emit closed();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply call closeExpandedPTFEditor

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to specifically capture the expanded PTFEditor's closeEvent so the containing PTFEditor can then set the expanded to nullptr.

If we don't, then the checks for _expandedPTFEditor==nullptr will fail, particularly in PTFEditor::showExpandedPTFEditor().

close();
}

PColormapTFEditor::PColormapTFEditor() : PTFEditor(RenderParams::_colorMapVariableNameTag, {PTFEditor::Histogram, PTFEditor::Colormap}, "Colormap Transfer Function") {}
17 changes: 16 additions & 1 deletion apps/vaporgui/PTFEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class PTFEditor : public PWidget {
TFColorMap * _colorMap;
TFIsoValueMap * _isoMap;
TFMappingRangeSelector *_range;
PTFEditor* _expandedPTFEditor = nullptr;
bool _expandable;

std::vector<QAction *> _colorMapActions;
std::vector<QAction *> _opacityMapActions;
Expand All @@ -72,7 +74,7 @@ class PTFEditor : public PWidget {
enum Element { Opacity, Histogram, Colormap, IsoValues, RegularIsoArray, Default };

PTFEditor();
PTFEditor(const std::string &tag, const std::set<Element> elements = {Default}, const std::string &label = "Transfer Function");
PTFEditor(const std::string &tag, const std::set<Element> elements = {Default}, const std::string &label = "Transfer Function", bool expandable = true);
//! Behaves the same as PWidget::ShowBasedOnParam except shows/hides the opacity controls.
//! @copydoc PWidget::ShowBasedOnParam
PTFEditor *ShowOpacityBasedOnParam(const std::string &tag, int value);
Expand All @@ -81,7 +83,20 @@ class PTFEditor : public PWidget {
PTFEditor *ShowColormapBasedOnParam(const std::string &tag, int value);

protected:
std::set<Element> _elements;
std::string _label;

void updateGUI() const override;
void Update(VAPoR::ParamsBase* p, VAPoR::ParamsMgr* pm, VAPoR::DataMgr* dm) override;
void getExpandedPTFEditorInfo(std::string &name, std::string &type);

signals:
void closed();

private slots:
void showExpandedPTFEditor();
void closeExpandedPTFEditor();
void closeEvent(QCloseEvent* event) override;
};

class PColormapTFEditor : public PTFEditor {
Expand Down
3 changes: 2 additions & 1 deletion apps/vaporgui/PWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class PWidget : public UWidget {
VAPoR::ParamsBase *_params = nullptr;
VAPoR::ParamsMgr * _paramsMgr = nullptr;
VAPoR::DataMgr * _dataMgr = nullptr;
const std::string _tag;

bool _showBasedOnParam = false;
std::string _showBasedOnParamTag = "";
Expand Down Expand Up @@ -55,6 +54,8 @@ class PWidget : public UWidget {
void setToolTip(const QString &) = delete;

protected:
const std::string _tag;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should remain private.


virtual void updateGUI() const = 0;
virtual bool requireParamsMgr() const { return false; }
virtual bool requireDataMgr() const { return false; }
Expand Down
56 changes: 0 additions & 56 deletions apps/vaporgui/TFEditor.cpp

This file was deleted.

38 changes: 0 additions & 38 deletions apps/vaporgui/TFEditor.h

This file was deleted.

7 changes: 7 additions & 0 deletions apps/vaporgui/TFMapWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "TFMapWidget.h"
#include "TFColorWidget.h"
#include "TFIsoValueWidget.h"
#include <QPainter>
#include <QResizeEvent>
#include <QMenu>
Expand Down Expand Up @@ -199,6 +201,11 @@ TFMapWidget::TFMapWidget(TFMap *map)
AddMap(map);
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(_showContextMenu(const QPoint &)));

// Is there a better way or place to set the sizePolicy of this object?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do it in the subclass constructor

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subclass isn't a QWidget though. It needs to be done in the TFMapWidget, not the TFMap :\

if (dynamic_cast<TFColorMap*>(map)) setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
else if (dynamic_cast<TFIsoValueMap*>(map)) setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
else setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
}

TFMapWidget::~TFMapWidget()
Expand Down
49 changes: 49 additions & 0 deletions apps/vaporgui/VSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ void VSection::setMenu(QMenu *menu)
menuButton->setMenu(menu);
}

void VSection::setExpandedSection()
{
ExpandSectionButton *expandSectionButton = (ExpandSectionButton *)QTabWidget::cornerWidget();
if (!expandSectionButton) {
expandSectionButton = new ExpandSectionButton;
QTabWidget::setCornerWidget(expandSectionButton, Qt::TopLeftCorner);
}
connect(expandSectionButton, &QToolButton::clicked, this, [this](){ emit this->expandButtonClicked(); });
}

QWidget *VSection::_tab() const { return QTabWidget::widget(0); }

QString VSection::_createStylesheet() const
Expand All @@ -39,6 +49,13 @@ QString VSection::_createStylesheet() const
right: 3px;
}
)";
stylesheet +=
R"(
QTabWidget::left-corner {
top: 24px;
left: 3px;
}
)";
#else
stylesheet +=
R"(
Expand All @@ -47,6 +64,13 @@ QString VSection::_createStylesheet() const
right: 5px;
}
)";
stylesheet +=
R"(
QTabWidget::left-corner {
top: -3px;
right: 5px;
}
)";
#endif

return QString::fromStdString(stylesheet);
Expand Down Expand Up @@ -75,3 +99,28 @@ void VSection::SettingsMenuButton::paintEvent(QPaintEvent *event)
option.features = QStyleOptionToolButton::None;
p.drawComplexControl(QStyle::CC_ToolButton, option);
}

VSection::ExpandSectionButton::ExpandSectionButton()
{
setIcon(QIcon(QString::fromStdString(Wasp::GetSharePath("images/expandSection.png"))));
setIconSize(QSize(18, 18));
setCursor(QCursor(Qt::PointingHandCursor));
setPopupMode(QToolButton::InstantPopup);

setStyleSheet("border: none;"
"background-color: none;"
"padding: 0px;");
}

void VSection::ExpandSectionButton::paintEvent(QPaintEvent *event)
{
// This function is overridden to prevent Qt from drawing its own dropdown arrow
QStylePainter p(this);

QStyleOptionToolButton option;
initStyleOption(&option);
option.subControls = QStyle::SC_ToolButton;
option.features = QStyleOptionToolButton::None;
p.drawComplexControl(QStyle::CC_ToolButton, option);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExpandSectionButton duplicates the code of SettingsMenuButton apart from changing the icon path.

15 changes: 15 additions & 0 deletions apps/vaporgui/VSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class VSection : public QTabWidget {
Q_OBJECT

class SettingsMenuButton;
class ExpandSectionButton;

public:
VSection(const std::string &title);
QVBoxLayout *layout() const;
void setMenu(QMenu *menu);
void setExpandedSection();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method is called set... but nothing is being set.


void setLayout(QLayout *layout) = delete;
int addTab(QWidget *page, const QString &label) = delete;
Expand All @@ -34,6 +36,9 @@ class VSection : public QTabWidget {
private:
QWidget *_tab() const;
QString _createStylesheet() const;

signals:
void expandButtonClicked();
};

#include "AbstractWidgetGroup.h"
Expand Down Expand Up @@ -61,3 +66,13 @@ class VSection::SettingsMenuButton : public QToolButton {
protected:
void paintEvent(QPaintEvent *event);
};

class VSection::ExpandSectionButton: public QToolButton {
Q_OBJECT

public:
ExpandSectionButton();

protected:
void paintEvent(QPaintEvent *event);
};
Loading