Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display qml scale charges dialog #1763

Merged
merged 24 commits into from Jan 26, 2024

Conversation

RobBuchananCompPhys
Copy link
Contributor

@RobBuchananCompPhys RobBuchananCompPhys commented Jan 16, 2024

After selecting an atomic species and clicking "Scale Charges", you should see something like this:
(The spin box is narrower than before with xml, but maybe that is alright? - the inputs aren't expected to get too large)
scale_charges

@RobBuchananCompPhys RobBuchananCompPhys force-pushed the scale-charges-dialog-qml-translation branch from 997efcd to a0011bf Compare January 16, 2024 13:46
@RobBuchananCompPhys RobBuchananCompPhys marked this pull request as ready for review January 16, 2024 13:46
Copy link
Contributor

@rprospero rprospero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've made a bunch of comments, so I want to take a moment here to say that I really like what you've done here. This is a great use of the model setup and the QML code is pretty clean.

Besides the individual comments that I've made (and which I'm more than willing to listen, if you disagree), there's one larger change that I would suggest. Your model is very good, but a bunch of the work is still ultimately performed by the DissolveWindow::on_SpeciesScaleChargesAction_triggered function (which is the way it's always been). I think it would be worth adding a function to the model where you pass in a reference/pointer to the species and it does all the scaling within the model. That gives us a couple of advantages:

  1. It's now possible (and recommended) two write a unit test to confirm that the model performs the correct scaling.
  2. There's less code in the menu GUI, which should really only be for dispatch
  3. When we replace the main GUI with QML, there's no concern that we won't translate the logic correctly

src/gui/models/scaleChargesDialogModel.cpp Outdated Show resolved Hide resolved
src/gui/qml/ScaleChargesDialog.qml Show resolved Hide resolved
src/gui/qml/ScaleChargesDialog.qml Outdated Show resolved Hide resolved
src/gui/qml/ScaleChargesDialog.qml Outdated Show resolved Hide resolved
src/gui/models/scaleChargesDialogModel.h Outdated Show resolved Hide resolved
Copy link
Member

@trisyoungs trisyoungs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, and I think @rprospero makes a convincing case for moving the functionality into the model.

Have added some other comments, but notice that in the screengrab the buttons are aligned bottom-left in the dialog, when convention suggests bottom-right is the correct location.

src/gui/menu_species.cpp Outdated Show resolved Hide resolved
src/gui/menu_species.cpp Outdated Show resolved Hide resolved
src/gui/qml/ScaleChargesDialog.qml Outdated Show resolved Hide resolved
src/gui/qml/ScaleChargesDialog.qml Show resolved Hide resolved
@RobBuchananCompPhys RobBuchananCompPhys force-pushed the scale-charges-dialog-qml-translation branch from ba80920 to 480d50a Compare January 22, 2024 17:10
@RobBuchananCompPhys
Copy link
Contributor Author

I've added a unit test for the model. This should be good to go.

One outstanding issue is that user manually resizing the dialog's window doesn't seem cause the contained UI components to adapt their size/positioning, or enforce a minimum size. (Perhaps I'm missing something @rprospero?)

scale_charges2

src/gui/menu_species.cpp Outdated Show resolved Hide resolved
src/gui/models/scaleChargesDialogModel.cpp Outdated Show resolved Hide resolved
src/gui/models/scaleChargesDialogModel.cpp Outdated Show resolved Hide resolved
src/gui/models/scaleChargesDialogModel.cpp Outdated Show resolved Hide resolved
src/gui/models/scaleChargesDialogModel.h Outdated Show resolved Hide resolved
src/gui/models/scaleChargesDialogModel.h Show resolved Hide resolved
@trisyoungs
Copy link
Member

The dialog looks really nice now - great work on the harmonisation of styles! One small thing - the Cancel button should be leftmost rather than occupying the default "human click" position of bottom-right.

@RobBuchananCompPhys RobBuchananCompPhys force-pushed the scale-charges-dialog-qml-translation branch from b0ae9b0 to 7591342 Compare January 25, 2024 10:11
@rprospero rprospero merged commit 4e67ebe into develop Jan 26, 2024
8 checks passed
@rprospero rprospero deleted the scale-charges-dialog-qml-translation branch January 26, 2024 09:47
Copy link
Member

@trisyoungs trisyoungs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent stuff. Some small suggested corrections (more auto and a few other bits) but this is good to go.

ScaleChargesDialog::~ScaleChargesDialog() {}
ScaleChargesDialog::ScaleChargesDialog(QWidget *parent) : QDialog(parent)
{
QQuickWidget *view = new QQuickWidget(QUrl("qrc:/dialogs/qml/ScaleChargesDialog.qml"), this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QQuickWidget *view = new QQuickWidget(QUrl("qrc:/dialogs/qml/ScaleChargesDialog.qml"), this);
auto view = new QQuickWidget(QUrl("qrc:/dialogs/qml/ScaleChargesDialog.qml"), this);

}
view->setResizeMode(QQuickWidget::SizeRootObjectToView);

QHBoxLayout *topLeftLayout = new QHBoxLayout;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QHBoxLayout *topLeftLayout = new QHBoxLayout;
auto topLeftLayout = new QHBoxLayout;


ScaleChargesDialogModel::Option ScaleChargesDialogModel::getOption() { return scaleType_; }

bool ScaleChargesDialogModel::scaleCharges(Species *species, bool showDialogOnError = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool ScaleChargesDialogModel::scaleCharges(Species *species, bool showDialogOnError = true)
bool ScaleChargesDialogModel::scaleCharges(Species *species, bool showDialogOnError)

// Returns the current scale value
double value() const;
// Apply scaling operation to species atoms
bool scaleCharges(Species *, bool);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool scaleCharges(Species *, bool);
bool scaleCharges(Species *species, bool showDialogOnError = true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants