SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
mainwindow.h
Go to the documentation of this file.
1// SedSAT3 – Sediment Source Assessment Tool, version 3
2// U.S. Geological Survey. See LICENSE.md and DISCLAIMER.md in the repository root.
3
4#ifndef MAINWINDOW_H
5#define MAINWINDOW_H
6
7#include <QMainWindow>
8#include <memory>
9#include <string>
10#include <map>
11#include <QStandardItemModel>
12#include <QStandardItem>
13#include "sourcesinkdata.h"
14#include <QJsonDocument>
15#ifdef USE_QCHARTS
16#include "GeneralChartPlotter.h"
17#else
18#include "generalplotter.h"
19#endif // USE_QCHARTS
20
22#include "conductor.h"
23#include "guihost.h"
24
26 elementRole = Qt::ItemDataRole::UserRole + 1,
27 groupRole = Qt::ItemDataRole::UserRole + 2,
28 sampleRole = Qt::ItemDataRole::UserRole + 3
29};
30
31QT_BEGIN_NAMESPACE
32namespace Ui { class MainWindow; }
33QT_END_NAMESPACE
34
44 class MainWindow : public QMainWindow
45{
46 Q_OBJECT
47
48public:
53 explicit MainWindow(QWidget* parent = nullptr);
54
59
64 void SetSinkSheet(int i) { sinkSheet = i; }
65
71 void WriteMessageOnScreen(const QString& text, QColor color = Qt::black);
72
78 const SourceSinkData* Data() const { return &dataCollection; }
85 bool Execute(const std::string& command, const std::map<std::string, std::string>& arguments);
86
87private:
88 // UI Setup methods
96 void setupConnections();
97
104 void setupToolsView();
105
112 void setupResultsView();
113
119 void setupToolBar();
120
121 // Data import/export methods
127 bool ReadExcel(const QString& filename);
128
129 QString resourcesPath() const;
130
131 // Model conversion methods
132 QStandardItemModel* ToQStandardItemModel(const SourceSinkData* srcsinkdata);
133 QStandardItem* ToQStandardItem(const QString& key, const SourceSinkData* srcsinkdata);
134 QStandardItem* ElementsToQStandardItem(const QString& key, const SourceSinkData* srcsinkdata);
135 QStandardItem* ToQStandardItem(const QString& key, const QJsonObject& json);
136 QStandardItemModel* ToQStandardItemModel(const QJsonDocument& jsondocument);
137
138 QString TreeQStringSelectedType();
139
140 // JSON file I/O
141 QJsonDocument loadJson(const QString& fileName);
142 void saveJson(const QJsonDocument& document, const QString& fileName);
143
144 // Table initialization
145 void InitiateTables();
146
147 // Recent files management
148 void readRecentFilesList();
149 void addToRecentFiles(const QString &fileName, bool addToFile);
151 void removeFromRecentList(QAction* selectedFileAction);
152 bool CreateFileIfDoesNotExist(const QString &fileName);
153
154 // Project file management
155 bool LoadModel(const QString& fileName);
156
157 // Toolbar population
159
160private slots:
161 // File operations
162 void on_import_excel();
163
164 // Plotting
166
167 // Tree view handling
168 void on_tree_selectionChanged(const QItemSelection& changed);
169 void preparetreeviewMenu(const QPoint& pos);
171
172 // Data management
174 void onSetTargetGroup();
176 void onOMSizeCorrection();
177
178 // Tool execution
179 void on_tool_executed(const QModelIndex& index);
180 void on_old_result_requested(const QModelIndex& index);
181
182 // Application menu
183 void onAboutTriggered();
185
186
187private:
188 // Project management
194 QString getSaveFilePath(bool promptUser);
195
201 bool saveProjectToFile(const QString& filePath);
202
207 QJsonObject buildProjectJson() const;
208
213 QJsonObject buildResultsJson() const;
214
215 void onSaveProject();
216 void onSaveProjectAs();
217 void onOpenProject();
219
220 // Results management
221 void DeleteResults();
222 void onCustomContextMenu(const QPoint& pos);
223
224 // Display
226 void on_ZoomExtends();
227
239 void addToolBarAction(const QString& text,
240 const QString& iconPath,
241 const QString& toolTip,
242 void (MainWindow::* slot)());
243
244 Ui::MainWindow* ui;
245
246 // Data
248 int sinkSheet = -1;
249
250 // Visualization
251#ifdef USE_QCHARTS
252 GeneralChartPlotter* plotter = nullptr;
253#else
255#endif // USE_QCHARTS
256
257
258 std::unique_ptr<Interface> plottedData;
259
260 // Models
261 std::unique_ptr<QStandardItemModel> columnViewModel;
262 std::unique_ptr<QStandardItemModel> resultsViewModel;
263
264 // Context menus and actions
265 QMenu* ResultscontextMenu = nullptr;
266 QAction* DeleteAction = nullptr;
267
268 // JSON configuration
269 QJsonDocument formsstructure;
270
271 // State tracking
272 QString selectedTreeItemType = "None";
275 QStringList recentFiles;
276
277 // Main components
278 std::unique_ptr<QMenu> menu;
279 std::unique_ptr<QWidget> centralform;
280 std::unique_ptr<GuiHost> analysis_host;
281 std::unique_ptr<Conductor> conductor;
283};
284
289QString localAppFolderAddress();
290
291#endif // MAINWINDOW_H
Main application window for SedSAT3 source apportionment analysis.
Definition mainwindow.h:45
void on_actionRecent_triggered()
void addToolBarAction(const QString &text, const QString &iconPath, const QString &toolTip, void(MainWindow::*slot)())
Helper to add an action to the toolbar with icon and connection.
QString resourcesPath() const
void on_old_result_requested(const QModelIndex &index)
bool ReadExcel(const QString &filename)
Reads elemental profile data from Excel file.
QStringList recentFiles
List of recently opened files.
Definition mainwindow.h:275
SourceSinkData * Data()
Returns pointer to the main data collection.
Definition mainwindow.h:77
QMenu * ResultscontextMenu
Context menu for results view.
Definition mainwindow.h:265
void DeleteResults()
GeneralPlotter * plotter
Main plotting widget.
Definition mainwindow.h:254
SourceSinkData dataCollection
Main data collection for analysis.
Definition mainwindow.h:247
void showdistributionsforelements()
void on_show_data_as_table()
QString ProjectFileName
Current project file path.
Definition mainwindow.h:274
void onOpenProject()
QStandardItem * ToQStandardItem(const QString &key, const SourceSinkData *srcsinkdata)
std::unique_ptr< QStandardItemModel > columnViewModel
Model for column/data tree view.
Definition mainwindow.h:261
bool LoadModel(const QString &fileName)
void setupResultsView()
Initializes the results tree view and context menu.
void WriteMessageOnScreen(const QString &text, QColor color=Qt::black)
Writes a message to the application's message display area.
Ui::MainWindow * ui
Definition mainwindow.h:244
bool treeItemChangedProgramatically
Flag for programmatic tree changes.
Definition mainwindow.h:273
void setupToolsView()
Initializes the tools tree view.
bool CreateFileIfDoesNotExist(const QString &fileName)
void Populate_General_ToolBar()
std::unique_ptr< QStandardItemModel > resultsViewModel
Model for results tree view.
Definition mainwindow.h:262
const SourceSinkData * Data() const
Definition mainwindow.h:78
bool saveProjectToFile(const QString &filePath)
Saves project data to the specified file.
QString getSaveFilePath(bool promptUser)
Gets the file path for saving, prompting user if needed.
std::unique_ptr< Conductor > conductor
Analysis command coordinator.
Definition mainwindow.h:281
void on_Options_triggered()
void addToRecentFiles(const QString &fileName, bool addToFile)
QJsonObject buildProjectJson() const
Builds the complete project JSON object.
QJsonDocument formsstructure
Forms structure definitions.
Definition mainwindow.h:269
void SetSinkSheet(int i)
Sets the sink sheet index for Excel import.
Definition mainwindow.h:64
QString selectedTreeItemType
Currently selected tree item type.
Definition mainwindow.h:272
void on_constituent_properties_triggered()
QStandardItemModel * ToQStandardItemModel(const SourceSinkData *srcsinkdata)
QString TreeQStringSelectedType()
void on_import_excel()
void removeFromRecentList(QAction *selectedFileAction)
void writeRecentFilesList()
void InitiateTables()
void setupConnections()
Sets up all signal-slot connections for UI elements.
bool Execute(const std::string &command, const std::map< std::string, std::string > &arguments)
Executes a specified analysis command.
MainWindow(QWidget *parent=nullptr)
Constructs the main window.
std::unique_ptr< QMenu > menu
Main menu.
Definition mainwindow.h:278
QJsonObject buildResultsJson() const
Builds the results section of the project JSON.
QJsonDocument loadJson(const QString &fileName)
std::unique_ptr< QWidget > centralform
Central form widget.
Definition mainwindow.h:279
QAction * DeleteAction
Delete action for results.
Definition mainwindow.h:266
std::unique_ptr< Interface > plottedData
Currently plotted data interface.
Definition mainwindow.h:258
void preparetreeviewMenu(const QPoint &pos)
void on_ZoomExtends()
void onOMSizeCorrection()
std::unique_ptr< GuiHost > analysis_host
Reports analyses through this window.
Definition mainwindow.h:280
void onAboutTriggered()
QStandardItem * ElementsToQStandardItem(const QString &key, const SourceSinkData *srcsinkdata)
void readRecentFilesList()
void onSetTargetGroup()
int sinkSheet
Index of sink sheet in Excel import.
Definition mainwindow.h:248
void on_plot_raw_elemental_profiles()
void setupToolBar()
Initializes the general toolbar.
void onCustomContextMenu(const QPoint &pos)
QModelIndex indexresultselected
Currently selected result index.
Definition mainwindow.h:282
void on_tree_selectionChanged(const QItemSelection &changed)
~MainWindow()
Destructor - cleans up UI resources.
void onSaveProject()
void saveJson(const QJsonDocument &document, const QString &fileName)
void onIncludeExcludeSample()
void on_tool_executed(const QModelIndex &index)
void onSaveProjectAs()
ItemDataRoles
Definition mainwindow.h:25
@ elementRole
Definition mainwindow.h:26
@ sampleRole
Definition mainwindow.h:28
@ groupRole
Definition mainwindow.h:27
QString localAppFolderAddress()
Returns the local application folder address.