• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • apps
  • marble-qt
qtmain.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2006-2007 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007 Inge Wallin <ingwa@kde.org>
10 //
11 
12 #include <QApplication>
13 #include <QFile>
14 #include <QDir>
15 #include <QLocale>
16 #include <QSettings>
17 #include <QTranslator>
18 #include <QProcessEnvironment>
19 
20 #include "QtMainWindow.h"
21 
22 #include "MarbleDirs.h"
23 #include "MarbleDebug.h"
24 #include "MarbleTest.h"
25 #include "MarbleLocale.h"
26 
27 #ifdef STATIC_BUILD
28  #include <QtPlugin>
29  Q_IMPORT_PLUGIN(qjpeg)
30  Q_IMPORT_PLUGIN(qsvg)
31 #endif
32 
33 #ifdef Q_OS_MACX
34 //for getting app bundle path
35 #include <ApplicationServices/ApplicationServices.h>
36 #endif
37 
38 using namespace Marble;
39 
40 int main(int argc, char *argv[])
41 {
42 #if QT_VERSION < 0x050000
43  // The GraphicsSystem needs to be set before the instantiation of the
44  // QApplication. Therefore we need to parse the current setting
45  // in this unusual place :-/
46  QSettings graphicsSettings("KDE", "Marble Virtual Globe"); // keep the parameters here
47  QString const graphicsString = graphicsSettings.value("View/graphicsSystem", "raster").toString();
48  QApplication::setGraphicsSystem( graphicsString );
49 #endif
50 
51 #ifdef Q_OS_MACX
52  if ( QSysInfo::MacintoshVersion > QSysInfo::MV_10_8 )
53  {
54  // fix Mac OS X 10.9 (mavericks) font issue
55  // https://bugreports.qt-project.org/browse/QTBUG-32789
56  QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande");
57  }
58 #endif
59 
60  QApplication app(argc, argv);
61  app.setApplicationName( "Marble Virtual Globe" );
62  app.setOrganizationName( "KDE" );
63  app.setOrganizationDomain( "kde.org" );
64  // Widget translation
65 
66  QString lang = QLocale::system().name().section('_', 0, 0);
67  QTranslator translator;
68  translator.load( "marble-" + lang, MarbleDirs::path(QString("lang") ) );
69  app.installTranslator(&translator);
70 
71  // For non static builds on mac and win
72  // we need to be sure we can find the qt image
73  // plugins. In mac be sure to look in the
74  // application bundle...
75 
76 #ifdef Q_WS_WIN
77  QApplication::addLibraryPath( QApplication::applicationDirPath()
78  + QDir::separator() + "plugins" );
79 #endif
80 #ifdef Q_OS_MACX
81  QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus);
82  qDebug("Adding qt image plugins to plugin search path...");
83  CFURLRef myBundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
84  CFStringRef myMacPath = CFURLCopyFileSystemPath(myBundleRef, kCFURLPOSIXPathStyle);
85  const char *mypPathPtr = CFStringGetCStringPtr(myMacPath,CFStringGetSystemEncoding());
86  CFRelease(myBundleRef);
87  CFRelease(myMacPath);
88  QString myPath(mypPathPtr);
89  // if we are not in a bundle assume that the app is built
90  // as a non bundle app and that image plugins will be
91  // in system Qt frameworks. If the app is a bundle
92  // lets try to set the qt plugin search path...
93  if (myPath.contains(".app"))
94  {
95  myPath += "/Contents/plugins";
96  QApplication::addLibraryPath( myPath );
97  qDebug( "Added %s to plugin search path", qPrintable( myPath ) );
98  }
99 #endif
100 
101  QString marbleDataPath;
102  int dataPathIndex=0;
103  QString mapThemeId;
104  QString coordinatesString;
105  QString distanceString;
106  MarbleGlobal::Profiles profiles = MarbleGlobal::detectProfiles();
107 
108  QStringList args = QApplication::arguments();
109 
110  if ( args.contains( "-h" ) || args.contains( "--help" ) ) {
111  qWarning() << "Usage: marble [options] [files]";
112  qWarning();
113  qWarning() << "[files] can be zero, one or more .kml and/or .gpx files to load and show.";
114  qWarning();
115  qWarning() << "general options:";
116  qWarning() << " --marbledatapath=<path> .... Overwrite the compile-time path to map themes and other data";
117  qWarning() << " --latlon=<coordinates> ..... Show map at given lat lon coordinates";
118  qWarning() << " --distance=<value> ......... Set the distance of the observer to the globe (in km)";
119  qWarning() << " --map=<id> ................. Use map id (e.g. \"earth/openstreetmap/openstreetmap.dgml\")";
120  qWarning();
121  qWarning() << "debug options:";
122  qWarning() << " --debug-info ............... write (more) debugging information to the console";
123  qWarning() << " --fps ...................... Show the paint performance (paint rate) in the top left corner";
124  qWarning() << " --runtimeTrace.............. Show the time spent and other debug info of each layer";
125  qWarning() << " --tile-id................... Write the identifier of texture tiles on top of them";
126  qWarning() << " --timedemo ................. Measure the paint performance while moving the map and quit";
127  qWarning();
128  qWarning() << "profile options (note that marble should automatically detect which profile to use. Override that with the options below):";
129  qWarning() << " --highresolution ........... Enforce the profile for devices with high resolution (e.g. desktop computers)";
130  qWarning() << " --nohighresolution ......... Deactivate the profile for devices with high resolution (e.g. desktop computers)";
131 
132  return 0;
133  }
134 
135  for ( int i = 1; i < args.count(); ++i ) {
136  const QString arg = args.at(i);
137 
138  if ( arg == QLatin1String( "--debug-info" ) )
139  {
140  MarbleDebug::setEnabled( true );
141  }
142  else if ( arg.startsWith( QLatin1String( "--marbledatapath=" ), Qt::CaseInsensitive ) )
143  {
144  marbleDataPath = args.at(i).mid(17);
145  }
146  else if ( arg.compare( QLatin1String( "--marbledatapath" ), Qt::CaseInsensitive ) == 0 ) {
147  dataPathIndex = i + 1;
148  marbleDataPath = args.value( dataPathIndex );
149  ++i;
150  }
151  else if ( arg == QLatin1String( "--highresolution" ) ) {
152  profiles |= MarbleGlobal::HighResolution;
153  }
154  else if ( arg == QLatin1String( "--nohighresolution" ) ) {
155  profiles &= ~MarbleGlobal::HighResolution;
156  }
157  else if ( arg.startsWith( QLatin1String( "--latlon=" ), Qt::CaseInsensitive ) )
158  {
159  coordinatesString = arg.mid(9);
160  }
161  else if ( arg.compare( QLatin1String( "--latlon" ), Qt::CaseInsensitive ) == 0 ) {
162  ++i;
163  // TODO: misses an error check if there is a value at all
164  // and error reporting to user (problem also exists with marbledatapath)
165  coordinatesString = args.value( i );
166  }
167  else if ( arg.startsWith( QLatin1String( "--distance=" ), Qt::CaseInsensitive ) )
168  {
169  distanceString = arg.mid(11);
170  }
171  else if ( arg.compare( QLatin1String( "--distance" ), Qt::CaseInsensitive ) == 0 ) {
172  ++i;
173  // TODO: misses an error check if there is a value at all
174  // and error reporting to user (problem also exists with marbledatapath)
175  distanceString = args.value( i );
176  }
177  else if ( arg.startsWith( QLatin1String( "--map=" ), Qt::CaseInsensitive ) )
178  {
179  mapThemeId = arg.mid(6);
180  }
181  else if ( arg.compare( QLatin1String( "--map" ), Qt::CaseInsensitive ) == 0 ) {
182  ++i;
183  // TODO: misses an error check if there is a value at all
184  // and error reporting to user (problem also exists with marbledatapath)
185  mapThemeId = args.value( i );
186  }
187  }
188  MarbleGlobal::getInstance()->setProfiles( profiles );
189 
190  QLocale::MeasurementSystem const measurement = QLocale::system().measurementSystem();
191  MarbleGlobal::getInstance()->locale()->setMeasurementSystem( measurement );
192 
193  QVariantMap cmdLineSettings;
194  if ( !mapThemeId.isEmpty() ) {
195  cmdLineSettings.insert( QLatin1String("mapTheme"), QVariant(mapThemeId) );
196  }
197 
198  if ( !coordinatesString.isEmpty() ) {
199  bool success = false;
200  const GeoDataCoordinates coordinates = GeoDataCoordinates::fromString(coordinatesString, success);
201  if ( success ) {
202  QVariantList lonLat;
203  lonLat << QVariant( coordinates.longitude(GeoDataCoordinates::Degree) )
204  << QVariant( coordinates.latitude(GeoDataCoordinates::Degree) );
205  cmdLineSettings.insert( QLatin1String("lonlat"), QVariant(lonLat) );
206  }
207  }
208  if ( !distanceString.isEmpty() ) {
209  bool success = false;
210  const qreal distance = distanceString.toDouble(&success);
211  if ( success ) {
212  cmdLineSettings.insert( QLatin1String("distance"), QVariant(distance) );
213  }
214  }
215 
216  MainWindow *window = new MainWindow( marbleDataPath, cmdLineSettings );
217  window->setAttribute( Qt::WA_DeleteOnClose, true );
218 
219 // window->marbleWidget()->rotateTo( 0, 0, -90 );
220 // window->show();
221 
222  for ( int i = 1; i < args.count(); ++i ) {
223  const QString arg = args.at(i);
224  if ( arg == "--timedemo" )
225  {
226  window->resize(900, 640);
227  MarbleTest marbleTest( window->marbleWidget() );
228  marbleTest.timeDemo();
229  return 0;
230  }
231  else if( arg == "--fps" ) {
232  window->marbleControl()->marbleWidget()->setShowFrameRate( true );
233  }
234  else if ( arg == "--tile-id" )
235  {
236  window->marbleControl()->marbleWidget()->setShowTileId(true);
237  }
238  else if( arg == "--runtimeTrace" ) {
239  window->marbleControl()->marbleWidget()->setShowRuntimeTrace( true );
240  }
241  else if ( i != dataPathIndex && QFile::exists( arg ) )
242  window->addGeoDataFile( arg );
243  }
244 
245  return app.exec();
246 }
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::MarbleGlobal::setProfiles
void setProfiles(Profiles profiles)
Definition: MarbleGlobal.cpp:52
Marble::MainWindow::marbleControl
ControlView * marbleControl() const
Definition: KdeMainWindow.cpp:74
Marble::MarbleGlobal::HighResolution
Definition: MarbleGlobal.h:269
main
int main(int argc, char *argv[])
Definition: qtmain.cpp:40
Marble::MarbleDirs::path
static QString path(const QString &relativePath)
Definition: MarbleDirs.cpp:53
Marble::MarbleGlobal::detectProfiles
static Profiles detectProfiles()
Automatically detects the profile.
Definition: MarbleGlobal.cpp:56
Marble::MarbleWidget::setShowRuntimeTrace
void setShowRuntimeTrace(bool visible)
Set whether the runtime tracing for layers gets shown.
Definition: MarbleWidget.cpp:1065
Marble::MarbleLocale::setMeasurementSystem
void setMeasurementSystem(QLocale::MeasurementSystem measurementSystem)
Definition: MarbleLocale.cpp:40
Marble::GeoDataCoordinates::latitude
qreal latitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
Definition: GeoDataCoordinates.cpp:751
MarbleDebug.h
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
MarbleDirs.h
Marble::MarbleGlobal::locale
MarbleLocale * locale() const
Definition: MarbleGlobal.cpp:43
MarbleLocale.h
Marble::MarbleTest
Definition: MarbleTest.h:24
QtMainWindow.h
Marble::GeoDataCoordinates::longitude
qreal longitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
Definition: GeoDataCoordinates.cpp:739
Marble::ControlView::marbleWidget
MarbleWidget * marbleWidget() const
Definition: ControlView.h:59
Marble::MarbleGlobal::getInstance
static MarbleGlobal * getInstance()
Definition: MarbleGlobal.cpp:37
MarbleTest.h
Marble::MainWindow
Definition: KdeMainWindow.h:26
Marble::MarbleTest::timeDemo
void timeDemo()
Definition: MarbleTest.cpp:31
Marble::MarbleWidget::setShowTileId
void setShowTileId(bool visible)
Set whether the is tile is visible NOTE: This is part of the transitional debug API and might be subj...
Definition: MarbleWidget.cpp:1070
Marble::MarbleGlobal
Definition: MarbleGlobal.h:258
Marble::GeoDataCoordinates::fromString
static GeoDataCoordinates fromString(const QString &string, bool &successful)
try to parse the string into a coordinate pair
Definition: GeoDataCoordinates.cpp:909
Marble::MainWindow::marbleWidget
MarbleWidget * marbleWidget() const
Definition: KdeMainWindow.cpp:79
Marble::MarbleDebug::setEnabled
static void setEnabled(bool enabled)
setEnabled Toggle debug information output generation
Definition: MarbleDebug.cpp:47
Marble::MainWindow::addGeoDataFile
void addGeoDataFile(const QString &path)
Definition: MobileMainWindow.cpp:197
Marble::MarbleWidget::setShowFrameRate
void setShowFrameRate(bool visible)
Set whether the frame rate gets shown.
Definition: MarbleWidget.cpp:1051
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal