Skip to content

Commit

Permalink
clang and qml formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
RobBuchananCompPhys committed Feb 6, 2024
1 parent 31ac53a commit 4b1b3b5
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 58 deletions.
1 change: 0 additions & 1 deletion src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ class DissolveWindow : public QMainWindow
* Shared Dialog Models
*/
public:

ModifyChargesModel *modifyChargesModel{nullptr};

public Q_SLOTS:
Expand Down
17 changes: 13 additions & 4 deletions src/gui/menu_species.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include "gui/importCIFDialog.h"
#include "gui/importLigParGenDialog.h"
#include "gui/importSpeciesDialog.h"
#include "gui/modifyChargesDialog.h"
#include "gui/models/modifyChargesModel.h"
#include "gui/modifyChargesDialog.h"
#include "gui/selectAtomTypeDialog.h"
#include "gui/selectElementDialog.h"
#include "gui/selectSpeciesDialog.h"
Expand Down Expand Up @@ -437,7 +437,10 @@ void DissolveWindow::on_SpeciesScaleChargesAction_triggered(bool checked)
if (!species)
return;

if (!modifyChargesModel) { modifyChargesModel = new ModifyChargesModel; }
if (!modifyChargesModel)
{
modifyChargesModel = new ModifyChargesModel;
}

ModifyChargesDialog dialog(this, modifyChargesModel, ModifyChargesModel::Scaling);
if (dialog.exec() == QDialog::Accepted)
Expand All @@ -455,7 +458,10 @@ void DissolveWindow::on_SpeciesSmoothChargesAction_triggered(bool checked)
if (!species)
return;

if (!modifyChargesModel) { modifyChargesModel = new ModifyChargesModel; }
if (!modifyChargesModel)
{
modifyChargesModel = new ModifyChargesModel;
}

ModifyChargesDialog dialog(this, modifyChargesModel, ModifyChargesModel::Smoothing);
if (dialog.exec() == QDialog::Accepted)
Expand All @@ -473,7 +479,10 @@ void DissolveWindow::on_SpeciesReduceChargesSigFigsAction_triggered(bool checked
if (!species)
return;

if (!modifyChargesModel) { modifyChargesModel = new ModifyChargesModel; }
if (!modifyChargesModel)
{
modifyChargesModel = new ModifyChargesModel;
}

ModifyChargesDialog dialog(this, modifyChargesModel, ModifyChargesModel::ReduceSigFig);
if (dialog.exec() == QDialog::Accepted)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/models/modifyChargesModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool ModifyChargesModel::scale(Species *species, bool showDialogOnError = true)
return true;
}

void ModifyChargesModel::smooth(Species *species)
void ModifyChargesModel::smooth(Species *species)
{
auto targetSum = smoothValue();
auto sum = species->totalCharge(false), shiftVal = 0.0;
Expand All @@ -66,7 +66,7 @@ void ModifyChargesModel::smooth(Species *species)
atom.setCharge(atom.charge() - shiftVal);
}

void ModifyChargesModel::reduceSignificantFigures(Species *species)
void ModifyChargesModel::reduceSignificantFigures(Species *species)
{
auto significantFigures = sigFigValue();
for (auto &atom : species->atoms())
Expand Down
20 changes: 14 additions & 6 deletions src/gui/models/modifyChargesModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ class ModifyChargesModel : public QObject
~ModifyChargesModel();

// Enum type to differentiate between operations for mofiying charges
enum ModifyBy { Scaling, Smoothing, ReduceSigFig };
enum ModifyBy
{
Scaling,
Smoothing,
ReduceSigFig
};
Q_ENUM(ModifyBy)

// Enum type to differentiate between usage options for dialog
// Can either "Scale" the current value, or "ScaleTo" a given value
enum ScaleType { Scale, ScaleTo };
enum ScaleType
{
Scale,
ScaleTo
};
Q_ENUM(ScaleType)

private:
Expand Down Expand Up @@ -63,12 +72,11 @@ class ModifyChargesModel : public QObject
// Returns the current significant figures
int sigFigValue() const;
// Apply scaling operation to species atoms charges
bool scale(Species*, bool);
bool scale(Species *, bool);
// Apply smoothing operation to species atoms charges
void smooth(Species*);
void smooth(Species *);
// Reduce significant figures on species atoms charges
void reduceSignificantFigures(Species*);

void reduceSignificantFigures(Species *);

Q_SIGNALS:
void valueSet();
Expand Down
7 changes: 4 additions & 3 deletions src/gui/modifyChargesDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2024 Team Dissolve and contributors

#include "gui/models/modifyChargesModel.h"
#include "gui/modifyChargesDialog.h"
#include <QObject>
#include "gui/models/modifyChargesModel.h"
#include <QHBoxLayout>
#include <QObject>
#include <QQmlContext>
#include <QQuickItem>
#include <QString>
#include <string>

#include <QDebug>

ModifyChargesDialog::ModifyChargesDialog(QWidget *parent, ModifyChargesModel *dialogModel, ModifyChargesModel::ModifyBy modify) : QDialog(parent)
ModifyChargesDialog::ModifyChargesDialog(QWidget *parent, ModifyChargesModel *dialogModel, ModifyChargesModel::ModifyBy modify)
: QDialog(parent)
{
view_ = new QQuickWidget(this);
view_->rootContext()->setContextProperty("modify", modify);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/modifyChargesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#pragma once

#include "gui/models/modifyChargesModel.h"
#include <QObject>
#include <QCloseEvent>
#include <QDialog>
#include <QObject>
#include <QQuickWidget>
#include <QCloseEvent>

class ModifyChargesModel;

Expand Down
34 changes: 15 additions & 19 deletions src/gui/qml/modifyCharges/Layout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,42 @@ import QtQuick.Layouts
import Dissolve
import "../widgets" as D


ColumnLayout {
anchors.fill: parent
spacing: 10

property ModifyChargesModel dialogModel
property int modify
property double smoothValue
property int sigFigValue
property double smoothValue

anchors.fill: parent
spacing: 10

function processSelection(option, x) {
switch(option) {
case ModifyChargesModel.Smoothing:
dialogModel.updateSmoothValue(x)
break
case ModifyChargesModel.ReduceSigFig:
dialogModel.updateSigFigValue(x)
break
default:
break
switch (option) {
case ModifyChargesModel.Smoothing:
dialogModel.updateSmoothValue(x);
break;
case ModifyChargesModel.ReduceSigFig:
dialogModel.updateSigFigValue(x);
break;
default:
break;
}
}

D.Text {
Layout.fillHeight: true
Layout.fillWidth: true
font.pointSize: 11
text: modify === ModifyChargesModel.Smoothing ?
"Enter the target sum to smooth atom charges to" :
"Enter the number of significant figures to use for all atoms"
text: modify === ModifyChargesModel.Smoothing ? "Enter the target sum to smooth atom charges to" : "Enter the number of significant figures to use for all atoms"
width: parent.width - 2 * parent.spacing
wrapMode: Text.WordWrap
}
SpinBox {
id: spinBox
objectName: modify === ModifyChargesModel.Smoothing ? "smoothSpinBox" : "sigFigSpinBox"
Layout.alignment: Qt.AlignRight
Layout.fillWidth: true
editable: modify === ModifyChargesModel.Smoothing ? true : false
from: modify === ModifyChargesModel.ReduceSigFig ? 0 : -100
objectName: modify === ModifyChargesModel.Smoothing ? "smoothSpinBox" : "sigFigSpinBox"
stepSize: 1
to: 100
value: modify === ModifyChargesModel.Smoothing ? dialogModel.smoothValue : dialogModel.sigFigValue
Expand Down
31 changes: 17 additions & 14 deletions src/gui/qml/modifyCharges/Loader.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,31 @@ Page {
id: root
height: 166
title: {
switch(modify) {
case ModifyChargesModel.Scaling:
return "Scale Charges";
case ModifyChargesModel.Smoothing:
return "Smooth Charges";
case ModifyChargesModel.ReduceSigFig:
return "Reduce Significant Figures";
default:
break;
switch (modify) {
case ModifyChargesModel.Scaling:
return "Scale Charges";
case ModifyChargesModel.Smoothing:
return "Smooth Charges";
case ModifyChargesModel.ReduceSigFig:
return "Reduce Significant Figures";
default:
break;
}
}
width: 400
visible: true
width: 400

Loader {
id: loader
objectName: "loader"
anchors.fill: parent
anchors.margins: 10
objectName: "loader"
sourceComponent: {
var path = modify === ModifyChargesModel.Scaling ? "ScaleLayout.qml" : "Layout.qml"
loader.setSource(qsTr("qrc:/dialogs/qml/modifyCharges/")+path, { "dialogModel" : dialogModel, "modify" : modify })
var path = modify === ModifyChargesModel.Scaling ? "ScaleLayout.qml" : "Layout.qml";
loader.setSource(qsTr("qrc:/dialogs/qml/modifyCharges/") + path, {
"dialogModel": dialogModel,
"modify": modify
});
}
}
}
}
10 changes: 4 additions & 6 deletions src/gui/qml/modifyCharges/ScaleLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@ import QtQuick.Layouts
import Dissolve
import "../widgets" as D


ColumnLayout {
anchors.fill: parent
spacing: 10

property ModifyChargesModel dialogModel
property int modify
property double scaleValue

anchors.fill: parent
spacing: 10

D.Text {
Layout.fillHeight: true
Layout.fillWidth: true
font.pointSize: 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: spinBox
objectName: "scaleSpinBox"
Layout.alignment: Qt.AlignRight
Layout.fillWidth: true
editable: true
from: -100
objectName: "scaleSpinBox"
stepSize: 1
to: 100
value: dialogModel.scaleValue
Expand Down
1 change: 1 addition & 0 deletions src/gui/qml/widgets/Text.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import QtQuick

Text {
anchors.margins: 4
font.pointSize: 11
wrapMode: Text.Wrap
}
2 changes: 1 addition & 1 deletion src/gui/typesFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "gui/models/configurationModel.h"
#include "gui/models/dissolveModel.h"
#include "gui/models/masterTermTreeModel.h"
#include "gui/models/moduleLayersModel.h"
#include "gui/models/modifyChargesModel.h"
#include "gui/models/moduleLayersModel.h"
#include "gui/models/speciesModel.h"
#include "gui/types.h"
#include <QQmlEngine>
Expand Down

0 comments on commit 4b1b3b5

Please sign in to comment.