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

Simulation data manager as QML TableView #1809

Merged
merged 19 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ add_library(
copySpeciesTermsDialog.ui
dataManagerDialog.cpp
dataManagerDialog.h
dataManagerDialog.ui
editSpeciesDialog.cpp
editSpeciesDialog.h
editSpeciesDialog.ui
Expand Down
41 changes: 12 additions & 29 deletions src/gui/dataManagerDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,26 @@
#include "main/dissolve.h"
#include "templates/variantPointer.h"
#include <QFileDialog>
#include <QHBoxLayout>
#include <QInputDialog>
#include <QMessageBox>
#include <QQmlContext>
#include <QRegularExpression>

DataManagerDialog::DataManagerDialog(QWidget *parent, Dissolve &dissolve, GenericList &items)
: QDialog(parent), dissolve_(dissolve), simModel_(dissolve, items)
{
ui_.setupUi(this);

view_ = new QQuickWidget(this);
simProxy_.setSourceModel(&simModel_);
ui_.SimulationDataTable->setModel(&simProxy_);
ui_.SimulationDataTable->setSortingEnabled(true);

updateControls();
}

/*
* UI
*/
view_->rootContext()->setContextProperty("simProxy", &simProxy_);
view_->rootContext()->setContextProperty("simModel", &simModel_);
view_->setSource(QUrl("qrc:/dialogs/qml/simulationDataManager/SimulationDataManager.qml"));

// Update the specified table of GenericItems, optionally filtering them by name and description
void DataManagerDialog::filterTable(QString filterText)
{
simProxy_.setFilterRegularExpression(
QRegularExpression(filterText.replace("*", ".*"), QRegularExpression::CaseInsensitiveOption));
simProxy_.setFilterKeyColumn(0);
}

// Update controls
void DataManagerDialog::updateControls()
{
// Clear and re-populate simulation data table
ui_.SimulationDataTable->resizeColumnsToContents();
}
view_->setResizeMode(QQuickWidget::SizeRootObjectToView);

// Simulation Data
void DataManagerDialog::on_SimulationDataFilterEdit_textChanged(const QString &text) { filterTable(text); }
auto *topLeftLayout = new QHBoxLayout;
topLeftLayout->addWidget(view_);
setLayout(topLeftLayout);

// Dialog
void DataManagerDialog::on_CloseButton_clicked(bool checked) { accept(); }
QObject::connect(&simModel_, SIGNAL(closeClicked()), this, SLOT(accept()));
}
15 changes: 2 additions & 13 deletions src/gui/dataManagerDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#pragma once

#include "gui/models/dataManagerSimulationModel.h"
#include "gui/ui_dataManagerDialog.h"
#include "items/list.h"
#include <QDialog>
#include <QQuickWidget>
#include <QSortFilterProxyModel>
#include <vector>

Expand Down Expand Up @@ -34,16 +34,5 @@ class DataManagerDialog : public QDialog
* UI
*/
private:
// Main form declaration
Ui::DataManagerDialog ui_;

private:
// Update the specified table of GenericItems, optionally filtering them by name and description
void filterTable(QString filterText);
// Update controls
void updateControls();

private Q_SLOTS:
void on_SimulationDataFilterEdit_textChanged(const QString &text);
void on_CloseButton_clicked(bool checked);
QQuickWidget *view_{nullptr};
};
185 changes: 0 additions & 185 deletions src/gui/dataManagerDialog.ui

This file was deleted.

1 change: 1 addition & 0 deletions src/gui/main.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
<file>qml/modifyCharges/Loader.qml</file>
<file>qml/modifyCharges/Layout.qml</file>
<file>qml/modifyCharges/ScaleLayout.qml</file>
<file>qml/simulationDataManager/SimulationDataManager.qml</file>
<file>qml/DropDownLabel.qml</file>
<file>qml/ForceFieldAssign.qml</file>
<file>qml/ForceFieldAtomTypes.qml</file>
Expand Down
4 changes: 4 additions & 0 deletions src/gui/models/dataManagerSimulationModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "main/dissolve.h"
#include <QAbstractTableModel>
#include <QModelIndex>
#include <QString>
#include <optional>
#include <vector>

Expand All @@ -30,4 +31,7 @@ class DataManagerSimulationModel : public QAbstractTableModel

// Register all changes to the model
void update();

Q_SIGNALS:
void closeClicked();
};
91 changes: 91 additions & 0 deletions src/gui/qml/simulationDataManager/SimulationDataManager.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Dissolve 1.0
import "../widgets" as D

Page {
id: root
height: 500
visible: true
width: 670

function filterByRegExp(proxy, text) {
proxy.filterRegularExpression = RegExp(text);
}
function getHeaderStringArray(model) {
var headerArray = [];
for (var i = 0; i < model.columnCount(); ++i) {
headerArray.push(qsTr(model.headerData(i, Qt.Horizontal)));
}
return headerArray;
}

D.GroupBox {
id: gb
anchors.fill: parent
title: "Current Module Data"

ColumnLayout {
anchors.fill: parent

TextField {
id: searchBox
Layout.alignment: Qt.AlignRight
Layout.preferredWidth: gb.width / 4
placeholderText: qsTr("Search...")

onEditingFinished: {
filterByRegExp(simProxy, searchBox.text);
if (simProxy.rowCount() == 0) {
filterByRegExp(simProxy, "");
}
}
}
HorizontalHeaderView {
id: header
Layout.fillWidth: true
Layout.preferredHeight: contentHeight
Layout.preferredWidth: contentWidth
clip: true
enabled: simModel.rowCount() == 0 ? false : true
model: getHeaderStringArray(simModel)
syncView: table
}
TableView {
id: table
property variant colWidths: [300, 300, 50]

Layout.fillHeight: true
Layout.fillWidth: true
boundsBehavior: Flickable.StopAtBounds
clip: true
columnSpacing: 1
columnWidthProvider: function (column) {
return colWidths[column];
}
model: simProxy
rowSpacing: 1

delegate: Rectangle {
color: "white"
implicitHeight: tableText.height
implicitWidth: tableText.width

D.Text {
id: tableText
padding: 12
text: display
}
}
}
D.Button {
id: closeButton
Layout.alignment: Qt.AlignRight
text: "Close"

onClicked: simModel.closeClicked()
}
}
}
}
Loading