[PATCH 1/2] Delay Qt ui construction
amit.k.chaudhuri at gmail.com
amit.k.chaudhuri at gmail.com
Thu Apr 18 00:59:31 PDT 2013
From: Amit Chaudhuri <amit.k.chaudhuri at gmail.com>
The Qt ui will need to read the dive_table to populate widgets with
dives. Gtk functionality in init_ui is required to parse the dives.
Split init_ui to allow parsing to proceed and complete before Qt ui
mainwindow constructor is called.
Play with qDebug()'s printf style (Thiago!)
Signed-off-by: Amit Chaudhuri <amit.k.chaudhuri at gmail.com>
---
dive.h | 1 +
divelist.c | 1 -
main.c | 7 ++++---
qt-gui.cpp | 13 ++++++++-----
qt-ui/mainwindow.cpp | 4 ++++
5 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/dive.h b/dive.h
index 734aa22..2662397 100644
--- a/dive.h
+++ b/dive.h
@@ -602,6 +602,7 @@ extern void add_event(struct divecomputer *dc, int time, int type, int flags, in
/* UI related protopypes */
extern void init_ui(int *argcp, char ***argvp);
+extern void init_qt_ui(int *argcp, char ***argvp);
extern void run_ui(void);
extern void exit_ui(void);
diff --git a/divelist.c b/divelist.c
index 61b9116..088b0e6 100644
--- a/divelist.c
+++ b/divelist.c
@@ -492,7 +492,6 @@ void get_suit(struct dive *dive, char **str)
/*
* helper functions for dive_trip handling
*/
-
#ifdef DEBUG_TRIP
void dump_trip_list(void)
{
diff --git a/main.c b/main.c
index 3c0ea73..bf3bc08 100644
--- a/main.c
+++ b/main.c
@@ -335,7 +335,7 @@ int main(int argc, char **argv)
subsurface_command_line_init(&argc, &argv);
parse_xml_init();
- init_ui(&argc, &argv);
+ init_ui(&argc, &argv); /* the gtk stuff is needed for parsing below */
for (i = 1; i < argc; i++) {
const char *a = argv[i];
@@ -372,12 +372,13 @@ int main(int argc, char **argv)
report_dives(imported, FALSE);
if (dive_table.nr == 0)
show_dive_info(NULL);
- run_ui();
- exit_ui();
parse_xml_exit();
subsurface_command_line_exit(&argc, &argv);
+ init_qt_ui(&argc, &argv); /* qt bit delayed until dives are parsed */
+ run_ui();
+ exit_ui();
#ifdef DEBUGFILE
if (debugfile)
fclose(debugfile);
diff --git a/qt-gui.cpp b/qt-gui.cpp
index 7454577..86731bb 100644
--- a/qt-gui.cpp
+++ b/qt-gui.cpp
@@ -1864,6 +1864,14 @@ QStringList MainWindow::fileNameFilters() const
}
#endif /* NEEDS_TO_MOVE_TO_QT_UI */
+void init_qt_ui(int *argcp, char ***argvp)
+{
+ application = new QApplication(*argcp, *argvp);
+ application->installTranslator(new Translator(application));
+ MainWindow *window = new MainWindow();
+ window->show();
+}
+
void init_ui(int *argcp, char ***argvp)
{
GtkWidget *win;
@@ -1877,11 +1885,6 @@ void init_ui(int *argcp, char ***argvp)
GtkSettings *settings;
GtkUIManager *ui_manager;
- application = new QApplication(*argcp, *argvp);
- application->installTranslator(new Translator(application));
- MainWindow *window = new MainWindow();
- window->show();
-
gtk_init(argcp, argvp);
settings = gtk_settings_get_default();
gtk_settings_set_long_property(settings, "gtk-tooltip-timeout", 10, "subsurface setting");
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 577b7fb..e81d9de 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -46,6 +46,10 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow())
dive = new DiveItem(1,QString("01/03/13"),14.2, 29.0,QString("Wraysbury"),root);
Q_UNUSED(dive)
+
+ qDebug("dive_table checks - number of dives is %d", dive_table.nr);
+ qDebug("# allocated dives = %d, pre-existing = %d",
+ dive_table.allocated, dive_table.preexisting);
}
--
1.7.10.4
More information about the subsurface
mailing list