ViewPluginSamplerAction

Qualified name: mv::gui::ViewPluginSamplerAction

class ViewPluginSamplerAction : public mv::gui::HorizontalGroupAction

View plugin sampler action class.

Provides sampling support in view plugins

Sampling is based on either:

When the current sample context changes, the current ViewPluginSamplerAction::_viewGeneratorType determines whether the HTML or widget view generator function is called to update the view:

  • ViewPluginSamplerAction::_htmlViewGeneratorFunction, see ViewPluginSamplerAction::setHtmlViewGeneratorFunction(…)

  • ViewPluginSamplerAction::_widgetViewGeneratorFunction, see ViewPluginSamplerAction::setWidgetViewGeneratorFunction(…) The generated view is then either:

  • Not shown at all (ViewingMode::None)

  • Shown in a tooltip (ViewingMode::Tooltip)

  • Shown in a window (ViewingMode::Windowed)

Note: ViewPluginSamplerAction::initialize(…) needs to be called for this action to work properly. In addition to a pointer to a view plugin, it requires two pointers to pixel selection actions:

  • Normal pixel selection action

  • Sampling pixel selection action (enabled when selection is idle)

The scatter plot plugin is a good example of how this view plugin sampler can be integrated into a view plugin class.

Special considerations:

  • ViewPluginSamplerAction::setWidgetViewGeneratorFunction(…) does not work reliably together with QWebEngineView and QLabel for HTML-based view, use QTextBrowser instead

  • This action is developed for internal use only

Author

Thomas Kroes

Public Types

enum class SamplingMode

Sampling modes.

Values:

enumerator Selection
enumerator FocusRegion

Sampling is based on the current selection.

enum class ViewingMode

Viewing modes.

Values:

enumerator None
enumerator Windowed

Do not show samples.

enumerator Tooltip

Force sample scope view plugin based view.

Force tooltip view (regardless of the size of the tooltip)

enum class ViewGeneratorType

Type of view generator.

Values:

enumerator HTML
enumerator Widget

HTML formatted string.

Widget

using SampleContext = QVariantMap

Context with which the tooltip is created.

using HtmlViewGeneratorFunction = std::function<QString(const SampleContext&)>

View generator function which is called periodically when the mouse moves in the view (should return an HTML formatted string)

using WidgetViewGeneratorFunction = std::function<QWidget*(const SampleContext&)>

Widget view generator function ()

Public Functions

Q_INVOKABLE ViewPluginSamplerAction(QObject *parent, const QString &title, const ViewingMode &viewingMode = ViewingMode::None)

Construct with pointer to parent object and title.

Parameters:
  • parent – Pointer to parent object

  • title – Title of the action

  • viewingMode – Viewing mode

void initialize(plugin::ViewPlugin *viewPlugin, PixelSelectionAction *pixelSelectionAction, PixelSelectionAction *samplerPixelSelectionAction)

Initializes the action and enables tooltip display.

Parameters:
  • viewPlugin – Pointer to view plugin (may not be nullptr)

  • pixelSelectionAction – Pointer to pixel selection action to use (may not be nullptr)

  • samplerPixelSelectionAction – Pointer to sampler pixel selection action to use (may not be nullptr)

ViewingMode getViewingMode() const

Get viewing mode.

Returns:

Viewing mode

void setViewingMode(const ViewingMode &viewingMode)

Set viewing mode to viewingMode.

Parameters:

viewingMode – Viewing mode

SamplingMode getSamplingMode() const

Get sampling mode.

Returns:

Sampling mode

void setSamplingMode(const SamplingMode &samplingMode)

Set sampling mode to samplingMode.

Parameters:

samplingMode – Viewing mode

bool canView() const

Whether this sampler can be viewed, three criteria must be met:

  • ViewPluginSamplerAction._enabledAction must be checked

  • ViewPluginSamplerAction::_viewingMode must be either Mode::Tooltip or Mode::Windowed

  • ViewPluginSamplerAction::_viewGeneratorFunction must be valid

Returns:

ViewGeneratorType getViewGeneratorType() const

Get the view generator type.

Returns:

View generator type

void setViewGeneratorType(const ViewGeneratorType &viewGeneratorType)

Set the generated view type to generatedViewType.

Parameters:

viewGeneratorType – View generator type

void setHtmlViewGeneratorFunction(const HtmlViewGeneratorFunction &htmlViewGeneratorFunction)

Sets the HTML view generator function to htmlViewGeneratorFunction (automatically sets the viewing type to ViewGeneratorType::HTML)

Parameters:

htmlViewGeneratorFunction – HTML view generator function

void setWidgetViewGeneratorFunction(const WidgetViewGeneratorFunction &widgetViewGeneratorFunction)

Sets the widget view generator function to widgetViewGeneratorFunction (automatically sets the viewing type to ViewGeneratorType::Widget)

Parameters:

widgetViewGeneratorFunction – Widget view generator function

SampleContext getSampleContext() const

Get sample context.

Returns:

Sample variant map

void setSampleContext(const SampleContext &sampleContext)

Set the sample context and flag request an update.

Parameters:

sampleContext – Sample context

QString getViewString() const

Get view string.

Returns:

HTML formatted string

const QWidget *getViewWidget() const

Get view widget.

Returns:

Pointer to view widget (maybe nullptr)

virtual void fromVariantMap(const QVariantMap &variantMap) override

Load view plugin from variant.

Parameters:

variantMap – Variant representation of the view plugin

virtual QVariantMap toVariantMap() const override

Save view plugin to variant.

Returns:

Variant representation of the view plugin

void viewingModeChanged(const ViewingMode &previousViewingMode, const ViewingMode &currentViewingMode)

Signals that the viewing mode changed from previousViewingMode to currentViewingMode.

Parameters:
  • previousViewingMode – Previous viewing mode

  • currentViewingMode – Current viewing mode

void viewGeneratorTypeChanged(const ViewGeneratorType &previousViewGeneratorType, const ViewGeneratorType &currentViewGeneratorType)

Signals that the generated view type changed from previousViewGeneratorType to currentViewGeneratorType.

Parameters:
  • previousViewGeneratorType – Previous generated view type

  • currentViewGeneratorType – Current generated view type

void viewStringChanged(const QString &previousViewString, const QString &currentViewString)

Signals that the view HTML string changed from previousViewString to currentViewString.

Parameters:
  • previousViewString – Previous view HTML string

  • currentViewString – Current view HTML string

void viewWidgetChanged(const QWidget *previousViewWidget, const QWidget *currentViewWidget)

Signals that the view widget changed from previousViewWidget to currentViewWidget.

Parameters:
  • previousViewWidget – Previous view widget

  • currentViewWidget – Current view widget

void sampleContextRequested()

Signals that a new sample context is required.

void sampleContextChanged(const SampleContext &previousSampleContext, const SampleContext &currentSampleContext)

Signals that the sample context changed from previousSampleContext to currentSampleContext.

Parameters:
  • previousSampleContext – Previous sample context

  • currentSampleContext – Current sample context

void canViewChanged(bool canView)

Signals that the view-ability changed to canView.

Parameters:

canView – Current view-ability