libpappsomspp
Library for mass spectrometry
pappso::BaseColorMapPlotWidget Class Reference

#include <basecolormapplotwidget.h>

Inheritance diagram for pappso::BaseColorMapPlotWidget:
pappso::BasePlotWidget pappso::DriftSpecMassSpecColorMapPlotWidget pappso::TicXicChromDriftSpecColorMapPlotWidget pappso::TicXicChromMassSpecColorMapPlotWidget

Public Member Functions

 BaseColorMapPlotWidget (QWidget *parent, const QString &x_axis_label, const QString &y_axis_label)
 
virtual ~BaseColorMapPlotWidget ()
 Destruct this BaseColorMapPlotWidget instance. More...
 
virtual void setColorMapPlotConfig (const ColorMapPlotConfig &color_map_config)
 
virtual const ColorMapPlotConfiggetColorMapPlotConfig ()
 
virtual QCPColorMap * addColorMap (std::shared_ptr< std::map< double, MapTrace >> double_map_trace_map_sp, ColorMapPlotConfig color_map_plot_config, const QColor &color)
 
virtual void transposeAxes ()
 
DataKind xAxisDataKind () const
 
DataKind yAxisDataKind () const
 
virtual void setPlottingColor (QCPAbstractPlottable *plottable_p, const QColor &new_color) override
 
virtual QColor getPlottingColor (int index=0) const override
 
- Public Member Functions inherited from pappso::BasePlotWidget
 BasePlotWidget (QWidget *parent)
 
 BasePlotWidget (QWidget *parent, const QString &x_axis_label, const QString &y_axis_label)
 
virtual ~BasePlotWidget ()
 Destruct this BasePlotWidget instance. More...
 
virtual bool setupWidget ()
 
virtual void setPen (const QPen &pen)
 
virtual const QPen & getPen () const
 
virtual void setPlottingColor (int index, const QColor &new_color)
 
virtual QColor getPlottingColor (QCPAbstractPlottable *plottable_p) const
 
virtual void setAxisLabelX (const QString &label)
 
virtual void setAxisLabelY (const QString &label)
 
virtual void resetAxesRangeHistory ()
 
virtual void updateAxesRangeHistory ()
 Create new axis range history items and append them to the history. More...
 
virtual void restorePreviousAxesRangeHistory ()
 Go up one history element in the axis history. More...
 
virtual void restoreAxesRangeHistory (std::size_t index)
 Get the axis histories at index index and update the plot ranges. More...
 
virtual void keyPressEvent (QKeyEvent *event)
 KEYBOARD-related EVENTS. More...
 
virtual void keyReleaseEvent (QKeyEvent *event)
 Handle specific key codes and trigger respective actions. More...
 
virtual void spaceKeyReleaseEvent (QKeyEvent *event)
 
virtual void directionKeyPressEvent (QKeyEvent *event)
 
virtual void directionKeyReleaseEvent (QKeyEvent *event)
 
virtual void mousePseudoButtonKeyPressEvent (QKeyEvent *event)
 
virtual void mousePseudoButtonKeyReleaseEvent (QKeyEvent *event)
 
virtual void mousePressHandler (QMouseEvent *event)
 KEYBOARD-related EVENTS. More...
 
virtual void mouseReleaseHandler (QMouseEvent *event)
 
virtual void mouseReleaseHandlerLeftButton ()
 
virtual void mouseReleaseHandlerRightButton ()
 
virtual void mouseMoveHandler (QMouseEvent *event)
 
virtual void mouseMoveHandlerNotDraggingCursor ()
 
virtual void mouseMoveHandlerDraggingCursor ()
 
virtual void mouseMoveHandlerLeftButtonDraggingCursor ()
 
virtual void mouseMoveHandlerRightButtonDraggingCursor ()
 
virtual void axisDoubleClickHandler (QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event)
 
bool isClickOntoXAxis (const QPointF &mousePoint)
 
bool isClickOntoYAxis (const QPointF &mousePoint)
 
int dragDirection ()
 MOUSE-related EVENTS. More...
 
virtual void moveMouseCursorGraphCoordToGlobal (QPointF plot_coordinates)
 
virtual void moveMouseCursorPixelCoordToGlobal (QPointF local_coordinates)
 
virtual void horizontalMoveMouseCursorCountPixels (int pixel_count)
 
virtual QPointF horizontalGetGraphCoordNewPointCountPixels (int pixel_count)
 
virtual void verticalMoveMouseCursorCountPixels (int pixel_count)
 
virtual QPointF verticalGetGraphCoordNewPointCountPixels (int pixel_count)
 
virtual QCPRange getRangeX (bool &found_range, int index) const
 MOUSE MOVEMENTS mouse/keyboard-triggered. More...
 
virtual QCPRange getRangeY (bool &found_range, int index) const
 
QCPRange getRange (PlotAxis axis, RangeType range_type, bool &found_range) const
 
virtual QCPRange getInnermostRangeX (bool &found_range) const
 
virtual QCPRange getOutermostRangeX (bool &found_range) const
 
virtual QCPRange getInnermostRangeY (bool &found_range) const
 
virtual QCPRange getOutermostRangeY (bool &found_range) const
 
void yMinMaxOnXAxisCurrentRange (double &min, double &max, QCPAbstractPlottable *plottable_p=nullptr)
 
void yMinMaxOnXAxisCurrentRange (double &min, double &max, int index)
 
virtual void axisRescale ()
 RANGE-related functions. More...
 
virtual void axisReframe ()
 
virtual void axisZoom ()
 
virtual void axisPan ()
 
virtual void replotWithAxesRanges (QCPRange xAxisRange, QCPRange yAxisRange, PlotAxis whichAxis)
 
virtual void replotWithAxisRangeX (double lower, double upper)
 
virtual void replotWithAxisRangeY (double lower, double upper)
 
virtual void hideAllPlotItems ()
 PLOTTING / REPLOTTING functions. More...
 
virtual void showTracers ()
 Show the traces (vertical and horizontal). More...
 
virtual void hideTracers ()
 Hide the traces (vertical and horizontal). More...
 
virtual void drawRectangleAndPrepareZoom ()
 
virtual void prepareXDeltaLineAndMeasure ()
 
virtual void drawXDeltaLineAndMeasure ()
 
virtual void drawXDeltaLineForIntegration ()
 
virtual void calculateDragDeltas ()
 
virtual void calculateDragDeltasAndUnSortedRegionCorners ()
 
virtual bool isProperSelectionRectangle ()
 
virtual void setFocus ()
 PLOT ITEMS : TRACER TEXT ITEMS... More...
 
virtual void redrawPlotBackground (QWidget *focusedPlotWidget)
 Redraw the background of the focusedPlotWidget plot widget. More...
 
virtual void updateContextRanges ()
 
virtual const BasePlotContextgetContext () const
 

Protected Attributes

ColorMapPlotConfig m_colorMapPlotConfig
 
- Protected Attributes inherited from pappso::BasePlotWidget
QString m_name = "NOT_SET"
 Name of the plot widget. More...
 
QString m_desc = "NOT_SET"
 Description of the plot widget. More...
 
QString m_fileName
 The name of the data file from which the mass data were read. More...
 
QString m_axisLabelX
 
QString m_axisLabelY
 
BasePlotContext m_context
 
int m_leftMousePseudoButtonKey = Qt::Key_Less
 
int m_rightMousePseudoButtonKey = Qt::Key_Greater
 
QCPItemRect * mp_zoomRectItem = nullptr
 Rectangle defining the borders of zoomed-in/out data. More...
 
QCPItemLine * mp_selectLineItem = nullptr
 Line that is printed when the user selects a range. More...
 
QCPItemText * mp_xDeltaTextItem = nullptr
 Text describing the x-axis delta value during a drag operation. More...
 
bool m_shouldTracersBeVisible = true
 Tells if the tracers should be visible. More...
 
QCPItemLine * mp_hPosTracerItem
 Horizontal position tracer. More...
 
QCPItemLine * mp_vPosTracerItem
 Vertical position tracer. More...
 
QCPItemLine * mp_vStartTracerItem
 Vertical selection start tracer (typically in green). More...
 
QCPItemLine * mp_vEndTracerItem
 Vertical selection end tracer (typically in red). More...
 
std::size_t m_lastAxisRangeHistoryIndex = 0
 Index of the last axis range history item. More...
 
std::vector< QCPRange * > m_xAxisRangeHistory
 List of x axis ranges occurring during the panning zooming actions. More...
 
std::vector< QCPRange * > m_yAxisRangeHistory
 List of y axis ranges occurring during the panning zooming actions. More...
 
int m_mouseMoveHandlerSkipAmount = 10
 How many mouse move events must be skipped *‍/. More...
 
int m_mouseMoveHandlerSkipCount = 0
 Counter to handle the "fat data" mouse move event handling. More...
 
QColor m_unfocusedColor = QColor("lightgray")
 Color used for the background of unfocused plot. More...
 
QBrush m_unfocusedBrush = QBrush(m_unfocusedColor)
 Color used for the background of unfocused plot. More...
 
QColor m_focusedColor = QColor(Qt::transparent)
 Color used for the background of focused plot. More...
 
QBrush m_focusedBrush = QBrush(m_focusedColor)
 Color used for the background of focused plot. More...
 
QPen m_pen
 Pen used to draw the graph and textual elements in the plot widget. More...
 

Additional Inherited Members

- Signals inherited from pappso::BasePlotWidget
void setFocusSignal ()
 
void lastCursorHoveredPointSignal (const QPointF &pointf)
 
void plotRangesChangedSignal (const BasePlotContext &context)
 
void xAxisMeasurementSignal (const BasePlotContext &context, bool with_delta)
 
void keyPressEventSignal (const BasePlotContext &context)
 
void keyReleaseEventSignal (const BasePlotContext &context)
 
void mouseReleaseEventSignal (const BasePlotContext &context)
 
void plottableSelectionChangedSignal (QCPAbstractPlottable *plottable_p, bool selected)
 
void integrationRequestedSignal (const BasePlotContext &context)
 
void plottableDestructionRequestedSignal (BasePlotWidget *base_plot_widget_p, QCPAbstractPlottable *plottable_p, const BasePlotContext &context)
 

Detailed Description

Definition at line 61 of file basecolormapplotwidget.h.

Constructor & Destructor Documentation

◆ BaseColorMapPlotWidget()

pappso::BaseColorMapPlotWidget::BaseColorMapPlotWidget ( QWidget *  parent,
const QString &  x_axis_label,
const QString &  y_axis_label 
)
explicit

Definition at line 44 of file basecolormapplotwidget.cpp.

47  : BasePlotWidget(parent, x_axis_label, y_axis_label)
48 {
49 }

◆ ~BaseColorMapPlotWidget()

pappso::BaseColorMapPlotWidget::~BaseColorMapPlotWidget ( )
virtual

Destruct this BaseColorMapPlotWidget instance.

The destruction involves clearing the history, deleting all the axis range history items for x and y axes.

Definition at line 59 of file basecolormapplotwidget.cpp.

60 {
61 }

Member Function Documentation

◆ addColorMap()

QCPColorMap * pappso::BaseColorMapPlotWidget::addColorMap ( std::shared_ptr< std::map< double, MapTrace >>  double_map_trace_map_sp,
ColorMapPlotConfig  color_map_plot_config,
const QColor &  color 
)
virtual

Definition at line 80 of file basecolormapplotwidget.cpp.

84 {
85  // qDebug() << "Adding color map with config:" <<
86  // color_map_plot_config.toString();
87 
88  if(!color.isValid())
89  throw PappsoException(
90  QString("The color to be used for the plot graph is invalid."));
91 
92  QCPColorMap *color_map_p = new QCPColorMap(xAxis, yAxis);
93 
94  // Do not forget to copy the config!
95 
96  m_colorMapPlotConfig = color_map_plot_config;
97 
98 #if 0
99  // This is the code on the QCustomPlot documentation and it works fine.
100  QCPColorMap *color_map_p = new QCPColorMap(xAxis, yAxis);
101 
102  color_map_p->data()->setSize(50, 50);
103  color_map_p->data()->setRange(QCPRange(0, 2), QCPRange(0, 2));
104  for(int x = 0; x < 50; ++x)
105  for(int y = 0; y < 50; ++y)
106  color_map_p->data()->setCell(x, y, qCos(x / 10.0) + qSin(y / 10.0));
107  color_map_p->setGradient(QCPColorGradient::gpPolar);
108  color_map_p->rescaleDataRange(true);
109  rescaleAxes();
110  replot();
111 #endif
112 
113  // Connect the signal of selection change so that we can re-emit it for the
114  // widget that is using *this widget.
115 
116  connect(color_map_p,
117  static_cast<void (QCPAbstractPlottable::*)(bool)>(
118  &QCPAbstractPlottable::selectionChanged),
119  [this, color_map_p]() {
120  emit plottableSelectionChangedSignal(color_map_p,
121  color_map_p->selected());
122  });
123 
124  // qDebug() << "Configuring the color map with this config:"
125  //<< color_map_plot_config.toString();
126 
127  color_map_p->data()->setSize(color_map_plot_config.keyCellCount,
128  color_map_plot_config.mzCellCount);
129 
130  color_map_p->data()->setRange(QCPRange(color_map_plot_config.minKeyValue,
131  color_map_plot_config.maxKeyValue),
132  QCPRange(color_map_plot_config.minMzValue,
133  color_map_plot_config.maxMzValue));
134  color_map_p->data()->fill(0.0);
135 
136  // We have now to fill the color map.
137 
138  for(auto &&pair : *double_map_trace_map_sp)
139  {
140 
141  // The first value is the key and the second value is the MapTrace into
142  // which we need to iterated and for each point (double mz, double
143  // intensity) create a map cell.
144 
145  double dt_or_rt_key = pair.first;
146  MapTrace map_trace = pair.second;
147 
148  for(auto &&data_point_pair : map_trace)
149  {
150  double mz = data_point_pair.first;
151  double intensity = data_point_pair.second;
152 
153  // We are filling dynamically the color map. If a cell had already
154  // something in, then we need to take that into account. This is
155  // because we let QCustomPlot handle the fuzzy transition between
156  // color map plot cells.
157 
158  double prev_intensity = color_map_p->data()->data(dt_or_rt_key, mz);
159 
160  // qDebug() << "Setting tri-point:" << dt_or_rt_key << "," << mz <<
161  // ","
162  //<< prev_intensity + intensity;
163 
164  color_map_p->data()->setData(
165  dt_or_rt_key, mz, prev_intensity + intensity);
166  }
167  }
168 
169  // At this point we have finished filling-up the color map.
170 
171  // The gpThermal is certainly one of the best.
172 
173  color_map_p->setGradient(QCPColorGradient::gpThermal);
174 
175  color_map_p->rescaleDataRange(true);
176 
177  color_map_p->rescaleAxes();
179 
180  // The pen of the color map itself is of no use. Instead the user will see the
181  // color of the axes' labels.
182 
183  QPen pen = xAxis->basePen();
184  pen.setColor(color);
185 
186  xAxis->setBasePen(pen);
187  xAxis->setLabelColor(color);
188  xAxis->setTickLabelColor(color);
189 
190  yAxis->setBasePen(pen);
191  yAxis->setLabelColor(color);
192  yAxis->setTickLabelColor(color);
193 
194  // And now set the color map's pen to the same color, even if we do not use
195  // it, we need it for coloring the plots that might be integrated from this
196  // color map.
197 
198  color_map_p->setPen(pen);
199 
200  replot();
201 
202  return color_map_p;
203 }

References pappso::ColorMapPlotConfig::keyCellCount, m_colorMapPlotConfig, pappso::ColorMapPlotConfig::maxKeyValue, pappso::ColorMapPlotConfig::maxMzValue, pappso::ColorMapPlotConfig::minKeyValue, pappso::ColorMapPlotConfig::minMzValue, pappso::mz, pappso::ColorMapPlotConfig::mzCellCount, pappso::BasePlotWidget::plottableSelectionChangedSignal(), pappso::BasePlotWidget::resetAxesRangeHistory(), pappso::x, and pappso::y.

◆ getColorMapPlotConfig()

const ColorMapPlotConfig & pappso::BaseColorMapPlotWidget::getColorMapPlotConfig ( )
virtual

Definition at line 73 of file basecolormapplotwidget.cpp.

74 {
75  return m_colorMapPlotConfig;
76 }

References m_colorMapPlotConfig.

◆ getPlottingColor()

QColor pappso::BaseColorMapPlotWidget::getPlottingColor ( int  index = 0) const
overridevirtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 325 of file basecolormapplotwidget.cpp.

326 {
327  Q_UNUSED(index);
328 
329  QPen pen = xAxis->basePen();
330  return pen.color();
331 }

◆ setColorMapPlotConfig()

void pappso::BaseColorMapPlotWidget::setColorMapPlotConfig ( const ColorMapPlotConfig color_map_config)
virtual

Definition at line 65 of file basecolormapplotwidget.cpp.

67 {
68  m_colorMapPlotConfig = color_map_config;
69 }

References m_colorMapPlotConfig.

◆ setPlottingColor()

void pappso::BaseColorMapPlotWidget::setPlottingColor ( QCPAbstractPlottable *  plottable_p,
const QColor &  new_color 
)
overridevirtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 293 of file basecolormapplotwidget.cpp.

295 {
296  Q_UNUSED(plottable_p);
297 
298  // The pen of the color map itself is of no use. Instead the user will see the
299  // color of the axes' labels.
300 
301  QPen pen = xAxis->basePen();
302  pen.setColor(new_color);
303 
304  xAxis->setBasePen(pen);
305  xAxis->setLabelColor(new_color);
306  xAxis->setTickLabelColor(new_color);
307 
308  yAxis->setBasePen(pen);
309  yAxis->setLabelColor(new_color);
310  yAxis->setTickLabelColor(new_color);
311 
312  // And now set the color map's pen to the same color, even if we do not use
313  // it, we need it for coloring the plots that might be integrated from this
314  // color map.
315 
316  QCPColorMap *color_map_p = static_cast<QCPColorMap *>(plottable(0));
317 
318  color_map_p->setPen(pen);
319 
320  replot();
321 }

◆ transposeAxes()

void pappso::BaseColorMapPlotWidget::transposeAxes ( )
virtual

Definition at line 207 of file basecolormapplotwidget.cpp.

208 {
209  // qDebug() << __FILE__ << __LINE__ << __FUNCTION__ << "()" ;
210 
211  QCPColorMap *color_map_p = static_cast<QCPColorMap *>(plottable(0));
212 
213  QCPColorMapData *origData = color_map_p->data();
214 
215  int keySize = origData->keySize();
216  int valueSize = origData->valueSize();
217 
218  // qDebug() << __FILE__ << __LINE__ << __FUNCTION__ << "()"
219  //<< "Orig data size:" << keySize << valueSize;
220 
221  QCPRange keyRange = origData->keyRange();
222  QCPRange valueRange = origData->valueRange();
223 
224  // qDebug() << __FILE__ << __LINE__ << __FUNCTION__ << "()"
225  //<< "Value at cell 80,650:" << origData->cell(80,650);
226 
227  // Transposed map.
228  QCPColorMapData *newData =
229  new QCPColorMapData(valueSize, keySize, valueRange, keyRange);
230 
231  for(int iter = 0; iter < keySize; ++iter)
232  {
233  for(int jter = 0; jter < valueSize; ++jter)
234  {
235  double cellData = origData->cell(iter, jter);
236 
237  newData->setCell(jter, iter, cellData);
238  }
239  }
240 
241  // qDebug() << __FILE__ << __LINE__ << __FUNCTION__ << "()"
242  //<< "New data size:" << newData->keySize() << newData->valueSize();
243 
244  // At this point the transposition has been done.
245 
246  color_map_p->data()->clear();
247  color_map_p->rescaleDataRange(true);
248 
249  // Now we need to invert the labels and data kinds.
250 
253  m_colorMapPlotConfig.yAxisDataKind = temp_data_kind;
254 
255  QString temp_axis_label = xAxis->label();
256  xAxis->setLabel(yAxis->label());
257  yAxis->setLabel(temp_axis_label);
258 
259  // Will take ownership of the newData.
260  color_map_p->setData(newData);
261 
262  // qDebug() << __FILE__ << __LINE__ << __FUNCTION__ << "()"
263  //<< "Value at cell 80,650:" << newData->cell(80,650)
264  //<< "Value at cell 650, 80:" << newData->cell(650,80);
265 
266  // QCPAxis *p_keyAxis = mp_colorMap->keyAxis();
267  // QCPAxis *p_valueAxis = mp_colorMap->valueAxis();
268 
269  // mp_colorMap->setKeyAxis(p_valueAxis);
270  // mp_colorMap->setValueAxis(p_keyAxis);
271 
272  color_map_p->rescaleAxes();
273 
274  replot();
275 }

References m_colorMapPlotConfig, pappso::ColorMapPlotConfig::xAxisDataKind, and pappso::ColorMapPlotConfig::yAxisDataKind.

◆ xAxisDataKind()

DataKind pappso::BaseColorMapPlotWidget::xAxisDataKind ( ) const

◆ yAxisDataKind()

DataKind pappso::BaseColorMapPlotWidget::yAxisDataKind ( ) const

Member Data Documentation

◆ m_colorMapPlotConfig

ColorMapPlotConfig pappso::BaseColorMapPlotWidget::m_colorMapPlotConfig
protected

The documentation for this class was generated from the following files:
pappso::ColorMapPlotConfig::yAxisDataKind
DataKind yAxisDataKind
Definition: colormapplotconfig.h:24
pappso::BasePlotWidget::BasePlotWidget
BasePlotWidget(QWidget *parent)
Definition: baseplotwidget.cpp:114
pappso::DataKind
DataKind
Definition: types.h:192
pappso::PeptideIonCter::y
@ y
pappso::ColorMapPlotConfig::xAxisDataKind
DataKind xAxisDataKind
Definition: colormapplotconfig.h:23
pappso::PeptideIonCter::x
@ x
pappso::BasePlotWidget::plottableSelectionChangedSignal
void plottableSelectionChangedSignal(QCPAbstractPlottable *plottable_p, bool selected)
pappso::BasePlotWidget::resetAxesRangeHistory
virtual void resetAxesRangeHistory()
Definition: baseplotwidget.cpp:366
pappso::PrecisionUnit::mz
@ mz
pappso::BaseColorMapPlotWidget::m_colorMapPlotConfig
ColorMapPlotConfig m_colorMapPlotConfig
Definition: basecolormapplotwidget.h:94