From 0f34fd437efb936ef29ac91186321aa7251fbfb1 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Tue, 23 May 2023 11:22:33 +0200 Subject: Massive changes in initial port away from Qt. --- barchart.cpp | 79 ++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 26 deletions(-) (limited to 'barchart.cpp') diff --git a/barchart.cpp b/barchart.cpp index 8eab073..a21d353 100644 --- a/barchart.cpp +++ b/barchart.cpp @@ -4,20 +4,15 @@ #include #include -#include -#include -#include -#include - #include "continuouscolorscale.h" #include "geometry.h" -static const QColor OUTLINE_COLOR(0, 0, 0); -static const QColor BRUSH_COLOR(0, 0, 0); -static const QColor BAR_COLOR(128, 128, 128); -static const QColor PRESELECTION_COLOR(128, 128, 128, 96); -static const QColor SELECTION_VISIBLE_COLOR(128, 128, 128, 96); -static const QColor SELECTION_INVISIBLE_COLOR(0, 0, 0, 0); +static const Color OUTLINE_COLOR(0, 0, 0); +static const Color BRUSH_COLOR(0, 0, 0); +static const Color BAR_COLOR(128, 128, 128); +static const Color PRESELECTION_COLOR(128, 128, 128, 96); +static const Color SELECTION_VISIBLE_COLOR(128, 128, 128, 96); +static const Color SELECTION_INVISIBLE_COLOR(0, 0, 0, 0); static const float DEFAULT_OPACITY = 0.8f; @@ -27,9 +22,8 @@ static inline T clamp(T value, T min, T max) return std::min(std::max(min, value), max); } -BarChart::BarChart(QQuickItem *parent) - : QQuickItem(parent) - , m_shouldUpdateBars(false) +BarChart::BarChart() + : m_shouldUpdateBars(false) , m_shouldUpdatePreSelection(false) , m_dragStartPos(-1.0f) , m_dragLastPos(-1.0f) @@ -37,13 +31,12 @@ BarChart::BarChart(QQuickItem *parent) , m_brushedItem(-1) , m_colorScale(0) , m_scale(0.0f, 1.0f, 0.0f, 1.0f) + , m_width(0) + , m_height(0) { - setClip(true); - setFlag(QQuickItem::ItemHasContents); - //setAcceptedMouseButtons(Qt::LeftButton); } -BarChart::~BarChart() +void BarChart::update() { } @@ -57,7 +50,7 @@ void BarChart::setValues(const arma::vec &values) m_originalIndices.resize(m_values.n_elem); m_currentIndices.resize(m_values.n_elem); - setAcceptHoverEvents(m_values.n_elem > 0); + // setAcceptHoverEvents(m_values.n_elem > 0); if (m_values.n_elem > 0) { m_scale.setDomain(m_values.min(), m_values.max()); @@ -72,7 +65,7 @@ void BarChart::setValues(const arma::vec &values) m_currentIndices[i] = k++; } } - emit valuesChanged(values); + valuesChanged(values); m_shouldUpdateSelection = true; m_shouldUpdateBars = true; @@ -90,10 +83,10 @@ void BarChart::updateValues(const arma::vec &values) update(); } -void BarChart::setColorScale(const ColorScale *scale) +void BarChart::setColorScale(std::shared_ptr scale) { m_colorScale = scale; - emit colorScaleChanged(m_colorScale); + colorScaleChanged(m_colorScale); m_shouldUpdateBars = true; update(); @@ -102,7 +95,7 @@ void BarChart::setColorScale(const ColorScale *scale) void BarChart::setSelection(const std::vector &selection) { m_selection = selection; - emit selectionChanged(m_selection); + selectionChanged(m_selection); // Our selection changed but we don't want to display it unless we have the // right number of values @@ -116,7 +109,7 @@ void BarChart::brushItem(int item) { if (item < 0) { m_brushedItem = item; - emit itemBrushed(m_brushedItem, 0.0f); + itemBrushed(m_brushedItem, 0.0f); } else { // safe comparison: we just checked for negative values if (m_values.n_elem == 0 || item > m_values.n_elem - 1) { @@ -125,12 +118,13 @@ void BarChart::brushItem(int item) m_brushedItem = m_currentIndices[item]; item = m_originalIndices[m_brushedItem]; - emit itemBrushed(item, m_values[item]); + itemBrushed(item, m_values[item]); } update(); } +/* QSGNode *BarChart::newSceneGraph() const { // NOTE: scene graph structure is as follows: @@ -172,7 +166,9 @@ QSGNode *BarChart::newSceneGraph() const return root; } +*/ +/* QSGNode *BarChart::newBarNode() const { // A bar node is: @@ -209,13 +205,17 @@ QSGNode *BarChart::newBarNode() const return opacityNode; } +*/ +/* QSGNode *BarChart::newSelectionBarNode() const { QSGSimpleRectNode *node = new QSGSimpleRectNode; return node; } +*/ +/* void BarChart::updateViewport(QSGNode *root) const { QSGTransformNode *viewportNode = static_cast(root); @@ -223,7 +223,9 @@ void BarChart::updateViewport(QSGNode *root) const viewport.scale(width(), height()); viewportNode->setMatrix(viewport); } +*/ +/* void BarChart::updateBarNodeGeom(QSGNode *barNode, float x, float barWidth, @@ -241,7 +243,9 @@ void BarChart::updateBarNodeGeom(QSGNode *barNode, //updateRectGeometry(outlineGeomNode->geometry(), x, y, barWidth, barHeight); //outlineGeomNode->markDirty(QSGNode::DirtyGeometry); } +*/ +/* void BarChart::updateBarNodeColor(QSGNode *barNode, const QColor &color) const { QSGGeometryNode *barGeomNode = @@ -279,7 +283,9 @@ void BarChart::updateBars(QSGNode *node) const node = node->nextSibling(); } } +*/ +/* void BarChart::updateSelectionBar(QSGNode *node, float x, float barWidth, @@ -289,7 +295,9 @@ void BarChart::updateSelectionBar(QSGNode *node, barNode->setRect(x, 0, barWidth, 1.0f); barNode->setColor(color); } +*/ +/* void BarChart::updateSelectionBars(QSGNode *node) const { int numValues = (int) m_values.n_elem; @@ -318,14 +326,18 @@ void BarChart::updateSelectionBars(QSGNode *node) const node = node->nextSibling(); } } +*/ +/* void BarChart::updatePreSelection(QSGNode *node) const { QSGSimpleRectNode *preSelectionNode = static_cast(node); preSelectionNode->setRect(std::min(m_dragStartPos, m_dragLastPos), 0.0f, fabs(m_dragLastPos - m_dragStartPos), 1.0f); } +*/ +/* void BarChart::updateBrush(QSGNode *node) const { float barWidth = 1.0f / m_values.n_elem; @@ -337,7 +349,9 @@ void BarChart::updateBrush(QSGNode *node) const 1.0f); brushGeomNode->markDirty(QSGNode::DirtyGeometry); } +*/ +/* QSGNode *BarChart::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) { QSGNode *root = oldNode ? oldNode : newSceneGraph(); @@ -367,6 +381,7 @@ QSGNode *BarChart::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) return root; } +*/ int BarChart::itemAt(float x, bool includeSelectorWidth) const { @@ -398,9 +413,10 @@ void BarChart::interactiveSelection(float start, float end) m_selection[m_originalIndices[i]] = true; } - emit selectionInteractivelyChanged(m_selection); + selectionInteractivelyChanged(m_selection); } +/* void BarChart::hoverEnterEvent(QHoverEvent *event) { m_brushedItem = itemAt(float(event->pos().x()) / width()); @@ -408,7 +424,9 @@ void BarChart::hoverEnterEvent(QHoverEvent *event) update(); } +*/ +/* void BarChart::hoverMoveEvent(QHoverEvent *event) { m_brushedItem = itemAt(float(event->pos().x()) / width()); @@ -416,7 +434,9 @@ void BarChart::hoverMoveEvent(QHoverEvent *event) update(); } +*/ +/* void BarChart::hoverLeaveEvent(QHoverEvent *event) { m_brushedItem = -1; @@ -424,7 +444,9 @@ void BarChart::hoverLeaveEvent(QHoverEvent *event) update(); } +*/ +/* void BarChart::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::RightButton) { @@ -444,7 +466,9 @@ void BarChart::mousePressEvent(QMouseEvent *event) m_shouldUpdatePreSelection = true; update(); } +*/ +/* void BarChart::mouseMoveEvent(QMouseEvent *event) { if (m_dragStartPos < 0.0f) { @@ -457,7 +481,9 @@ void BarChart::mouseMoveEvent(QMouseEvent *event) m_shouldUpdatePreSelection = true; update(); } +*/ +/* void BarChart::mouseReleaseEvent(QMouseEvent *event) { if (m_dragStartPos < 0.0f) { @@ -478,3 +504,4 @@ void BarChart::mouseReleaseEvent(QMouseEvent *event) m_shouldUpdatePreSelection = true; update(); } +*/ -- cgit v1.2.3