Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
DlgSettingsGeneral.cpp
1 #include "CmdMediator.h"
2 #include "CmdSettingsGeneral.h"
3 #include "DlgSettingsGeneral.h"
4 #include "EngaugeAssert.h"
5 #include "Logger.h"
6 #include "MainWindow.h"
7 #include <QComboBox>
8 #include <QGraphicsScene>
9 #include <QGridLayout>
10 #include <QGroupBox>
11 #include <QLabel>
12 #include <qmath.h>
13 #include <QPushButton>
14 #include <QSettings>
15 #include <QSpinBox>
16 #include "Settings.h"
17 
19  DlgSettingsAbstractBase ("General",
20  "DlgSettingsGeneral",
21  mainWindow),
22  m_modelGeneralBefore (0),
23  m_modelGeneralAfter (0)
24 {
25  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::DlgSettingsGeneral";
26 
27  QWidget *subPanel = createSubPanel ();
28  finishPanel (subPanel);
29 }
30 
31 DlgSettingsGeneral::~DlgSettingsGeneral()
32 {
33  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::~DlgSettingsGeneral";
34 }
35 
36 void DlgSettingsGeneral::createControls (QGridLayout *layout,
37  int &row)
38 {
39  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::createControls";
40 
41  QLabel *labelCursorSize = new QLabel ("Cursor size (pixels):");
42  layout->addWidget (labelCursorSize, row, 1);
43 
44  m_spinCursorSize = new QSpinBox;
45  m_spinCursorSize->setMinimum (1);
46  m_spinCursorSize->setWhatsThis (tr ("Effective Cursor Size\n\n"
47  "This is the effective width and height of the cursor when clicking on a pixel that is "
48  "not part of the background.\n\n"
49  "This parameter is used in the Color Picker and Point Match modes"));
50  connect (m_spinCursorSize, SIGNAL (valueChanged (int)), this, SLOT (slotCursorSize (int)));
51  layout->addWidget (m_spinCursorSize, row++, 2);
52 
53  QLabel *labelExtraPrecision = new QLabel ("Extra precision (digits):");
54  layout->addWidget (labelExtraPrecision, row, 1);
55 
56  m_spinExtraPrecision = new QSpinBox;
57  m_spinExtraPrecision->setMinimum (0);
58  m_spinExtraPrecision->setWhatsThis (tr ("Extra Digits of Precision\n\n"
59  "This is the number of additional digits of precision appended after the significant "
60  "digits determined by the digitization accuracy at that point. The digitization accuracy "
61  "at any point equals the change in graph coordinates from moving one pixel in each direction. "
62  "Appending extra digits does not improve the accuracy of the numbers. More information can "
63  "be found in discussions of accuracy versus precision.\n\n"
64  "This parameter is used on the coordinates in the Status Bar and during Export"));
65  connect (m_spinExtraPrecision, SIGNAL (valueChanged (int)), this, SLOT (slotExtraPrecision (int)));
66  layout->addWidget (m_spinExtraPrecision, row++, 2);
67 }
68 
70 {
71  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::createOptionalSaveDefault";
72 
73  m_btnSaveDefault = new QPushButton ("Save As Default");
74  m_btnSaveDefault->setWhatsThis (tr ("Save the settings for use as future defaults, according to the curve name selection."));
75  connect (m_btnSaveDefault, SIGNAL (released ()), this, SLOT (slotSaveDefault ()));
76  layout->addWidget (m_btnSaveDefault, 0, Qt::AlignLeft);
77 }
78 
80 {
81  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::createSubPanel";
82 
83  QWidget *subPanel = new QWidget ();
84  QGridLayout *layout = new QGridLayout (subPanel);
85  subPanel->setLayout (layout);
86 
87  layout->setColumnStretch(0, 1); // Empty first column
88  layout->setColumnStretch(1, 0); // Labels
89  layout->setColumnStretch(2, 0); // Values
90  layout->setColumnStretch(3, 1); // Empty first column
91 
92  int row = 0;
93  createControls (layout, row);
94 
95  return subPanel;
96 }
97 
99 {
100  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::handleOk";
101 
103  cmdMediator ().document(),
104  *m_modelGeneralBefore,
105  *m_modelGeneralAfter);
106  cmdMediator ().push (cmd);
107 
108  hide ();
109 }
110 
112 {
113  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::load";
114 
115  setCmdMediator (cmdMediator);
116 
117  // Flush old data
118  if (m_modelGeneralBefore != 0) {
119  delete m_modelGeneralBefore;
120  }
121  if (m_modelGeneralAfter != 0) {
122  delete m_modelGeneralAfter;
123  }
124 
125  // Save new data
126  m_modelGeneralBefore = new DocumentModelGeneral (cmdMediator.document());
127  m_modelGeneralAfter = new DocumentModelGeneral (cmdMediator.document());
128 
129  // Populate controls
130  m_spinCursorSize->setValue (m_modelGeneralAfter->cursorSize());
131  m_spinExtraPrecision->setValue (m_modelGeneralAfter->extraPrecision());
132 
133  updateControls ();
134  enableOk (false); // Disable Ok button since there not yet any changes
135 }
136 
137 void DlgSettingsGeneral::slotCursorSize (int cursorSize)
138 {
139  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::slotCursorSize";
140 
141  m_modelGeneralAfter->setCursorSize (cursorSize);
142  updateControls();
143 }
144 
145 void DlgSettingsGeneral::slotExtraPrecision (int extraPrecision)
146 {
147  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::slotExtraPrecision";
148 
149  m_modelGeneralAfter->setExtraPrecision (extraPrecision);
150  updateControls();
151 }
152 
153 void DlgSettingsGeneral::slotSaveDefault()
154 {
155  LOG4CPP_INFO_S ((*mainCat)) << "DlgSettingsGeneral::slotSaveDefault";
156 
157  QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
158  settings.beginGroup (SETTINGS_GROUP_GENERAL);
159 
160  settings.setValue (SETTINGS_GENERAL_CURSOR_SIZE,
161  m_modelGeneralAfter->cursorSize());
162  settings.setValue (SETTINGS_GENERAL_EXTRA_PRECISION,
163  m_modelGeneralAfter->extraPrecision());
164  settings.endGroup ();
165 }
166 
167 void DlgSettingsGeneral::updateControls ()
168 {
169  enableOk (true);
170 }
Model for DlgSettingsGeneral and CmdSettingsGeneral.
void setCursorSize(int cursorSize)
Set method for effective cursor size.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
int cursorSize() const
Get method for effective cursor size.
virtual void handleOk()
Process slotOk.
DlgSettingsGeneral(MainWindow &mainWindow)
Single constructor.
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:61
Command for DlgSettingsGeneral.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
void finishPanel(QWidget *subPanel)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
Command queue stack.
Definition: CmdMediator.h:16
Abstract base class for all Settings dialogs.
int extraPrecision() const
Get method for extra digits of precsion.
void setExtraPrecision(int extraPrecision)
Set method for extra digits of precision.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
MainWindow & mainWindow()
Get method for MainWindow.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:66
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.