-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
display qml scale charges dialog (#1763)
- Loading branch information
1 parent
36447f1
commit 4e67ebe
Showing
13 changed files
with
286 additions
and
133 deletions.
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; | ||
} |
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); | ||
|
||
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" | ||
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.
4e67ebe
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.
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.BM_Box_MinimumVector<OrthorhombicBox>
11.899363049760147
ns/iter5.30059682235742
ns/iter2.24
This comment was automatically generated by workflow using github-action-benchmark.
CC: @disorderedmaterials/dissolve-devs