Typica is a free program for professional coffee roasters. https://typica.us
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

graphsettings.w 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. @<GraphSettingsWidget implementation@>=
  21. GraphSettingsWidget::GraphSettingsWidget() : QWidget(NULL)
  22. {
  23. QTabWidget *graphCategories = new QTabWidget;
  24. GraphSettingsRelativeTab *relative = new GraphSettingsRelativeTab;
  25. graphCategories->addTab(relative, tr("Relative Temperatures"));
  26. QVBoxLayout *layout = new QVBoxLayout;
  27. layout->addWidget(graphCategories);
  28. setLayout(layout);
  29. }
  30. @ Relative temperature measurements are different from the absolute temperature
  31. measurements that fall on the primary axis in that it is likely that negative
  32. values will be presented. These may be important and should not be hidden off
  33. the bottom of the graph, but the most important values will be in a relatively
  34. small range of positive values. The particulars will depend on the settings
  35. used to construct the relative values and the style of coffee roasting. It is
  36. also possible to disable the graphing of relative temperature measurements.
  37. @<Class declarations@>=
  38. class GraphSettingsRelativeTab : public QWidget
  39. {
  40. Q_OBJECT
  41. public:
  42. GraphSettingsRelativeTab();
  43. public slots:
  44. void updateEnableSetting(bool enable);
  45. void updateColorSetting(const QString &color);
  46. void updateAxisSetting(const QString &gridList);
  47. void updateUnit(int unit);
  48. void showColorPicker();
  49. private:
  50. QLineEdit *colorEdit;
  51. };
  52. @ The constructor sets up the interface and restores any previous values from
  53. settings.
  54. @<GraphSettingsWidget implementation@>=
  55. GraphSettingsRelativeTab::GraphSettingsRelativeTab() : QWidget(NULL),
  56. colorEdit(new QLineEdit)
  57. {
  58. QSettings settings;
  59. QVBoxLayout *layout = new QVBoxLayout;
  60. QCheckBox *enable = new QCheckBox(tr("Graph relative temperatures"));
  61. enable->setChecked(settings.value("settings/graph/relative/enable", true).toBool());
  62. updateEnableSetting(enable->isChecked());
  63. connect(enable, SIGNAL(toggled(bool)), this, SLOT(updateEnableSetting(bool)));
  64. layout->addWidget(enable);
  65. QHBoxLayout *colorLayout = new QHBoxLayout;
  66. QLabel *colorLabel = new QLabel(tr("Axis color:"));
  67. colorEdit->setText(settings.value("settings/graph/relative/color", "#000000").toString());
  68. updateColorSetting(colorEdit->text());
  69. connect(colorEdit, SIGNAL(textChanged(QString)), this, SLOT(updateColorSetting(QString)));
  70. QToolButton *colorPickerButton = new QToolButton();
  71. colorPickerButton->setIcon(QIcon::fromTheme("applications-graphics"));
  72. connect(colorPickerButton, SIGNAL(clicked()), this, SLOT(showColorPicker()));
  73. colorLayout->addWidget(colorLabel);
  74. colorLayout->addWidget(colorEdit);
  75. colorLayout->addWidget(colorPickerButton);
  76. colorLayout->addStretch();
  77. layout->addLayout(colorLayout);
  78. QHBoxLayout *unitLayout = new QHBoxLayout;
  79. QLabel *unitLabel = new QLabel(tr("Unit"));
  80. QComboBox *unitSelector = new QComboBox;
  81. unitSelector->addItem(tr("Fahrenheit"));
  82. unitSelector->addItem(tr("Celsius"));
  83. unitSelector->setCurrentIndex(settings.value("settings/graph/relative/unit", 0).toInt());
  84. updateUnit(unitSelector->currentIndex());
  85. connect(unitSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUnit(int)));
  86. unitLayout->addWidget(unitLabel);
  87. unitLayout->addWidget(unitSelector);
  88. unitLayout->addStretch();
  89. layout->addLayout(unitLayout);
  90. QHBoxLayout *axisLayout = new QHBoxLayout;
  91. QLabel *axisLabel = new QLabel(tr("Grid line positions (comma separated):"));
  92. QLineEdit *axisEdit = new QLineEdit;
  93. axisEdit->setText(settings.value("settings/graph/relative/grid", "-300, -100, -10, 0, 10, 30, 50").toString());
  94. updateAxisSetting(axisEdit->text());
  95. connect(axisEdit, SIGNAL(textChanged(QString)), this, SLOT(updateAxisSetting(QString)));
  96. axisLayout->addWidget(axisLabel);
  97. axisLayout->addWidget(axisEdit);
  98. layout->addLayout(axisLayout);
  99. layout->addStretch();
  100. setLayout(layout);
  101. }
  102. @ A set of methods updates the settings as they are adjusted.
  103. @<GraphSettingsWidget implementation@>=
  104. void GraphSettingsRelativeTab::updateEnableSetting(bool enabled)
  105. {
  106. QSettings settings;
  107. settings.setValue("settings/graph/relative/enable", enabled);
  108. }
  109. void GraphSettingsRelativeTab::updateColorSetting(const QString &color)
  110. {
  111. QSettings settings;
  112. settings.setValue("settings/graph/relative/color", color);
  113. }
  114. void GraphSettingsRelativeTab::updateAxisSetting(const QString &gridList)
  115. {
  116. QSettings settings;
  117. QString settingValue;
  118. QStringList points = gridList.split(QRegExp("[\\s,]+"), QString::SkipEmptyParts);
  119. QStringList numbers;
  120. foreach(QString text, points)
  121. {
  122. bool okay = false;
  123. text.toDouble(&okay);
  124. if(okay)
  125. {
  126. numbers.append(text);
  127. }
  128. }
  129. numbers.removeDuplicates();
  130. settings.setValue("settings/graph/relative/grid", numbers.join(","));
  131. }
  132. void GraphSettingsRelativeTab::updateUnit(int unit)
  133. {
  134. QSettings settings;
  135. settings.setValue("settings/graph/relative/unit", unit);
  136. }
  137. @ When selecting a color, it is possible to either type the color into the line
  138. edit directly or use a color picker to select the color graphically. A tool
  139. button displays a color picker and pushes the selected color into the line edit
  140. which in turn updates the setting.
  141. @<GraphSettingsWidget implementation@>=
  142. void GraphSettingsRelativeTab::showColorPicker()
  143. {
  144. QColor color = QColorDialog::getColor(QColor(colorEdit->text()), this);
  145. colorEdit->setText(color.name());
  146. }