Engauge Digitizer  2
BackgroundStateCurve.cpp
Go to the documentation of this file.
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
8 #include "BackgroundStateCurve.h"
11 #include "FilterImage.h"
12 #include "GraphicsScene.h"
13 #include "GraphicsView.h"
14 #include "Logger.h"
15 #include <QPixmap>
16 #include "Transformation.h"
17 
19  GraphicsScene &scene) :
21  scene)
22 {
23 }
24 
26 {
27  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::begin";
28 
29  setImageVisible (true);
30 }
31 
33 {
34  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::end";
35 
36  setImageVisible (false);
37 }
38 
40 {
41  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::fitInView";
42 
43  view.fitInView (imageItem ().boundingRect());
44 }
45 
46 void BackgroundStateCurve::processImageFromSavedInputs (bool isGnuplot,
47  const Transformation &transformation,
48  const DocumentModelGridRemoval &modelGridRemoval,
49  const DocumentModelColorFilter &modelColorFilter,
50  const QString &curveSelected)
51 {
52  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::processImageFromSavedInputs";
53 
54  // Use the settings if the selected curve is known
55  if (!curveSelected.isEmpty()) {
56 
57  // Generate filtered image
58  FilterImage filterImage;
59  QPixmap pixmapFiltered = filterImage.filter (isGnuplot,
60  m_pixmapOriginal.toImage(),
61  transformation,
62  curveSelected,
63  modelColorFilter,
64  modelGridRemoval);
65 
66  setProcessedPixmap (pixmapFiltered);
67 
68  } else {
69 
70  // Set the image in case BackgroundStateContext::fitInView is called, so the bounding rect is available
71  setProcessedPixmap (m_pixmapOriginal);
72 
73  }
74 }
75 
76 void BackgroundStateCurve::setCurveSelected (bool isGnuplot,
77  const Transformation &transformation,
78  const DocumentModelGridRemoval &modelGridRemoval,
79  const DocumentModelColorFilter &modelColorFilter,
80  const QString &curveSelected)
81 {
82  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::setCurveSelected"
83  << " curve=" << curveSelected.toLatin1().data();
84 
85  // Even if m_curveSelected equals curveSelected we update the image, since the transformation
86  // may have changed
87  processImageFromSavedInputs (isGnuplot,
88  transformation,
89  modelGridRemoval,
90  modelColorFilter,
91  curveSelected);
92 }
93 
94 void BackgroundStateCurve::setPixmap (bool isGnuplot,
95  const Transformation &transformation,
96  const DocumentModelGridRemoval &modelGridRemoval,
97  const DocumentModelColorFilter &modelColorFilter,
98  const QPixmap &pixmapOriginal,
99  const QString &curveSelected)
100 {
101  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::setPixmap";
102 
103  m_pixmapOriginal = pixmapOriginal;
104  processImageFromSavedInputs (isGnuplot,
105  transformation,
106  modelGridRemoval,
107  modelColorFilter,
108  curveSelected);
109 }
110 
111 QString BackgroundStateCurve::state () const
112 {
113  return "BackgroundStateCurve";
114 }
115 
116 void BackgroundStateCurve::updateColorFilter (bool isGnuplot,
117  const Transformation &transformation,
118  const DocumentModelGridRemoval &modelGridRemoval,
119  const DocumentModelColorFilter &modelColorFilter,
120  const QString &curveSelected)
121 {
122  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::updateColorFilter";
123 
124  processImageFromSavedInputs (isGnuplot,
125  transformation,
126  modelGridRemoval,
127  modelColorFilter,
128  curveSelected);
129 }
FilterImage.h
FilterImage
Filters an image using a combination of color filtering and grid removal.
Definition: FilterImage.h:17
FilterImage::filter
QPixmap filter(bool isGnuplot, const QImage &imageUnfiltered, const Transformation &transformation, const QString &curveSelected, const DocumentModelColorFilter &modelColorFilter, const DocumentModelGridRemoval &modelGridRemoval) const
Filter original unfiltered image into filtered pixmap.
Definition: FilterImage.cpp:21
BackgroundStateCurve::updateColorFilter
virtual void updateColorFilter(bool isGnuplot, const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &colorFilter, const QString &curveSelected)
Apply color filter settings.
Definition: BackgroundStateCurve.cpp:115
DocumentModelGridRemoval.h
BackgroundStateCurve::end
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
Definition: BackgroundStateCurve.cpp:31
BackgroundStateCurve::setCurveSelected
virtual void setCurveSelected(bool isGnuplot, const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &colorFilter, const QString &curveSelected)
Update the currently selected curve name.
Definition: BackgroundStateCurve.cpp:75
BackgroundStateAbstractBase::setImageVisible
void setImageVisible(bool visible)
Show/hide background image.
Definition: BackgroundStateAbstractBase.cpp:64
Transformation
Affine transformation between screen and graph coordinates, based on digitized axis points.
Definition: Transformation.h:30
BackgroundStateCurve.h
BackgroundStateCurve::state
virtual QString state() const
State name for debugging.
Definition: BackgroundStateCurve.cpp:110
DocumentModelColorFilter
Model for DlgSettingsColorFilter and CmdSettingsColorFilter.
Definition: DocumentModelColorFilter.h:20
BackgroundStateAbstractBase::imageItem
QGraphicsPixmapItem & imageItem() const
Graphics image item for the current state.
Definition: BackgroundStateAbstractBase.cpp:49
BackgroundStateAbstractBase
Background image state machine state base class.
Definition: BackgroundStateAbstractBase.h:29
GraphicsView
QGraphicsView class with event handling added. Typically the events are sent to the active digitizing...
Definition: GraphicsView.h:19
Transformation.h
Logger.h
BackgroundStateCurve::BackgroundStateCurve
BackgroundStateCurve(BackgroundStateContext &context, GraphicsScene &scene)
Single constructor.
Definition: BackgroundStateCurve.cpp:17
BackgroundStateContext.h
LOG4CPP_INFO_S
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
GraphicsScene
Add point and line handling to generic QGraphicsScene.
Definition: GraphicsScene.h:35
BackgroundStateAbstractBase::setProcessedPixmap
void setProcessedPixmap(const QPixmap &pixmap)
Save the image for this state after it has been processed by the leaf class.
Definition: BackgroundStateAbstractBase.cpp:69
mainCat
log4cpp::Category * mainCat
Definition: Logger.cpp:14
GraphicsScene.h
BackgroundStateCurve::begin
virtual void begin()
Method that is called at the exact moment a state is entered. Typically called just after end for the...
Definition: BackgroundStateCurve.cpp:24
DocumentModelGridRemoval
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...
Definition: DocumentModelGridRemoval.h:16
DocumentModelColorFilter.h
BackgroundStateContext
Context class that manages the background image state machine.
Definition: BackgroundStateContext.h:31
BackgroundStateCurve::fitInView
virtual void fitInView(GraphicsView &view)
Zoom so background fills the window.
Definition: BackgroundStateCurve.cpp:38
BackgroundStateCurve::setPixmap
virtual void setPixmap(bool isGnuplot, const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &modelColorFilter, const QPixmap &pixmapOriginal, const QString &curveSelected)
Update the image for this state, after the leaf class processes it appropriately.
Definition: BackgroundStateCurve.cpp:93
GraphicsView.h