1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
/*
* mainwindow.cpp
*
* classes for the main UI window in Subsurface
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QVBoxLayout>
#include <QFileDialog>
#include <QMessageBox>
#include <QtDebug>
#include <QDateTime>
#include <QSortFilterProxyModel>
#include <QSettings>
#include <QCloseEvent>
#include <QApplication>
#include <QFontMetrics>
#include "divelistview.h"
#include "starwidget.h"
#include "glib.h"
#include "../dive.h"
#include "../divelist.h"
#include "../pref.h"
#include "modeldelegates.h"
#include "models.h"
MainWindow::MainWindow() : ui(new Ui::MainWindow()),
model(new DiveTripModel(this)),
sortModel(new QSortFilterProxyModel())
{
ui->setupUi(this);
sortModel->setSourceModel(model);
ui->ListWidget->setModel(sortModel);
connect(ui->ListWidget, SIGNAL(activated(QModelIndex)), this, SLOT(diveSelected(QModelIndex)));
setWindowIcon(QIcon(":subsurface-icon"));
readSettings();
}
void MainWindow::diveSelected(const QModelIndex& index)
{
struct dive *dive = (struct dive*) index.model()->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
if (dive)
selected_dive = get_index_for_dive(dive);
// Here should be the code to update the other widgets.
}
void MainWindow::on_actionNew_triggered()
{
qDebug("actionNew");
}
void MainWindow::on_actionOpen_triggered()
{
QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::homePath(), filter());
if (filename.isEmpty())
return;
// Needed to convert to char*
QByteArray fileNamePtr = filename.toLocal8Bit();
on_actionClose_triggered();
GError *error = NULL;
parse_file(fileNamePtr.data(), &error);
set_filename(fileNamePtr.data(), TRUE);
if (error != NULL) {
QMessageBox::warning(this, "Error", error->message);
g_error_free(error);
error = NULL;
}
process_dives(FALSE, FALSE);
ui->InfoWidget->reload();
model->deleteLater();
model = new DiveTripModel(this);
sortModel->setSourceModel(model);
ui->ListWidget->sortByColumn(0, Qt::DescendingOrder);
}
void MainWindow::on_actionSave_triggered()
{
qDebug("actionSave");
}
void MainWindow::on_actionSaveAs_triggered()
{
qDebug("actionSaveAs");
}
void MainWindow::on_actionClose_triggered()
{
if (unsaved_changes() && (askSaveChanges() == FALSE))
return;
/* free the dives and trips */
while (dive_table.nr)
delete_single_dive(0);
mark_divelist_changed(FALSE);
/* clear the selection and the statistics */
selected_dive = 0;
//WARNING: Port this to Qt.
//process_selected_dives();
ui->InfoWidget->clearStats();
ui->InfoWidget->clearInfo();
ui->InfoWidget->clearEquipment();
clear_events();
#if USE_GTK_UI
show_dive_stats(NULL);
/* redraw the screen */
//WARNING: Port this to Qt.
dive_list_update_dives();
// WARNING? Port this to Qt.
show_dive_info(NULL);
#endif /* USE_GTK_UI */
}
void MainWindow::on_actionImport_triggered()
{
qDebug("actionImport");
}
void MainWindow::on_actionExportUDDF_triggered()
{
qDebug("actionExportUDDF");
}
void MainWindow::on_actionPrint_triggered()
{
qDebug("actionPrint");
}
void MainWindow::on_actionPreferences_triggered()
{
qDebug("actionPreferences");
}
void MainWindow::on_actionQuit_triggered()
{
qDebug("actionQuit");
if (unsaved_changes() && (askSaveChanges() == FALSE))
return;
}
void MainWindow::on_actionDownloadDC_triggered()
{
qDebug("actionDownloadDC");
}
void MainWindow::on_actionDownloadWeb_triggered()
{
qDebug("actionDownloadWeb");}
void MainWindow::on_actionEditDeviceNames_triggered()
{
qDebug("actionEditDeviceNames");}
void MainWindow::on_actionAddDive_triggered()
{
qDebug("actionAddDive");
}
void MainWindow::on_actionRenumber_triggered()
{
qDebug("actionRenumber");
}
void MainWindow::on_actionAutoGroup_triggered()
{
qDebug("actionAutoGroup");
}
void MainWindow::on_actionToggleZoom_triggered()
{
qDebug("actionToggleZoom");
}
void MainWindow::on_actionYearlyStatistics_triggered()
{
qDebug("actionYearlyStatistics");
}
void MainWindow::on_actionViewList_triggered()
{
qDebug("actionViewList");
ui->InfoWidget->setVisible(false);
ui->ListWidget->setVisible(true);
ui->ProfileWidget->setVisible(false);
}
void MainWindow::on_actionViewProfile_triggered()
{
qDebug("actionViewProfile");
ui->InfoWidget->setVisible(false);
ui->ListWidget->setVisible(false);
ui->ProfileWidget->setVisible(true);
}
void MainWindow::on_actionViewInfo_triggered()
{
qDebug("actionViewInfo");
ui->InfoWidget->setVisible(true);
ui->ListWidget->setVisible(false);
ui->ProfileWidget->setVisible(false);
}
void MainWindow::on_actionViewAll_triggered()
{
qDebug("actionViewAll");
ui->InfoWidget->setVisible(true);
ui->ListWidget->setVisible(true);
ui->ProfileWidget->setVisible(true);
}
void MainWindow::on_actionPreviousDC_triggered()
{
qDebug("actionPreviousDC");
}
void MainWindow::on_actionNextDC_triggered()
{
qDebug("actionNextDC");
}
void MainWindow::on_actionSelectEvents_triggered()
{
qDebug("actionSelectEvents");
}
void MainWindow::on_actionInputPlan_triggered()
{
qDebug("actionInputPlan");
}
void MainWindow::on_actionAboutSubsurface_triggered()
{
qDebug("actionAboutSubsurface");
}
void MainWindow::on_actionUserManual_triggered()
{
qDebug("actionUserManual");
}
QString MainWindow::filter()
{
QString f;
f += "ALL ( *.xml *.XML *.uddf *.udcf *.UDFC *.jlb *.JLB ";
#ifdef LIBZIP
f += "*.sde *.SDE *.dld *.DLD ";
#endif
#ifdef SQLITE3
f += "*.db";
#endif
f += ");;";
f += "XML (*.xml *.XML);;";
f += "UDDF (*.uddf);;";
f += "UDCF (*.udcf *.UDCF);;";
f += "JLB (*.jlb *.JLB);;";
#ifdef LIBZIP
f += "SDE (*.sde *.SDE);;";
f += "DLD (*.dld *.DLD);;";
#endif
#ifdef SQLITE3
f += "DB (*.db)";
#endif
return f;
}
bool MainWindow::askSaveChanges()
{
QString message = ! existing_filename ? tr("You have unsaved changes\nWould you like to save those before closing the datafile?")
: tr("You have unsaved changes to file: %1 \nWould you like to save those before closing the datafile?").arg(existing_filename);
if (QMessageBox::question(this, tr("Save Changes?"), message) == QMessageBox::Ok) {
// WARNING: Port.
// file_save(NULL,NULL);
return true;
}
return false;
}
void MainWindow::readSettings()
{
int i;
QSettings settings("hohndel.org","subsurface");
settings.beginGroup("MainWindow");
QSize sz = settings.value("size").value<QSize>();
resize(sz);
ui->mainSplitter->restoreState(settings.value("mainSplitter").toByteArray());
ui->infoProfileSplitter->restoreState(settings.value("infoProfileSplitter").toByteArray());
settings.endGroup();
settings.beginGroup("ListWidget");
/* if no width are set, use the calculated width for each column;
* for that to work we need to temporarily expand all rows */
ui->ListWidget->expandAll();
for (i = TreeItemDT::NR; i < TreeItemDT::COLUMNS; i++) {
QVariant width = settings.value(QString("colwidth%1").arg(i));
if (width.isValid())
ui->ListWidget->setColumnWidth(i, width.toInt());
else
ui->ListWidget->resizeColumnToContents(i);
}
ui->ListWidget->collapseAll();
settings.endGroup();
}
void MainWindow::writeSettings()
{
int i;
QSettings settings("hohndel.org","subsurface");
settings.beginGroup("MainWindow");
settings.setValue("size",size());
settings.setValue("mainSplitter", ui->mainSplitter->saveState());
settings.setValue("infoProfileSplitter", ui->infoProfileSplitter->saveState());
settings.endGroup();
settings.beginGroup("ListWidget");
for (i = TreeItemDT::NR; i < TreeItemDT::COLUMNS; i++)
settings.setValue(QString("colwidth%1").arg(i), ui->ListWidget->columnWidth(i));
settings.endGroup();
/* other groups here; avoid '/' and '\' in keys with setValue(...) please */
}
void MainWindow::closeEvent(QCloseEvent *event)
{
if (unsaved_changes() && (askSaveChanges() == FALSE)) {
event->ignore();
return;
}
event->accept();
writeSettings();
}
|