# HG changeset patch # User Chris Cannam # Date 1226503036 0 # Node ID e5800f4490c4806abf196805da7b14f6ecabe455 # Parent 5124d1494a59461c187d5a3af880ce3e04bf4797 * Make Colour 3D Plot layer vertically zoomable and scrollable Still need to save/restore these settings for this and the time/value and note layers diff -r 5124d1494a59 -r e5800f4490c4 layer/Colour3DPlotLayer.cpp --- a/layer/Colour3DPlotLayer.cpp Tue Nov 11 13:54:47 2008 +0000 +++ b/layer/Colour3DPlotLayer.cpp Wed Nov 12 15:17:16 2008 +0000 @@ -18,6 +18,7 @@ #include "view/View.h" #include "base/Profiler.h" #include "base/LogRange.h" +#include "base/RangeMapper.h" #include "ColourMapper.h" #include @@ -40,7 +41,9 @@ m_colourMap(0), m_normalizeColumns(false), m_normalizeVisibleArea(false), - m_invertVertical(false) + m_invertVertical(false), + m_miny(0), + m_maxy(0) { } @@ -290,6 +293,99 @@ return !v->shouldIlluminateLocalFeatures(this, discard); } +bool +Colour3DPlotLayer::getValueExtents(float &min, float &max, + bool &logarithmic, QString &unit) const +{ + if (!m_model) return false; + + min = 0; + max = m_model->getHeight(); + + logarithmic = false; + unit = ""; + + return true; +} + +bool +Colour3DPlotLayer::getDisplayExtents(float &min, float &max) const +{ + if (!m_model) return false; + + min = m_miny; + max = m_maxy; + if (max <= min) { + min = 0; + max = m_model->getHeight(); + } + if (min < 0) min = 0; + if (max > m_model->getHeight()) max = m_model->getHeight(); + + return true; +} + +bool +Colour3DPlotLayer::setDisplayExtents(float min, float max) +{ + if (!m_model) return false; + + m_miny = lrintf(min); + m_maxy = lrintf(max); + + emit layerParametersChanged(); + return true; +} + +int +Colour3DPlotLayer::getVerticalZoomSteps(int &defaultStep) const +{ + if (!m_model) return 0; + + defaultStep = 0; + int h = m_model->getHeight(); + return h; +} + +int +Colour3DPlotLayer::getCurrentVerticalZoomStep() const +{ + if (!m_model) return 0; + + float min, max; + getDisplayExtents(min, max); + return m_model->getHeight() - lrintf(max - min); +} + +void +Colour3DPlotLayer::setVerticalZoomStep(int step) +{ + if (!m_model) return; + + std::cerr << "Colour3DPlotLayer::setVerticalZoomStep(" <getHeight(); + int symin = m_miny; + int symax = m_maxy; + if (symax <= symin) { + symin = 0; + symax = sh; + } + if (symin < 0) symin = 0; + if (symax > sh) symax = sh; + if (sx0 > 0) --sx0; fillCache(sx0 < 0 ? 0 : sx0, sx1 < 0 ? 0 : sx1); @@ -667,16 +772,17 @@ paint.fontMetrics().width("0.000000") < rw - 3 && paint.fontMetrics().height() < (h / sh)); - for (int sy = 0; sy < sh; ++sy) { + for (int sy = symin; sy < symax; ++sy) { - int ry0 = h - (sy * h) / sh - 1; + int ry0 = h - ((sy - symin) * h) / (symax - symin) - 1; QRgb pixel = qRgb(255, 255, 255); if (scx >= 0 && scx < m_cache->width() && sy >= 0 && sy < m_cache->height()) { pixel = m_cache->pixel(scx, sy); } - QRect r(rx0, ry0 - h / sh - 1, rw, h / sh + 1); + QRect r(rx0, ry0 - h / (symax - symin) - 1, + rw, h / (symax - symin) + 1); if (rw == 1) { paint.setPen(pixel); @@ -741,6 +847,15 @@ int h = v->height(); int sh = m_model->getHeight(); + int symin = m_miny; + int symax = m_maxy; + if (symax <= symin) { + symin = 0; + symax = sh; + } + if (symin < 0) symin = 0; + if (symax > sh) symax = sh; + QImage img(w, h, QImage::Format_RGB32); for (int x = x0; x < x1; ++x) { @@ -763,8 +878,8 @@ for (int y = 0; y < h; ++y) { - float sy0 = (float(h - y - 1) * sh) / h; - float sy1 = (float(h - y) * sh) / h; + float sy0 = symin + (float(h - y - 1) * (symax - symin)) / h; + float sy1 = symin + (float(h - y) * (symax - symin)) / h; int sy0i = int(sy0 + 0.001); int sy1i = int(sy1); diff -r 5124d1494a59 -r e5800f4490c4 layer/Colour3DPlotLayer.h --- a/layer/Colour3DPlotLayer.h Tue Nov 11 13:54:47 2008 +0000 +++ b/layer/Colour3DPlotLayer.h Wed Nov 12 15:17:16 2008 +0000 @@ -70,8 +70,6 @@ virtual int getCompletion(View *) const { return m_model->getCompletion(); } - virtual bool getValueExtents(float &, float &, bool &, QString &) const { return false; } - virtual PropertyList getProperties() const; virtual PropertyType getPropertyType(const PropertyName &) const; virtual QString getPropertyLabel(const PropertyName &) const; @@ -101,6 +99,17 @@ void setInvertVertical(bool i); bool getInvertVertical() const; + virtual bool getValueExtents(float &min, float &max, + bool &logarithmic, QString &unit) const; + + virtual bool getDisplayExtents(float &min, float &max) const; + virtual bool setDisplayExtents(float min, float max); + + virtual int getVerticalZoomSteps(int &defaultStep) const; + virtual int getCurrentVerticalZoomStep() const; + virtual void setVerticalZoomStep(int); + virtual RangeMapper *getNewVerticalZoomRangeMapper() const; + virtual const Model *getSliceableModel() const { return m_model; } virtual void toXml(QTextStream &stream, QString indent = "", @@ -122,6 +131,9 @@ bool m_normalizeVisibleArea; bool m_invertVertical; + int m_miny; + int m_maxy; + void getColumn(size_t col, DenseThreeDimensionalModel::Column &) const; virtual int getColourScaleWidth(QPainter &) const;