Skip to content

Commit

Permalink
Merge pull request #914 from matty0ung/usability
Browse files Browse the repository at this point in the history
Fix combo box crash when selected value is "child" record
  • Loading branch information
matty0ung authored Jan 1, 2025
2 parents a79aa13 + 535d7c6 commit dd9aad6
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 231 deletions.
12 changes: 12 additions & 0 deletions CHANGES.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ happens, so I'm now setting it to a slightly arbitrary time early in the morning
* Additional methods for calculating IBU
* We'll list other new features here...

## v4.0.15
Bug fixes and minor enhancements.

### New Features
* Updated Danish translations (courtesy of Orla Valbjørn Møller)

### Bug Fixes
* 4.0.13 and ubuntu 24.10 crash [913](https://github.com/Brewtarget/brewtarget/issues/913)

### Release Timestamp
Tue, 31 Dec 2024 04:00:15 +0100

## v4.0.14
Bug fixes and minor enhancements.

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ endif()
#=======================================================================================================================
# It's simplest to keep the project name all lower-case as it means we can use a lot more of the default settings for
# Linux packaging (where directory names etc are expected to be all lower-case).
project(brewtarget VERSION 4.0.14 LANGUAGES CXX)
project(brewtarget VERSION 4.0.15 LANGUAGES CXX)
message(STATUS "Building ${PROJECT_NAME} version ${PROJECT_VERSION}")
message(STATUS "PROJECT_SOURCE_DIR is ${PROJECT_SOURCE_DIR}")
# Sometimes we do need the capitalised version of the project name
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
#
#
project('brewtarget', 'cpp',
version: '4.0.14',
version: '4.0.15',
license: 'GPL-3.0-or-later',
meson_version: '>=0.63.0',
default_options : ['cpp_std=c++23',
Expand Down
2 changes: 1 addition & 1 deletion src/editors/EquipmentEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "editors/EditorBase.h"
#include "model/Equipment.h"

#define EquipmentEditorOptions EditorBaseOptions{ }
#define EquipmentEditorOptions EditorBaseOptions{ .idDisplay = true }
/*!
* \class EquipmentEditor
*
Expand Down
2 changes: 1 addition & 1 deletion src/editors/StyleEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "editors/EditorBase.h"
#include "model/Style.h"

#define StyleEditorOptions EditorBaseOptions{ }
#define StyleEditorOptions EditorBaseOptions{ .idDisplay = true }
/*!
* \class StyleEditor
*
Expand Down
7 changes: 5 additions & 2 deletions src/widgets/BtComboBoxNamedEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <QStyleOptionComboBox>
#include <QStylePainter>

BtComboBoxNamedEntity::BtComboBoxNamedEntity(QWidget* parent) : QComboBox(parent) {
BtComboBoxNamedEntity::BtComboBoxNamedEntity(char const * const name, QWidget* parent) :
QComboBox{parent},
m_name{name} {
return;
}

Expand All @@ -37,7 +39,8 @@ void BtComboBoxNamedEntity::setCurrentId(int value) {
// See comment in widgets/BtComboBoxNamedEntity.h for why the "nothing selected" option cannot appear explicitly
//
int const index {value < 0 ? -1 : this->findData(value)};
qDebug() << Q_FUNC_INFO << "value:" << value << ", index:" << index;
qDebug() << Q_FUNC_INFO << this->m_name << "value:" << value << ", index:" << index;

// It's a coding error to set an ID we don't know about
Q_ASSERT(value < 0 || index >= 0);

Expand Down
45 changes: 38 additions & 7 deletions src/widgets/BtComboBoxNamedEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@
class BtComboBoxNamedEntity : public QComboBox {
Q_OBJECT

public:
BtComboBoxNamedEntity(QWidget * parent);
protected:
BtComboBoxNamedEntity(char const * const name, QWidget * parent);
virtual ~BtComboBoxNamedEntity();

/**
* \brief Set the ID of the selected \c NamedEntity
* \brief Set the ID of the selected \c NamedEntity. This should only be called via
* \c BtComboBoxNamedEntityBase::setItem() (which does additional checks).
*
* \param value -1 means nothing selected
*/
void setCurrentId(int value);

int getCurrentId() const;

private:
QString const m_name;
};


Expand Down Expand Up @@ -133,10 +137,37 @@ class BtComboBoxNamedEntityBase : public CuriouslyRecurringTemplateBase<BtComboB

void setItem(std::shared_ptr<NE> item) {
if (item) {
this->derived().setCurrentId(item->key());
} else {
this->derived().setCurrentId(-1);
//
// For historical reasons, we still have users who have parent-child copies of various records in their DB.
// (This is from when each Recipe made a copy of the Equipment/Style/Mash etc records it used.) In these
// cases, only the parent record will be in the combo box, so we want to select that.
//
// Of course, just to make our lives fun, there are in fact many user databases where the parent-child
// relationships are not all present, so it's not guaranteed that we'll be able to find the "original" record.
// In these cases, we just show nothing in the combo box. The corresponding button will still show the actual
// record name, and the Recipe will retain this record if no new Equipment/Style/Mash is selected from the
// combo box.
//
// TBD At some point we want to see if we can get rid of all these parent-child records.
//
if (item->display()) {
this->derived().setCurrentId(item->key());
return;
}
int const parentKey = item->getParentKey();
if (parentKey > 0) {
auto parent = ObjectStoreWrapper::getById<NE>(parentKey);
if (parent->display()) {
this->derived().setCurrentId(parentKey);
return;
}
}

// As mentioned above, in this event, we'll drop through and not show anything on the combo box
qWarning() << Q_FUNC_INFO << "Unable to find displayable parent for" << *item;
}

this->derived().setCurrentId(-1);
return;
}

Expand Down Expand Up @@ -179,7 +210,7 @@ class BtComboBox##NeName : public BtComboBoxNamedEntity, \
*/
#define BT_COMBO_BOX_NAMED_ENTITY_CODE(NeName) \
BtComboBox##NeName::BtComboBox##NeName(QWidget * parent) : \
BtComboBoxNamedEntity{parent}, \
BtComboBoxNamedEntity{"BtComboBox" #NeName, parent}, \
BtComboBoxNamedEntityBase<BtComboBox##NeName , \
NeName , \
NeName##ListModel , \
Expand Down
Loading

0 comments on commit dd9aad6

Please sign in to comment.