From ed0db5c8d8ed12fa02eab5e529db60d92d78d8b2 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Wed, 10 Feb 2016 11:59:59 -0200 Subject: Updated signal/slot connections to function pointers. Also, some small changes in Scatterplot and VoronoiSplat to accomodate this. --- main.cpp | 160 +++++++++++++++++++++++++++---------------------------- scatterplot.cpp | 57 +++++--------------- scatterplot.h | 9 +--- voronoisplat.cpp | 12 ++--- voronoisplat.h | 8 +-- 5 files changed, 104 insertions(+), 142 deletions(-) diff --git a/main.cpp b/main.cpp index c2d79df..3e62963 100644 --- a/main.cpp +++ b/main.cpp @@ -158,112 +158,112 @@ int main(int argc, char **argv) TransitionControl *plotTC = engine.rootObjects()[0]->findChild("plotTC"); // Keep track of the current cp (in order to save them later, if requested) - QObject::connect(m->cpPlot, SIGNAL(xyChanged(const arma::mat &)), - m, SLOT(setCP(const arma::mat &))); - QObject::connect(m->cpPlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), - m, SLOT(setCP(const arma::mat &))); + QObject::connect(m->cpPlot, &Scatterplot::xyChanged, + m, &Main::setCP); + QObject::connect(m->cpPlot, &Scatterplot::xyInteractivelyChanged, + m, &Main::setCP); // Update projection as the cp are modified (either directly in the // manipulationHandler object or interactively in cpPlot ManipulationHandler manipulationHandler(X, cpIndices); - QObject::connect(m->cpPlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), - &manipulationHandler, SLOT(setCP(const arma::mat &))); - QObject::connect(&manipulationHandler, SIGNAL(cpChanged(const arma::mat &)), - m->cpPlot, SLOT(setXY(const arma::mat &))); - QObject::connect(&manipulationHandler, SIGNAL(rpChanged(const arma::mat &)), - m->rpPlot, SLOT(setXY(const arma::mat &))); - QObject::connect(&manipulationHandler, SIGNAL(rpChanged(const arma::mat &)), - m->splat, SLOT(setSites(const arma::mat &))); + QObject::connect(m->cpPlot, &Scatterplot::xyInteractivelyChanged, + &manipulationHandler, &ManipulationHandler::setCP); + QObject::connect(&manipulationHandler, &ManipulationHandler::cpChanged, + m->cpPlot, &Scatterplot::setXY); + QObject::connect(&manipulationHandler, &ManipulationHandler::rpChanged, + m->rpPlot, &Scatterplot::setXY); + QObject::connect(&manipulationHandler, &ManipulationHandler::rpChanged, + m->splat, &VoronoiSplat::setSites); // Keep both scatterplots and the splat scaled equally and relative to the // full plot MapScaleHandler mapScaleHandler; - QObject::connect(&mapScaleHandler, SIGNAL(scaleChanged(const LinearScale &, const LinearScale &)), - m->cpPlot, SLOT(setScale(const LinearScale &, const LinearScale &))); - QObject::connect(&mapScaleHandler, SIGNAL(scaleChanged(const LinearScale &, const LinearScale &)), - m->rpPlot, SLOT(setScale(const LinearScale &, const LinearScale &))); - QObject::connect(&mapScaleHandler, SIGNAL(scaleChanged(const LinearScale &, const LinearScale &)), - m->splat, SLOT(setScale(const LinearScale &, const LinearScale &))); - QObject::connect(&manipulationHandler, SIGNAL(mapChanged(const arma::mat &)), - &mapScaleHandler, SLOT(scaleToMap(const arma::mat &))); - - QObject::connect(m->splat, SIGNAL(colorScaleChanged(const ColorScale &)), - m->colormap, SLOT(setColorScale(const ColorScale &))); + QObject::connect(&manipulationHandler, &ManipulationHandler::mapChanged, + &mapScaleHandler, &MapScaleHandler::scaleToMap); + QObject::connect(&mapScaleHandler, &MapScaleHandler::scaleChanged, + m->cpPlot, &Scatterplot::setScale); + QObject::connect(&mapScaleHandler, &MapScaleHandler::scaleChanged, + m->rpPlot, &Scatterplot::setScale); + QObject::connect(&mapScaleHandler, &MapScaleHandler::scaleChanged, + m->splat, &VoronoiSplat::setScale); + + QObject::connect(m->splat, &VoronoiSplat::colorScaleChanged, + m->colormap, &Colormap::setColorScale); // Linking between selections SelectionHandler cpSelectionHandler(cpIndices.n_elem); - QObject::connect(m->cpPlot, SIGNAL(selectionInteractivelyChanged(const std::vector &)), - &cpSelectionHandler, SLOT(setSelection(const std::vector &))); - QObject::connect(m->cpBarChart, SIGNAL(selectionInteractivelyChanged(const std::vector &)), - &cpSelectionHandler, SLOT(setSelection(const std::vector &))); - QObject::connect(&cpSelectionHandler, SIGNAL(selectionChanged(const std::vector &)), - m->cpPlot, SLOT(setSelection(const std::vector &))); + QObject::connect(m->cpPlot, &Scatterplot::selectionInteractivelyChanged, + &cpSelectionHandler, &SelectionHandler::setSelection); + QObject::connect(m->cpBarChart, &BarChart::selectionInteractivelyChanged, + &cpSelectionHandler, &SelectionHandler::setSelection); + QObject::connect(&cpSelectionHandler, &SelectionHandler::selectionChanged, + m->cpPlot, &Scatterplot::setSelection); SelectionHandler rpSelectionHandler(X.n_rows - cpIndices.n_elem); - QObject::connect(m->rpPlot, SIGNAL(selectionInteractivelyChanged(const std::vector &)), - &rpSelectionHandler, SLOT(setSelection(const std::vector &))); - QObject::connect(m->rpBarChart, SIGNAL(selectionInteractivelyChanged(const std::vector &)), - &rpSelectionHandler, SLOT(setSelection(const std::vector &))); - QObject::connect(&rpSelectionHandler, SIGNAL(selectionChanged(const std::vector &)), - m->rpPlot, SLOT(setSelection(const std::vector &))); + QObject::connect(m->rpPlot, &Scatterplot::selectionInteractivelyChanged, + &rpSelectionHandler, &SelectionHandler::setSelection); + QObject::connect(m->rpBarChart, &BarChart::selectionInteractivelyChanged, + &rpSelectionHandler, &SelectionHandler::setSelection); + QObject::connect(&rpSelectionHandler, &SelectionHandler::selectionChanged, + m->rpPlot, &Scatterplot::setSelection); // Brushing between bar chart and respective scatterplot BrushingHandler cpBrushHandler; - QObject::connect(m->cpPlot, SIGNAL(itemInteractivelyBrushed(int)), - &cpBrushHandler, SLOT(brushItem(int))); - QObject::connect(m->cpBarChart, SIGNAL(itemInteractivelyBrushed(int)), - &cpBrushHandler, SLOT(brushItem(int))); - QObject::connect(&cpBrushHandler, SIGNAL(itemBrushed(int)), - m->cpPlot, SLOT(brushItem(int))); - QObject::connect(&cpBrushHandler, SIGNAL(itemBrushed(int)), - m->cpBarChart, SLOT(brushItem(int))); + QObject::connect(m->cpPlot, &Scatterplot::itemInteractivelyBrushed, + &cpBrushHandler, &BrushingHandler::brushItem); + QObject::connect(m->cpBarChart, &BarChart::itemInteractivelyBrushed, + &cpBrushHandler, &BrushingHandler::brushItem); + QObject::connect(&cpBrushHandler, &BrushingHandler::itemBrushed, + m->cpPlot, &Scatterplot::brushItem); + QObject::connect(&cpBrushHandler, &BrushingHandler::itemBrushed, + m->cpBarChart, &BarChart::brushItem); BrushingHandler rpBrushHandler; - QObject::connect(m->rpPlot, SIGNAL(itemInteractivelyBrushed(int)), - &rpBrushHandler, SLOT(brushItem(int))); - QObject::connect(m->rpBarChart, SIGNAL(itemInteractivelyBrushed(int)), - &rpBrushHandler, SLOT(brushItem(int))); - QObject::connect(&rpBrushHandler, SIGNAL(itemBrushed(int)), - m->rpPlot, SLOT(brushItem(int))); - QObject::connect(&rpBrushHandler, SIGNAL(itemBrushed(int)), - m->rpBarChart, SLOT(brushItem(int))); + QObject::connect(m->rpPlot, &Scatterplot::itemInteractivelyBrushed, + &rpBrushHandler, &BrushingHandler::brushItem); + QObject::connect(m->rpBarChart, &BarChart::itemInteractivelyBrushed, + &rpBrushHandler, &BrushingHandler::brushItem); + QObject::connect(&rpBrushHandler, &BrushingHandler::itemBrushed, + m->rpPlot, &Scatterplot::brushItem); + QObject::connect(&rpBrushHandler, &BrushingHandler::itemBrushed, + m->rpBarChart, &BarChart::brushItem); // Recompute values whenever projection changes ProjectionObserver projectionObserver(X, cpIndices); m->projectionObserver = &projectionObserver; - QObject::connect(&manipulationHandler, SIGNAL(mapChanged(const arma::mat &)), - m->projectionObserver, SLOT(setMap(const arma::mat &))); - QObject::connect(m->projectionObserver, SIGNAL(cpValuesChanged(const arma::vec &)), - m->cpPlot, SLOT(setColorData(const arma::vec &))); - QObject::connect(m->projectionObserver, SIGNAL(rpValuesChanged(const arma::vec &)), - m->splat, SLOT(setValues(const arma::vec &))); - QObject::connect(m->projectionObserver, SIGNAL(cpValuesChanged(const arma::vec &)), - m->cpBarChart, SLOT(setValues(const arma::vec &))); - QObject::connect(m->projectionObserver, SIGNAL(rpValuesChanged(const arma::vec &)), - m->rpBarChart, SLOT(setValues(const arma::vec &))); + QObject::connect(&manipulationHandler, &ManipulationHandler::mapChanged, + m->projectionObserver, &ProjectionObserver::setMap); + QObject::connect(m->projectionObserver, &ProjectionObserver::cpValuesChanged, + m->cpPlot, &Scatterplot::setColorData); + QObject::connect(m->projectionObserver, &ProjectionObserver::rpValuesChanged, + m->splat, &VoronoiSplat::setValues); + QObject::connect(m->projectionObserver, &ProjectionObserver::cpValuesChanged, + m->cpBarChart, &BarChart::setValues); + QObject::connect(m->projectionObserver, &ProjectionObserver::rpValuesChanged, + m->rpBarChart, &BarChart::setValues); // Recompute values whenever selection changes - QObject::connect(&cpSelectionHandler, SIGNAL(selectionChanged(const std::vector &)), - &projectionObserver, SLOT(setCPSelection(const std::vector &))); - QObject::connect(&rpSelectionHandler, SIGNAL(selectionChanged(const std::vector &)), - &projectionObserver, SLOT(setRPSelection(const std::vector &))); + QObject::connect(&cpSelectionHandler, &SelectionHandler::selectionChanged, + &projectionObserver, &ProjectionObserver::setCPSelection); + QObject::connect(&rpSelectionHandler, &SelectionHandler::selectionChanged, + &projectionObserver, &ProjectionObserver::setRPSelection); // Connect visual components (but not barcharts) to rewinding mechanism - QObject::connect(plotTC, SIGNAL(tChanged(double)), - &manipulationHandler, SLOT(setRewind(double))); - QObject::connect(&manipulationHandler, SIGNAL(cpRewound(const arma::mat &)), - m->cpPlot, SLOT(setXY(const arma::mat &))); - QObject::connect(&manipulationHandler, SIGNAL(rpRewound(const arma::mat &)), - m->rpPlot, SLOT(setXY(const arma::mat &))); - QObject::connect(&manipulationHandler, SIGNAL(rpRewound(const arma::mat &)), - m->splat, SLOT(setSites(const arma::mat &))); - - QObject::connect(plotTC, SIGNAL(tChanged(double)), - m->projectionObserver, SLOT(setRewind(double))); - QObject::connect(m->projectionObserver, SIGNAL(cpValuesRewound(const arma::vec &)), - m->cpPlot, SLOT(setColorData(const arma::vec &))); - QObject::connect(m->projectionObserver, SIGNAL(rpValuesRewound(const arma::vec &)), - m->splat, SLOT(setValues(const arma::vec &))); + QObject::connect(plotTC, &TransitionControl::tChanged, + &manipulationHandler, &ManipulationHandler::setRewind); + QObject::connect(&manipulationHandler, &ManipulationHandler::cpRewound, + m->cpPlot, &Scatterplot::setXY); + QObject::connect(&manipulationHandler, &ManipulationHandler::rpRewound, + m->rpPlot, &Scatterplot::setXY); + QObject::connect(&manipulationHandler, &ManipulationHandler::rpRewound, + m->splat, &VoronoiSplat::setSites); + + QObject::connect(plotTC, &TransitionControl::tChanged, + m->projectionObserver, &ProjectionObserver::setRewind); + QObject::connect(m->projectionObserver, &ProjectionObserver::cpValuesRewound, + m->cpPlot, &Scatterplot::setColorData); + QObject::connect(m->projectionObserver, &ProjectionObserver::rpValuesRewound, + m->splat, &VoronoiSplat::setValues); // General component set up plotTC->setAcceptedMouseButtons(Qt::MiddleButton); diff --git a/scatterplot.cpp b/scatterplot.cpp index 91c85e5..4ef266b 100644 --- a/scatterplot.cpp +++ b/scatterplot.cpp @@ -243,7 +243,7 @@ bool Scatterplot::saveToFile(const QUrl &url) return m_xy.save(url.path().toStdString(), arma::raw_ascii); } -void Scatterplot::setXY(const arma::mat &xy, bool updateView) +void Scatterplot::setXY(const arma::mat &xy) { if (xy.n_cols != 2) { return; @@ -262,23 +262,17 @@ void Scatterplot::setXY(const arma::mat &xy, bool updateView) } if (m_opacityData.n_elem != m_xy.n_rows) { - arma::vec opacityData(xy.n_rows); - opacityData.fill(GLYPH_OPACITY); - setOpacityData(opacityData, false); + // Reset opacity data + m_opacityData.resize(xy.n_rows); + m_opacityData.fill(GLYPH_OPACITY); + emit opacityDataChanged(m_opacityData); } m_shouldUpdateGeometry = true; - if (updateView) { - update(); - } -} - -void Scatterplot::setXY(const arma::mat &xy) -{ - setXY(xy, true); + update(); } -void Scatterplot::setColorData(const arma::vec &colorData, bool updateView) +void Scatterplot::setColorData(const arma::vec &colorData) { if (m_xy.n_rows > 0 && (colorData.n_elem > 0 && colorData.n_elem != m_xy.n_rows)) { @@ -293,17 +287,10 @@ void Scatterplot::setColorData(const arma::vec &colorData, bool updateView) } m_shouldUpdateMaterials = true; - if (updateView) { - update(); - } -} - -void Scatterplot::setColorData(const arma::vec &colorData) -{ - setColorData(colorData, true); + update(); } -void Scatterplot::setOpacityData(const arma::vec &opacityData, bool updateView) +void Scatterplot::setOpacityData(const arma::vec &opacityData) { if (m_xy.n_rows > 0 && opacityData.n_elem != m_xy.n_rows) { return; @@ -311,18 +298,10 @@ void Scatterplot::setOpacityData(const arma::vec &opacityData, bool updateView) m_opacityData = opacityData; emit opacityDataChanged(m_opacityData); - - if (updateView) { - update(); - } -} - -void Scatterplot::setOpacityData(const arma::vec &opacityData) -{ - setOpacityData(opacityData, true); + update(); } -void Scatterplot::setScale(const LinearScale &sx, const LinearScale &sy, bool updateView) +void Scatterplot::setScale(const LinearScale &sx, const LinearScale &sy) { m_sx = sx; m_sy = sy; @@ -331,14 +310,7 @@ void Scatterplot::setScale(const LinearScale &sx, const LinearScale &sx, const LinearScale &sy) -{ - setScale(sx, sy, true); + update(); } void Scatterplot::setAutoScale(bool autoScale) @@ -368,11 +340,6 @@ void Scatterplot::setGlyphSize(float glyphSize, bool updateView) } } -void Scatterplot::setGlyphSize(float glyphSize) -{ - setGlyphSize(glyphSize, true); -} - QSGNode *Scatterplot::newSceneGraph() { // NOTE: diff --git a/scatterplot.h b/scatterplot.h index 93f4f3f..1b40040 100644 --- a/scatterplot.h +++ b/scatterplot.h @@ -23,11 +23,6 @@ public: arma::mat XY() const; void setColorScale(const ColorScale &colorScale); - void setXY(const arma::mat &xy, bool updateView); - void setColorData(const arma::vec &colorData, bool updateView); - void setOpacityData(const arma::vec &opacityData, bool updateView); - void setScale(const LinearScale &sx, const LinearScale &sy, bool updateView); - void setGlyphSize(float glyphSize, bool updateView); void setAutoScale(bool autoScale); Q_INVOKABLE bool saveToFile(const QUrl &url); @@ -52,10 +47,10 @@ public slots: void setXY(const arma::mat &xy); void setColorData(const arma::vec &colorData); void setOpacityData(const arma::vec &opacityData); + void setScale(const LinearScale &sx, const LinearScale &sy); void setSelection(const std::vector &selection); void brushItem(int item); - void setScale(const LinearScale &sx, const LinearScale &sy); - Q_INVOKABLE void setGlyphSize(float glyphSize); + Q_INVOKABLE void setGlyphSize(float glyphSize, bool updateView = true); protected: QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); diff --git a/voronoisplat.cpp b/voronoisplat.cpp index 7c5641b..f1ed821 100644 --- a/voronoisplat.cpp +++ b/voronoisplat.cpp @@ -85,7 +85,7 @@ void VoronoiSplat::setColorScale(const ColorScale &scale) scale.sample(scale.numColors(), m_cmap.begin()); emit colorScaleChanged(scale); - setColorScaleChanged(true); + setColormapChanged(true); update(); } @@ -152,7 +152,7 @@ private: GLuint m_VBOs[3]; GLuint m_textures[2], m_colormapTex; QOpenGLVertexArrayObject m_sitesVAO, m_2ndPassVAO; - bool m_sitesChanged, m_valuesChanged, m_colorScaleChanged; + bool m_sitesChanged, m_valuesChanged, m_colormapChanged; }; QQuickFramebufferObject::Renderer *VoronoiSplat::createRenderer() const @@ -361,7 +361,7 @@ void VoronoiSplatRenderer::render() if (m_valuesChanged) { updateValues(); } - if (m_colorScaleChanged) { + if (m_colormapChanged) { updateColorScale(); } @@ -439,12 +439,12 @@ void VoronoiSplatRenderer::synchronize(QQuickFramebufferObject *item) m_sitesChanged = splat->sitesChanged(); m_valuesChanged = splat->valuesChanged(); - m_colorScaleChanged = splat->colorScaleChanged(); + m_colormapChanged = splat->colormapChanged(); // Reset so that we have the correct values by the next synchronize() splat->setSitesChanged(false); splat->setValuesChanged(false); - splat->setColorScaleChanged(false); + splat->setColormapChanged(false); m_sites = &(splat->sites()); m_values = &(splat->values()); @@ -511,7 +511,7 @@ void VoronoiSplatRenderer::updateColorScale() gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_cmap->size() / 3, 1, 0, GL_RGB, GL_FLOAT, m_cmap->data()); - m_colorScaleChanged = false; + m_colormapChanged = false; } void VoronoiSplatRenderer::computeDT() diff --git a/voronoisplat.h b/voronoisplat.h index 21d2fb9..097b1ed 100644 --- a/voronoisplat.h +++ b/voronoisplat.h @@ -27,7 +27,7 @@ public: bool sitesChanged() const { return m_sitesChanged; } bool valuesChanged() const { return m_valuesChanged; } - bool colorScaleChanged() const { return m_colorScaleChanged; } + bool colormapChanged() const { return m_colormapChanged; } void setSitesChanged(bool sitesChanged) { m_sitesChanged = sitesChanged; @@ -35,8 +35,8 @@ public: void setValuesChanged(bool valuesChanged) { m_valuesChanged = valuesChanged; } - void setColorScaleChanged(bool colorScaleChanged) { - m_colorScaleChanged = colorScaleChanged; + void setColormapChanged(bool colormapChanged) { + m_colormapChanged = colormapChanged; } signals: @@ -69,7 +69,7 @@ private: std::vector m_sites, m_values, m_cmap; LinearScale m_sx, m_sy; float m_alpha, m_beta; - bool m_sitesChanged, m_valuesChanged, m_colorScaleChanged; + bool m_sitesChanged, m_valuesChanged, m_colormapChanged; }; #endif // VORONOISPLAT_H -- cgit v1.2.3