Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. @* Graph widget configuration.
  2. \noindent There are many features of the graph in Typica which ought to be
  3. configurable. Most of these cannot be configured until changes are made to the
  4. graph widget. The original motivation for the class comes from a need to
  5. configure secondary axes.
  6. @<Class declarations@>=
  7. class GraphSettingsWidget : public QWidget@/
  8. {@/
  9. @[Q_OBJECT@]@;
  10. public:@/
  11. GraphSettingsWidget();
  12. };
  13. @ At present there are three types of data that the graph might present. This
  14. will likely be expanded as support for additional unit types are added.
  15. Different measurement categories are presently organized into different tabs.
  16. This will potentially need to change later as more features are added and the
  17. tab set becomes excessively large but for now this is the best that I can
  18. think of. If anybody with UI design experience would like to propose something
  19. better I would be glad to consider it.
  20. @s GraphSettingsRelativeTab int
  21. @<GraphSettingsWidget implementation@>=
  22. GraphSettingsWidget::GraphSettingsWidget() : QWidget(NULL)
  23. {
  24. QTabWidget *graphCategories = new QTabWidget;
  25. GraphSettingsRelativeTab *relative = new GraphSettingsRelativeTab;
  26. graphCategories->addTab(relative, tr("Relative Temperatures"));
  27. QVBoxLayout *layout = new QVBoxLayout;
  28. layout->addWidget(graphCategories);
  29. setLayout(layout);
  30. }
  31. @ Relative temperature measurements are different from the absolute temperature
  32. measurements that fall on the primary axis in that it is likely that negative
  33. values will be presented. These may be important and should not be hidden off
  34. the bottom of the graph, but the most important values will be in a relatively
  35. small range of positive values. The particulars will depend on the settings
  36. used to construct the relative values and the style of coffee roasting. It is
  37. also possible to disable the graphing of relative temperature measurements.
  38. @<Class declarations@>=
  39. class GraphSettingsRelativeTab : public QWidget@/
  40. {@/
  41. @[Q_OBJECT@]@;
  42. public:@/
  43. GraphSettingsRelativeTab();@/
  44. @[public slots@]:@/
  45. void updateEnableSetting(bool enable);
  46. void updateColorSetting(const QString &color);
  47. void updateAxisSetting(const QString &gridList);
  48. void updateUnit(int unit);
  49. void showColorPicker();@/
  50. private:@/
  51. QLineEdit *colorEdit;
  52. };
  53. @ The constructor sets up the interface and restores any previous values from
  54. settings.
  55. The default grid line position has been updated since version 1.8 to match the
  56. number of grid lines present when viewing the graph in Fahrenheit and to
  57. present a slightly wider range where most measurements are expected.
  58. @<GraphSettingsWidget implementation@>=
  59. GraphSettingsRelativeTab::GraphSettingsRelativeTab() : QWidget(NULL),
  60. colorEdit(new QLineEdit)
  61. {
  62. QSettings settings;
  63. QVBoxLayout *layout = new QVBoxLayout;
  64. QCheckBox *enable = new QCheckBox(tr("Graph relative temperatures"));
  65. enable->setChecked(settings.value("settings/graph/relative/enable", true).toBool());
  66. updateEnableSetting(enable->isChecked());
  67. connect(enable, SIGNAL(toggled(bool)), this, SLOT(updateEnableSetting(bool)));
  68. layout->addWidget(enable);
  69. QHBoxLayout *colorLayout = new QHBoxLayout;
  70. QLabel *colorLabel = new QLabel(tr("Axis color:"));
  71. colorEdit->setText(settings.value("settings/graph/relative/color", "#000000").toString());
  72. updateColorSetting(colorEdit->text());
  73. connect(colorEdit, SIGNAL(textChanged(QString)), this, SLOT(updateColorSetting(QString)));
  74. QToolButton *colorPickerButton = new QToolButton();
  75. colorPickerButton->setIcon(QIcon::fromTheme("applications-graphics"));
  76. connect(colorPickerButton, SIGNAL(clicked()), this, SLOT(showColorPicker()));
  77. colorLayout->addWidget(colorLabel);
  78. colorLayout->addWidget(colorEdit);
  79. colorLayout->addWidget(colorPickerButton);
  80. colorLayout->addStretch();
  81. layout->addLayout(colorLayout);
  82. QHBoxLayout *unitLayout = new QHBoxLayout;
  83. QLabel *unitLabel = new QLabel(tr("Unit"));
  84. QComboBox *unitSelector = new QComboBox;
  85. unitSelector->addItem(tr("Fahrenheit"));
  86. unitSelector->addItem(tr("Celsius"));
  87. unitSelector->setCurrentIndex(settings.value("settings/graph/relative/unit", 0).toInt());
  88. updateUnit(unitSelector->currentIndex());
  89. connect(unitSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUnit(int)));
  90. unitLayout->addWidget(unitLabel);
  91. unitLayout->addWidget(unitSelector);
  92. unitLayout->addStretch();
  93. layout->addLayout(unitLayout);
  94. QHBoxLayout *axisLayout = new QHBoxLayout;
  95. QLabel *axisLabel = new QLabel(tr("Grid line positions (comma separated):"));
  96. QLineEdit *axisEdit = new QLineEdit;
  97. axisEdit->setText(settings.value("settings/graph/relative/grid", "-300, -100, 0, 30, 65, 100").toString());
  98. updateAxisSetting(axisEdit->text());
  99. connect(axisEdit, SIGNAL(textChanged(QString)), this, SLOT(updateAxisSetting(QString)));
  100. axisLayout->addWidget(axisLabel);
  101. axisLayout->addWidget(axisEdit);
  102. layout->addLayout(axisLayout);
  103. layout->addStretch();
  104. setLayout(layout);
  105. }
  106. @ A set of methods updates the settings as they are adjusted.
  107. @<GraphSettingsWidget implementation@>=
  108. void GraphSettingsRelativeTab::updateEnableSetting(bool enabled)
  109. {
  110. QSettings settings;
  111. settings.setValue("settings/graph/relative/enable", enabled);
  112. }
  113. void GraphSettingsRelativeTab::updateColorSetting(const QString &color)
  114. {
  115. QSettings settings;
  116. settings.setValue("settings/graph/relative/color", color);
  117. }
  118. void GraphSettingsRelativeTab::updateAxisSetting(const QString &gridList)
  119. {
  120. QSettings settings;
  121. QString settingValue;
  122. QStringList points = gridList.split(QRegExp("[\\s,]+"), QString::SkipEmptyParts);
  123. QStringList numbers;
  124. foreach(QString text, points)
  125. {
  126. bool okay = @[false@];
  127. text.toDouble(&okay);
  128. if(okay)
  129. {
  130. numbers.append(text);
  131. }
  132. }
  133. numbers.removeDuplicates();
  134. settings.setValue("settings/graph/relative/grid", numbers.join(","));
  135. }
  136. void GraphSettingsRelativeTab::updateUnit(int unit)
  137. {
  138. QSettings settings;
  139. settings.setValue("settings/graph/relative/unit", unit);
  140. }
  141. @ When selecting a color, it is possible to either type the color into the line
  142. edit directly or use a color picker to select the color graphically. A tool
  143. button displays a color picker and pushes the selected color into the line edit
  144. which in turn updates the setting.
  145. @<GraphSettingsWidget implementation@>=
  146. void GraphSettingsRelativeTab::showColorPicker()
  147. {
  148. QColor color = QColorDialog::getColor(QColor(colorEdit->text()), this);
  149. colorEdit->setText(color.name());
  150. }