Qt Virtual Chart Table (QVCT)
main.cpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Qt Virtual Chart Table (QVCT)
5  * Copyright (C) 2012 Cedric Dufour <http://cedric.dufour.name>
6  * Author: Cedric Dufour <http://cedric.dufour.name>
7  *
8  * The Qt Virtual Chart Table (QVCT) is free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Qt Virtual Chart Table (QVCT) is distributed in the hope
13  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU General Public License for more details.
17  */
18 
19 // C/C++
20 #include <sys/time.h>
21 
22 // QT
23 #include <QApplication>
24 #include <QDir>
25 #include <QTextCodec>
26 
27 // QVCT
28 #include "QVCTRuntime.hpp"
29 
30 double microtime()
31 {
32  timeval tTimeval;
33  gettimeofday( &tTimeval, 0 ) ;
34  return( (double)tTimeval.tv_sec + (double)tTimeval.tv_usec/1000000.0 );
35 }
36 
37 int main( int argc, char* argv[] )
38 {
39  // Application
40  QApplication qApplication( argc, argv );
41 
42  // Settings (load)
43  QString __qsSettingsFilename = QDir::homePath()+CONFDIR_STRING+"/settings.qvct";
44  CSettings* __poSettings = new CSettings();
45  QVCTRuntime::registerSettings( __poSettings );
46  __poSettings->load( __qsSettingsFilename );
47 
48  // Main window
49  CMainWindow* __poMainWindow = new CMainWindow();
50  QVCTRuntime::registerMainWindow( __poMainWindow );
51 
52  // Devices (load)
53  QString __qsDevicesFilename = QDir::homePath()+CONFDIR_STRING+"/devices.qvct";
54  CDeviceOverlay* __poDeviceOverlay = QVCTRuntime::useDeviceOverlay();
55  __poDeviceOverlay->load( __qsDevicesFilename, true );
56 
57  // Chart table
58  if( argc >= 2 ) QVCTRuntime::useChartTable()->load( argv[1] );
59 
60  // Main loop
61  __poMainWindow->restoreGeometry( QByteArray::fromBase64( __poSettings->getMainWindowGeometry().toLatin1() ) );
62  __poMainWindow->restoreState( QByteArray::fromBase64( __poSettings->getMainWindowState().toLatin1() ) );
63  __poMainWindow->show();
64  int __iExit = qApplication.exec();
65 
66  // Exit
67  if( !__iExit ) // if application terminated normally (exit=0)
68  {
69  // Devices (save)
70  __poDeviceOverlay->save( __qsDevicesFilename, 0, true );
71 
72  // Settings (save)
73  __poSettings->setMainWindowGeometry( QString( __poMainWindow->saveGeometry().toBase64() ) );
74  __poSettings->setMainWindowState( QString( __poMainWindow->saveState().toBase64() ) );
75  __poSettings->save( __qsSettingsFilename );
76  }
77 
78  delete __poMainWindow;
79  delete __poSettings;
81 
82  return __iExit;
83 }
void load(const QString &_rqsFilename)
Load a full project's content from the given file.
[UI] Device overlay container
void save(const QString &_rqsFilename, CDevice *_poDevice=0, bool _bApplicationDump=false) const
Save this object's content (device) to the given file (all selected items if no device is given)
CDevice * load(const QString &_rqsFilename, bool _bSilent=false)
Load this object's content from the given file and returns the last loaded device (0 if none)
[UI] Application main window
Definition: CMainWindow.hpp:36
[UI] Container for the application's settings
Definition: CSettings.hpp:51
void load(const QString &_rqsFilename)
Restore all parameters from the given file.
Definition: CSettings.cpp:592
QString getMainWindowState()
[Misc] Returns the main window state (Base64-encoded binary data)
Definition: CSettings.hpp:427
QString getMainWindowGeometry()
[Misc] Returns the main window geometry (Base64-encoded binary data)
Definition: CSettings.hpp:425
void setMainWindowState(const QString &_rqsMainWindowState)
[Misc] Sets the main window state (Base64-encoded binary data)
Definition: CSettings.hpp:327
void save(const QString &_rqsFilename) const
Store all parameters to the given file.
Definition: CSettings.cpp:364
void setMainWindowGeometry(const QString &_rqsMainWindowGeometry)
[Misc] Sets the main window geometry (Base64-encoded binary data)
Definition: CSettings.hpp:325
static void registerMainWindow(CMainWindow *_poMainWindow)
static CDeviceOverlay * useDeviceOverlay()
static void registerSettings(CSettings *_poSettings)
static void destroy()
Definition: QVCTRuntime.cpp:74
static CChartTable * useChartTable()
int main(int argc, char *argv[])
Definition: main.cpp:37
double microtime()
Returns the system time with microseconds resolution, in seconds.
Definition: main.cpp:30
#define CONFDIR_STRING
Definition: main.hpp:175