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

marble

  • sources
  • kde-4.14
  • 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 "MapThemeManager.h"
23 #include "MarbleDirs.h"
24 #include "MarbleDebug.h"
25 #include "MarbleTest.h"
26 #include "MarbleLocale.h"
27 #include "GeoUriParser.h"
28 
29 #ifdef STATIC_BUILD
30  #include <QtPlugin>
31  Q_IMPORT_PLUGIN(qjpeg)
32  Q_IMPORT_PLUGIN(qsvg)
33 #endif
34 
35 #ifdef Q_OS_MACX
36 //for getting app bundle path
37 #include <ApplicationServices/ApplicationServices.h>
38 #endif
39 
40 using namespace Marble;
41 
42 int main(int argc, char *argv[])
43 {
44 #if QT_VERSION < 0x050000
45  // The GraphicsSystem needs to be set before the instantiation of the
46  // QApplication. Therefore we need to parse the current setting
47  // in this unusual place :-/
48  QSettings graphicsSettings("KDE", "Marble Virtual Globe"); // keep the parameters here
49  QString const graphicsString = graphicsSettings.value("View/graphicsSystem", "raster").toString();
50  QApplication::setGraphicsSystem( graphicsString );
51 #endif
52 
53  QApplication app(argc, argv);
54  app.setApplicationName( "Marble Virtual Globe" );
55  app.setOrganizationName( "KDE" );
56  app.setOrganizationDomain( "kde.org" );
57  // Widget translation
58 
59  QString lang = QLocale::system().name().section('_', 0, 0);
60  QTranslator translator;
61  translator.load( "marble-" + lang, MarbleDirs::path(QString("lang") ) );
62  app.installTranslator(&translator);
63 
64  // For non static builds on mac and win
65  // we need to be sure we can find the qt image
66  // plugins. In mac be sure to look in the
67  // application bundle...
68 
69 #ifdef Q_WS_WIN
70  QApplication::addLibraryPath( QApplication::applicationDirPath()
71  + QDir::separator() + "plugins" );
72 #endif
73 #ifdef Q_OS_MACX
74  QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus);
75  qDebug("Adding qt image plugins to plugin search path...");
76  CFURLRef myBundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
77  CFStringRef myMacPath = CFURLCopyFileSystemPath(myBundleRef, kCFURLPOSIXPathStyle);
78  const char *mypPathPtr = CFStringGetCStringPtr(myMacPath,CFStringGetSystemEncoding());
79  CFRelease(myBundleRef);
80  CFRelease(myMacPath);
81  QString myPath(mypPathPtr);
82  // if we are not in a bundle assume that the app is built
83  // as a non bundle app and that image plugins will be
84  // in system Qt frameworks. If the app is a bundle
85  // lets try to set the qt plugin search path...
86  if (myPath.contains(".app"))
87  {
88  myPath += "/Contents/plugins";
89  QApplication::addLibraryPath( myPath );
90  qDebug( "Added %s to plugin search path", qPrintable( myPath ) );
91  }
92 #endif
93 
94  QString marbleDataPath;
95  int dataPathIndex=0;
96  QString mapThemeId;
97  QString coordinatesString;
98  QString distanceString;
99  QString geoUriString;
100  MarbleGlobal::Profiles profiles = MarbleGlobal::detectProfiles();
101 
102  QStringList args = QApplication::arguments();
103 
104  if ( args.contains( "-h" ) || args.contains( "--help" ) ) {
105  qWarning() << "Usage: marble [options] [files]";
106  qWarning();
107  qWarning() << "[files] can be zero, one or more .kml and/or .gpx files to load and show.";
108  qWarning();
109  qWarning() << "general options:";
110  qWarning() << " --marbledatapath=<path> .... Overwrite the compile-time path to map themes and other data";
111  qWarning() << " --geo-uri=<uri> ............ Show map at given geo uri";
112  qWarning() << " --latlon=<coordinates> ..... Show map at given lat lon coordinates";
113  qWarning() << " --distance=<value> ......... Set the distance of the observer to the globe (in km)";
114  qWarning() << " --map=<id> ................. Use map id (e.g. \"earth/openstreetmap/openstreetmap.dgml\")";
115  qWarning();
116  qWarning() << "debug options:";
117  qWarning() << " --debug-info ............... write (more) debugging information to the console";
118  qWarning() << " --fps ...................... Show the paint performance (paint rate) in the top left corner";
119  qWarning() << " --runtimeTrace.............. Show the time spent and other debug info of each layer";
120  qWarning() << " --tile-id................... Write the identifier of texture tiles on top of them";
121  qWarning() << " --timedemo ................. Measure the paint performance while moving the map and quit";
122  qWarning();
123  qWarning() << "profile options (note that marble should automatically detect which profile to use. Override that with the options below):";
124  qWarning() << " --highresolution ........... Enforce the profile for devices with high resolution (e.g. desktop computers)";
125  qWarning() << " --nohighresolution ......... Deactivate the profile for devices with high resolution (e.g. desktop computers)";
126 
127  return 0;
128  }
129 
130  for ( int i = 1; i < args.count(); ++i ) {
131  const QString arg = args.at(i);
132 
133  if ( arg == QLatin1String( "--debug-info" ) )
134  {
135  MarbleDebug::setEnabled( true );
136  }
137  else if ( arg.startsWith( QLatin1String( "--marbledatapath=" ), Qt::CaseInsensitive ) )
138  {
139  marbleDataPath = args.at(i).mid(17);
140  }
141  else if ( arg.compare( QLatin1String( "--marbledatapath" ), Qt::CaseInsensitive ) == 0 && i+1 < args.size() ) {
142  dataPathIndex = i + 1;
143  marbleDataPath = args.value( dataPathIndex );
144  ++i;
145  }
146  else if ( arg == QLatin1String( "--highresolution" ) ) {
147  profiles |= MarbleGlobal::HighResolution;
148  }
149  else if ( arg == QLatin1String( "--nohighresolution" ) ) {
150  profiles &= ~MarbleGlobal::HighResolution;
151  }
152  else if ( arg.startsWith( QLatin1String( "--latlon=" ), Qt::CaseInsensitive ) )
153  {
154  coordinatesString = arg.mid(9);
155  }
156  else if ( arg.compare( QLatin1String( "--latlon" ), Qt::CaseInsensitive ) == 0 && i+1 < args.size() ) {
157  ++i;
158  coordinatesString = args.value( i );
159  }
160  else if ( arg.compare( QLatin1String( "--geo-uri=" ), Qt::CaseInsensitive ) == 0 ) {
161  geoUriString = arg.mid(10);
162  }
163  else if ( arg.compare( QLatin1String( "--geo-uri" ), Qt::CaseInsensitive ) == 0 && i+1 < args.size() )
164  {
165  ++i;
166  geoUriString = args.value(i);
167  }
168  else if ( arg.startsWith( QLatin1String( "--distance=" ), Qt::CaseInsensitive ) )
169  {
170  distanceString = arg.mid(11);
171  }
172  else if ( arg.compare( QLatin1String( "--distance" ), Qt::CaseInsensitive ) == 0 && i+1 < args.size() ) {
173  ++i;
174  distanceString = args.value( i );
175  }
176  else if ( arg.startsWith( QLatin1String( "--map=" ), Qt::CaseInsensitive ) )
177  {
178  mapThemeId = arg.mid(6);
179  }
180  else if ( arg.compare( QLatin1String( "--map" ), Qt::CaseInsensitive ) == 0 && i+1 < args.size() ) {
181  ++i;
182  mapThemeId = args.value( i );
183  }
184  }
185  MarbleGlobal::getInstance()->setProfiles( profiles );
186 
187  MarbleLocale::MeasurementSystem const measurement =
188  (MarbleLocale::MeasurementSystem)QLocale::system().measurementSystem();
189  MarbleGlobal::getInstance()->locale()->setMeasurementSystem( measurement );
190 
191  QVariantMap cmdLineSettings;
192  if ( !mapThemeId.isEmpty() ) {
193  cmdLineSettings.insert( QLatin1String("mapTheme"), QVariant(mapThemeId) );
194  }
195 
196  if ( !coordinatesString.isEmpty() ) {
197  bool success = false;
198  const GeoDataCoordinates coordinates = GeoDataCoordinates::fromString(coordinatesString, success);
199  if ( success ) {
200  QVariantList lonLat;
201  lonLat << QVariant( coordinates.longitude(GeoDataCoordinates::Degree) )
202  << QVariant( coordinates.latitude(GeoDataCoordinates::Degree) );
203  cmdLineSettings.insert( QLatin1String("lonlat"), QVariant(lonLat) );
204  }
205  }
206  if ( !distanceString.isEmpty() ) {
207  bool success = false;
208  const qreal distance = distanceString.toDouble(&success);
209  if ( success ) {
210  cmdLineSettings.insert( QLatin1String("distance"), QVariant(distance) );
211  }
212  }
213 
214  cmdLineSettings.insert( QLatin1String("geo-uri"), QVariant(geoUriString) );
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:148
Marble::MarbleGlobal::HighResolution
Definition: MarbleGlobal.h:288
main
int main(int argc, char *argv[])
Definition: qtmain.cpp:42
Marble::MarbleDirs::path
static QString path(const QString &relativePath)
Definition: MarbleDirs.cpp:59
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:959
QList::at
const T & at(int i) const
QApplication
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QWidget::setAttribute
void setAttribute(Qt::WidgetAttribute attribute, bool on)
QCoreApplication::setOrganizationDomain
void setOrganizationDomain(const QString &orgDomain)
QCoreApplication::setAttribute
void setAttribute(Qt::ApplicationAttribute attribute, bool on)
QFile::exists
bool exists() const
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
QLocale::measurementSystem
MeasurementSystem measurementSystem() const
QString::toDouble
double toDouble(bool *ok) const
MarbleDebug.h
Marble::MarbleLocale::MeasurementSystem
MeasurementSystem
Definition: MarbleLocale.h:37
QDir::separator
QChar separator()
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
QCoreApplication::addLibraryPath
void addLibraryPath(const QString &path)
QList::size
int size() const
QLocale::system
QLocale system()
QList::value
T value(int i) const
QWidget::resize
void resize(int w, int h)
QList::count
int count(const T &value) const
MarbleDirs.h
QString::isEmpty
bool isEmpty() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QLocale::name
QString name() const
QCoreApplication::instance
QCoreApplication * instance()
Marble::MarbleGlobal::locale
MarbleLocale * locale() const
Definition: MarbleGlobal.cpp:43
QString
MarbleLocale.h
Marble::MarbleTest
Definition: MarbleTest.h:24
QStringList
QtMainWindow.h
QSettings
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
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QTranslator::load
bool load(const QString &filename, const QString &directory, const QString &search_delimiters, const QString &suffix)
Marble::MarbleGlobal::getInstance
static MarbleGlobal * getInstance()
Definition: MarbleGlobal.cpp:37
MarbleTest.h
Marble::MainWindow
Definition: KdeMainWindow.h:29
QCoreApplication::installTranslator
void installTranslator(QTranslator *translationFile)
Marble::MarbleTest::timeDemo
void timeDemo()
Definition: MarbleTest.cpp:31
QSettings::value
QVariant value(const QString &key, const QVariant &defaultValue) const
QApplication::exec
int exec()
QString::mid
QString mid(int position, int n) const
QLatin1String
QApplication::setGraphicsSystem
void setGraphicsSystem(const QString &system)
QString::section
QString section(QChar sep, int start, int end, QFlags< QString::SectionFlag > flags) const
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:964
QTranslator
Marble::MarbleGlobal
Definition: MarbleGlobal.h:277
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:153
Marble::MarbleDebug::setEnabled
static void setEnabled(bool enabled)
setEnabled Toggle debug information output generation
Definition: MarbleDebug.cpp:52
Marble::MarbleLocale::setMeasurementSystem
void setMeasurementSystem(MarbleLocale::MeasurementSystem measurementSystem)
Definition: MarbleLocale.cpp:40
QCoreApplication::arguments
QStringList arguments()
Marble::ControlView::marbleWidget
MarbleWidget * marbleWidget()
Definition: ControlView.h:60
QCoreApplication::applicationDirPath
QString applicationDirPath()
QCoreApplication::setOrganizationName
void setOrganizationName(const QString &orgName)
QString::compare
int compare(const QString &other) const
GeoUriParser.h
Marble::MainWindow::addGeoDataFile
void addGeoDataFile(const QString &path)
Definition: MobileMainWindow.cpp:197
QVariant::toString
QString toString() const
MapThemeManager.h
Marble::MarbleWidget::setShowFrameRate
void setShowFrameRate(bool visible)
Set whether the frame rate gets shown.
Definition: MarbleWidget.cpp:945
QCoreApplication::setApplicationName
void setApplicationName(const QString &application)
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:41 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
  • 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