-
Notifications
You must be signed in to change notification settings - Fork 16
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
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e509bbc
display qml scale charges dialog
RobBuchananCompPhys 1e79a61
removed ui file
RobBuchananCompPhys 169ae2d
applied clang formatting
RobBuchananCompPhys 11cee45
QC
RobBuchananCompPhys b93dca8
qml imports custom widgets, uses scale charge option enum as defined …
RobBuchananCompPhys 27bf1cc
applied clang formatting
RobBuchananCompPhys 9dab116
applied qml formatting
RobBuchananCompPhys e781977
use auto
RobBuchananCompPhys 36f7407
reset spin box when cancelled, modularised code for processing selection
RobBuchananCompPhys ec688b2
added padding, button icons and alignment
RobBuchananCompPhys 9d72b81
qml format
RobBuchananCompPhys 39ccff6
added unit test for model
RobBuchananCompPhys 4a6141f
clang formatting
RobBuchananCompPhys 1756a33
renamed test, renamed property scale_type_ to scaleType_
RobBuchananCompPhys 3c7f4ce
fixed scale dialog tests
RobBuchananCompPhys 8b45cd1
WordWrap
RobBuchananCompPhys a37dab6
tweaks to dialog
RobBuchananCompPhys 68981f5
format qml
RobBuchananCompPhys 0fba013
increased comment coverage
RobBuchananCompPhys 98004cc
use auto
RobBuchananCompPhys 7591342
moved scale error message from menu actions to model, scale method no…
RobBuchananCompPhys 678c3d7
updated to fix the gui header issue
RobBuchananCompPhys 68e839a
make dialog resizable
RobBuchananCompPhys 65a49b1
applied formatting
RobBuchananCompPhys File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// Copyright (c) 2024 Team Dissolve and contributors | ||
|
||
#include "gui/models/scaleChargesDialogModel.h" | ||
#include <QMessageBox> | ||
|
||
ScaleChargesDialogModel::ScaleChargesDialogModel() {} | ||
|
||
ScaleChargesDialogModel::~ScaleChargesDialogModel() {} | ||
|
||
double ScaleChargesDialogModel::value() const { return currentValue_; } | ||
|
||
void ScaleChargesDialogModel::updateValue(double newVal) { currentValue_ = newVal; } | ||
|
||
void ScaleChargesDialogModel::setOption(Option option) { scaleType_ = option; } | ||
|
||
ScaleChargesDialogModel::Option ScaleChargesDialogModel::getOption() { return scaleType_; } | ||
|
||
bool ScaleChargesDialogModel::scaleCharges(Species *species, bool showDialogOnError = true) | ||
{ | ||
auto scaleFactor = value(); | ||
if (scaleType_ != Scale) | ||
{ | ||
auto scaleTarget = scaleFactor; | ||
if (fabs(scaleTarget) < 1.0e-6) | ||
{ | ||
if (showDialogOnError) | ||
{ | ||
QMessageBox::warning(nullptr, "Scale atom charges", "Cannot scale atom charges so they sum to 0.", | ||
QMessageBox::StandardButton::Ok); | ||
} | ||
return false; | ||
} | ||
|
||
auto sum = 0.0; | ||
for (auto &atom : species->atoms()) | ||
sum += atom.charge(); | ||
scaleFactor = scaleTarget / sum; | ||
} | ||
for (auto &atom : species->atoms()) | ||
atom.setCharge(atom.charge() * scaleFactor); | ||
|
||
return true; | ||
} |
RobBuchananCompPhys marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,49 @@ | ||||||
// SPDX-License-Identifier: GPL-3.0-or-later | ||||||
// Copyright (c) 2024 Team Dissolve and contributors | ||||||
|
||||||
#pragma once | ||||||
|
||||||
#include "classes/species.h" | ||||||
#include <QObject> | ||||||
|
||||||
class ScaleChargesDialogModel : public QObject | ||||||
{ | ||||||
Q_OBJECT | ||||||
|
||||||
Q_PROPERTY(double value READ value NOTIFY valueSet) | ||||||
|
||||||
public: | ||||||
ScaleChargesDialogModel(); | ||||||
~ScaleChargesDialogModel(); | ||||||
|
||||||
// Enum type to differentiate between usage options for dialog | ||||||
// Can either "Scale" the current value, or "ScaleTo" a given value | ||||||
typedef enum | ||||||
{ | ||||||
Scale, | ||||||
ScaleTo | ||||||
} Option; | ||||||
Q_ENUM(Option) | ||||||
|
||||||
// User has chosen either to apply Scale or ScaleTo to the charges | ||||||
Q_INVOKABLE void setOption(Option); | ||||||
// Sets the new selected scale value | ||||||
Q_INVOKABLE void updateValue(double); | ||||||
|
||||||
// Returns the current option | ||||||
Option getOption(); | ||||||
|
||||||
// Returns the current scale value | ||||||
double value() const; | ||||||
// Apply scaling operation to species atoms | ||||||
bool scaleCharges(Species *, bool); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
private: | ||||||
double currentValue_{1.0}; | ||||||
Option scaleType_; | ||||||
|
||||||
Q_SIGNALS: | ||||||
void valueSet(); | ||||||
void cancelSelection(); | ||||||
void acceptSelection(); | ||||||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import QtQuick | ||
import QtQuick.Controls | ||
import QtQuick.Layouts | ||
import Dissolve | ||
import "widgets" as D | ||
|
||
Page { | ||
id: root | ||
property double value | ||
|
||
height: 116 | ||
title: "Scale Charges" | ||
visible: true | ||
width: 400 | ||
|
||
ScaleChargesDialogModel { | ||
id: dialogModel | ||
objectName: "dialogModel" | ||
|
||
function processSelection(mode, x) { | ||
dialogModel.setOption(mode); | ||
dialogModel.updateValue(x); | ||
} | ||
} | ||
Item { | ||
anchors.fill: parent | ||
anchors.margins: 10 | ||
|
||
ColumnLayout { | ||
anchors.fill: parent | ||
spacing: 10 | ||
|
||
D.Text { | ||
Layout.fillHeight: true | ||
Layout.fillWidth: true | ||
font.pixelSize: 11 | ||
text: "Enter the scaling factor to apply to all atoms / the target sum to determine scaling factor from" | ||
RobBuchananCompPhys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
width: parent.width - 2 * parent.spacing | ||
wrapMode: Text.WordWrap | ||
} | ||
SpinBox { | ||
id: scaleSpinBox | ||
Layout.alignment: Qt.AlignRight | ||
Layout.fillWidth: true | ||
editable: true | ||
from: -100 | ||
stepSize: 1 | ||
to: 100 | ||
value: dialogModel.value | ||
} | ||
RowLayout { | ||
Layout.alignment: Qt.AlignRight | ||
spacing: 10 | ||
|
||
D.Button { | ||
id: cancelButton | ||
icon.source: "qrc:/general/icons/false.svg" | ||
text: "Cancel" | ||
|
||
onClicked: { | ||
dialogModel.cancelSelection(); | ||
scaleSpinBox.value = dialogModel.value; | ||
} | ||
} | ||
D.Button { | ||
id: scaleButton | ||
icon.source: "qrc:/general/icons/true.svg" | ||
text: "Scale" | ||
|
||
onClicked: { | ||
dialogModel.processSelection(dialogModel.Scale, scaleSpinBox.value); | ||
dialogModel.acceptSelection(); | ||
} | ||
} | ||
D.Button { | ||
id: scaleToButton | ||
icon.source: "qrc:/general/icons/true.svg" | ||
text: "Scale To" | ||
|
||
onClicked: { | ||
dialogModel.processSelection(dialogModel.ScaleTo, scaleSpinBox.value); | ||
dialogModel.acceptSelection(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.