Added more edit fields to the first recipe editor tab. Cleanup of RangedSlider is ready.

Fri, 01 Apr 2022 17:25:42 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 01 Apr 2022 17:25:42 +0200
changeset 100
d11a3e713e3b
parent 99
053c0578cf58
child 101
1d14d3bf2465

Added more edit fields to the first recipe editor tab. Cleanup of RangedSlider is ready.

src/EditRecipe.cpp file | annotate | diff | comparison | revisions
src/RangedSlider.cpp file | annotate | diff | comparison | revisions
src/RangedSlider.h file | annotate | diff | comparison | revisions
--- a/src/EditRecipe.cpp	Fri Apr 01 16:52:25 2022 +0200
+++ b/src/EditRecipe.cpp	Fri Apr 01 17:25:42 2022 +0200
@@ -40,6 +40,10 @@
     ui->color_methodEdit->addItem("Halberstadt");
     ui->color_methodEdit->addItem("Naudts");
 
+    ui->ibu_methodEdit->addItem("Tinseth");
+    ui->ibu_methodEdit->addItem("Rager");
+    ui->ibu_methodEdit->addItem("Daniels");
+
     if (id >= 0) {
 	query.prepare("SELECT * FROM recipes WHERE record = :recno");
 	query.bindValue(":recno", id);
@@ -47,24 +51,13 @@
 	query.next();
 
 	ui->lockedEdit->setChecked(query.value(2).toInt() ? true:false);
-	//  3 st_name
-	//  4 st_letter
-	//  5 st_guide
-	//  6 st_category
-	//  7 st_category_number
-	//  8 st_type
-	//  9 st_og_min
-	// 10 st_og_max
-	// 11 st_fg_min
-	// 12 st_fg_max
-	// 13 st_ibu_min
-	// 14 st_ibu_max
-	// 15 st_color_min
-	// 16 st_color_max
-	// 17 st_carb_min
-	// 18 st_carb_max
-	// 19 st_abv_min
-	// 20 st_abv_max
+	ui->st_nameEdit->setText(query.value(3).toString());
+	ui->st_groupEdit->setText(query.value(4).toString());
+	ui->st_guideEdit->setText(query.value(5).toString());
+	ui->st_catEdit->setText(query.value(6).toString());
+	ui->st_catnrEdit->setText(query.value(7).toString());
+	ui->st_typeEdit->setText(query.value(8).toString());
+
 	ui->nameEdit->setText(query.value(21).toString());
 	ui->notesEdit->setPlainText(query.value(22).toString());
 	ui->typeEdit->setCurrentIndex(query.value(23).toInt());
@@ -101,9 +94,20 @@
 
 	ui->color_methodEdit->setCurrentIndex(query.value(32).toInt());
 
-	// 33 est_ibu
-	// 34 ibu_method
-	// 35 est_carb
+	ui->est_ibuEdit->setValue(query.value(33).toDouble());
+        ui->est_ibuShow->setPrecision(0);
+        ui->est_ibuShow->setMarkerTextIsValue(true);
+        ui->est_ibuShow->setRange(query.value(13).toDouble(), query.value(14).toDouble());
+        ui->est_ibuShow->setValue(query.value(33).toDouble());
+
+	ui->ibu_methodEdit->setCurrentIndex(query.value(34).toInt());
+
+	ui->est_carbEdit->setValue(query.value(35).toDouble());
+        ui->est_carbShow->setPrecision(1);
+        ui->est_carbShow->setMarkerTextIsValue(true);
+        ui->est_carbShow->setRange(query.value(17).toDouble(), query.value(18).toDouble());
+        ui->est_carbShow->setValue(query.value(35).toDouble());
+
 	// 36 sparge_temp
 	// 37 sparge_ph
 	// 38 sparge_volume
@@ -167,12 +171,13 @@
     connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
     connect(ui->typeEdit, &QComboBox::currentTextChanged, this, &EditRecipe::is_changed);
     connect(ui->batch_sizeEdit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed);
-    connect(ui->boil_sizeEdit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed);
     connect(ui->boil_timeEdit, &QSpinBox::textChanged, this, &EditRecipe::is_changed);
     connect(ui->efficiencyEdit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed);
 
     connect(ui->color_methodEdit, &QComboBox::currentTextChanged, this, &EditRecipe::is_changed);
 
+    connect(ui->ibu_methodEdit, &QComboBox::currentTextChanged, this, &EditRecipe::is_changed);
+
     ui->saveButton->setEnabled(false);
     ui->deleteButton->setEnabled((id >= 0) ? true:false);
 }
--- a/src/RangedSlider.cpp	Fri Apr 01 16:52:25 2022 +0200
+++ b/src/RangedSlider.cpp	Fri Apr 01 17:25:42 2022 +0200
@@ -53,22 +53,21 @@
     _markerTextIsValue(false),
     indicatorTextFont("Arial", 10, QFont::Normal) // Previously we just did the indicator text in 'default' font
 {
-    // Ensure this->heightInPixels is properly initialised
-//    this->recalculateHeightInPixels();
+    // Fixed minimum size.
+    this->setMinimumSize(60, 20);
+    this->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
 
-   // In principle we want to set our min/max sizes etc here.  However, if, say, a maximumSize property has been set
-   // for this object in a Designer UI File (eg ui/mainWindow.ui) then that setting will override this one, because it
-   // will be applied later (in fact pretty much straight after this constructor returns).  So we also make this call
-   // inside setValue(), which will be invoked _after_ the setter calls that were auto-generated from the Designer UI
-   // File.
-   this->setSizes();
+    // There no particular reason to limit our horizontal size, so, in principle, this call asks that there be no such
+    // (practical) limit.
+    this->setMaximumWidth(QWIDGETSIZE_MAX);
 
-   // Generate mouse move events whenever mouse movers over widget.
-   this->setMouseTracking(true);
+    // Generate mouse move events whenever mouse movers over widget.
+    this->setMouseTracking(true);
 
-   this->repaint();
+    this->repaint();
 }
 
+
 /**
  * @brief Set the normal limits in the _prexXxx values and calculate
  *        the real drawing limits so that we can see if a value is slightly
@@ -110,9 +109,6 @@
     }
 
     update();
-
-    // See comment in constructor for why we call this here
-    //this->setSizes();
     return;
 }
 
@@ -150,73 +146,6 @@
 }
 
 
-void RangedSlider::recalculateHeightInPixels() const {
-   //
-   // We need to be able to tell Qt about our minimum and preferred size in pixels.  This is something that's going
-   // to depend on the dots-per-inch (DPI) resolution of the monitor we're being displayed on.  Advice at
-   // https://doc.qt.io/qt-5/highdpi.html is that, for best High DPI display support, we should replace hard-coded
-   // sizes in layouts and drawing code with values calculated from font metrics or screen size.  For this widget, we
-   // use font sizes (as described in more detail later in this comment) as it seems simpler and the height of the
-   // widget really is determined by the size of the text it contains.
-   //
-   // In theory, someone might be running the app on a system with multiple screens with different DPI resolutions,
-   // so, in principle we ought to do redo size calculations every time the widget is moved, in case it moves from one
-   // screen to another and the resolution changes.  In practice, I'm not sure how big a requirement this is.  So, for
-   // now, have just tried to organise things so that it would, in principle, be possible to implement such behaviour
-   // in future.
-   //
-   // We want height to be fixed, as the slider does not get more readable if you make it taller.  So minimum and
-   // preferred height are the same.
-   //
-   // For width, We are OK for them to expand and contract horizontally, within reason, as the size of the main window
-   // changes.  Minimum and preferred widths are a bit of a rule-of-thumb, but 2× and 4× height are a sensible stab.
-   //
-   // Firstly we have to determine what the fixed height is.  We could query the DPI resolution and size of the current
-   // screen, but the simplest thing is to use font sizes.  The slider is basically two lines of characters high.  Top
-   // line is the "indicator" text that sits above the slider visual in the middle of the "preferred range".  Bottom
-   // line is the slider visual and the "value" text that sits to the right of the slider visual.  The fonts for both
-   // bits of text are set in device-independent points in the constructor, and we can just query their height etc in
-   // pixels.
-   //
-   // Secondly, the way we tell Qt about minimum and preferred sizes is slightly different:
-   //  • setMinimumSize() tells Qt not to make us smaller than the specified size when resizing windows etc, HOWEVER
-   //    it does not determine what size we are initially drawn
-   //  • instead, Qt calls sizeHint() when doing initial layout, and we must override this to supply our desired
-   //    initial dimensions.  NB: Although it makes no sense, there is nothing to stop this method returning dimensions
-   //    below the minimums already set via setMinimumSize().  (AIUI, sizeHint() is also called on resize events to
-   //    find our preferred dimensions.)
-   //
-   // The final wrinkle is that the height of the font sort of depends what you mean.  Strictly, using the inter-line
-   // spacing (= height plus leading, though the latter is often 0) gives you enough space to show any character of the
-   // font.  It is helpful for the indicator text to have a bit of space below it before we draw the graphical bit, and
-   // it's not a large font in any case.  However, for large value text font we don't necessarily need all this space
-   // because we currently only show digits and decimal points, which don't require space below the baseline.  However,
-   // assumptions about space below the baseline are locale-specific, so, say, using ascent() instead of lineSpacing()
-   // could end up painting us into a corner.
-   //
-   //QFontMetrics indicatorTextFontMetrics(this->indicatorTextFont);
-//   this->heightInPixels = this->height();
-   return;
-}
-
-void RangedSlider::setSizes() {
-   // Fixed minimum size.
-   this->setMinimumSize(60, 20);
-   this->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
-
-   // There no particular reason to limit our horizontal size, so, in principle, this call asks that there be no such
-   // (practical) limit.
-   this->setMaximumWidth(QWIDGETSIZE_MAX);
-
-   return;
-}
-
-//QSize RangedSlider::sizeHint() const
-//{
-//   this->recalculateHeightInPixels();
-//   return QSize(4 * this->heightInPixels, this->heightInPixels);
-//}
-
 void RangedSlider::mouseMoveEvent(QMouseEvent* event)
 {
     event->accept();
@@ -331,12 +260,8 @@
 }
 
 
-void RangedSlider::moveEvent(QMoveEvent *event) {
-   // If we've moved, we might be on a new screen with a different DPI resolution...
-   // .:TBD:. This almost certainly needs further work and further testing.  It's far from clear whether our font size
-   //         querying will give different answers just because the app has been moved from one screen to another.
-   this->recalculateHeightInPixels();
-
-   QWidget::moveEvent(event);
-   return;
+void RangedSlider::moveEvent(QMoveEvent *event)
+{
+    QWidget::moveEvent(event);
+    return;
 }
--- a/src/RangedSlider.h	Fri Apr 01 16:52:25 2022 +0200
+++ b/src/RangedSlider.h	Fri Apr 01 17:25:42 2022 +0200
@@ -58,9 +58,6 @@
    //! \brief Set the \c precision for displaying values.
    void setPrecision(int precision);
 
-   //! \brief Reimplemented from QWidget.
-//   virtual QSize sizeHint() const;
-
 public slots:
    /**
     * @brief Set the value for the indicator.
@@ -91,12 +88,6 @@
 
 private:
    /**
-    * Sets minimum / maximum sizes and resize policy
-    */
-   void setSizes();
-   void recalculateHeightInPixels() const;
-
-   /**
     * Minimum value the widget displays
     */
    double _min;
@@ -113,6 +104,7 @@
     * Maximum value for the "best" sub-range
     */
    double _prefMax;
+
    double _val;
    QString _markerText;
    int _prec;
@@ -129,14 +121,6 @@
     * the IBU/GU reading.
     */
    QFont const indicatorTextFont;
-
-   /**
-    * Since preferred and minimum dimensions are all based off a height we need to calculate based on the resolution of
-    * the current display (see more detailed comment in implementation of recalculateSizes()), it is useful to store
-    * that height here.  However, its value is not really part of the current value/state of the object, hence mutable
-    * (ie OK to change in a const function).
-    */
-   mutable int heightInPixels;
 };
 
 #endif

mercurial