Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
qSlicerCoreApplication.h
Go to the documentation of this file.
1/*==============================================================================
2
3 Program: 3D Slicer
4
5 Copyright (c) Kitware Inc.
6
7 See COPYRIGHT.txt
8 or http://www.slicer.org/copyright/copyright.txt for details.
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
17 and was partially funded by NIH grant 3P41RR013218-12S1
18
19==============================================================================*/
20
21#ifndef __qSlicerCoreApplication_h
22#define __qSlicerCoreApplication_h
23
24// Qt includes
25#include <QApplication>
26#include <QMetaType>
27#include <QProcessEnvironment>
28#include <QStringList>
29#include <QVariant>
30
31// CTK includes
32#include <ctkVTKObject.h>
33
34// SlicerCore includes
35#include "vtkSlicerConfigure.h" // For Slicer_USE_PYTHONQT
36#include "qSlicerBaseQTCoreExport.h"
37
38#ifdef Slicer_BUILD_DICOM_SUPPORT
39class ctkDICOMDatabase;
40#endif
41class ctkErrorLogAbstractModel;
42class QSettings;
45class qSlicerCoreApplicationPrivate;
47#ifdef Slicer_USE_PYTHONQT
49class ctkPythonConsole;
50#endif
51#ifdef Slicer_BUILD_EXTENSIONMANAGER_SUPPORT
53#endif
54#ifdef Slicer_BUILD_APPLICATIONUPDATE_SUPPORT
56#endif
63class vtkMRMLScene;
64
65class Q_SLICER_BASE_QTCORE_EXPORT qSlicerCoreApplication : public QApplication
66{
67 Q_OBJECT
68 QVTK_OBJECT
69 Q_ENUMS(ReturnCode)
70
71
75 Q_PROPERTY(QString slicerHome READ slicerHome CONSTANT)
77 Q_PROPERTY(QString slicerSharePath READ slicerSharePath CONSTANT)
78 Q_PROPERTY(QString temporaryPath READ temporaryPath WRITE setTemporaryPath)
79 Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath)
80 Q_PROPERTY(QString startupWorkingPath READ startupWorkingPath CONSTANT)
82 Q_PROPERTY(QString launcherSettingsFilePath READ launcherSettingsFilePath CONSTANT)
87 Q_PROPERTY(QString intDir READ intDir CONSTANT)
88 Q_PROPERTY(bool isInstalled READ isInstalled CONSTANT)
89 Q_PROPERTY(QString releaseType READ releaseType CONSTANT)
90 Q_PROPERTY(QString repositoryUrl READ repositoryUrl CONSTANT)
91 Q_PROPERTY(QString repositoryBranch READ repositoryBranch CONSTANT)
92 Q_PROPERTY(QString repositoryRevision READ repositoryRevision CONSTANT)
93 Q_PROPERTY(QString revision READ revision CONSTANT)
94 Q_PROPERTY(int majorVersion READ majorVersion CONSTANT)
95 Q_PROPERTY(int minorVersion READ minorVersion CONSTANT)
96 Q_PROPERTY(QLocale applicationLocale READ applicationLocale CONSTANT)
97 Q_PROPERTY(QString applicationLocaleName READ applicationLocaleName CONSTANT)
99 Q_PROPERTY(QString documentationVersion READ documentationVersion CONSTANT)
100 Q_PROPERTY(QString documentationLanguage READ documentationLanguage CONSTANT)
101 Q_PROPERTY(QString platform READ platform CONSTANT)
102 Q_PROPERTY(QString arch READ arch CONSTANT)
103 Q_PROPERTY(QString os READ os CONSTANT)
105 Q_PROPERTY(QString mainApplicationName READ mainApplicationName CONSTANT)
108 Q_PROPERTY(QString mainApplicationRevision READ mainApplicationRevision CONSTANT)
113
114public:
115
116 typedef QApplication Superclass;
117 qSlicerCoreApplication(int &argc, char **argv);
119
124
132
134 static void setAttribute(qSlicerCoreApplication::ApplicationAttribute attribute, bool on = true);
135
138
155 Q_INVOKABLE QProcessEnvironment startupEnvironment() const;
156
158 QString startupWorkingPath() const;
159
170 Q_INVOKABLE QProcessEnvironment environment() const;
171
176 Q_INVOKABLE void setEnvironmentVariable(const QString& key, const QString& value);
177
179 Q_INVOKABLE bool isEnvironmentVariableValueSet(const QString& key, const QString& value);
180
183 Q_INVOKABLE void prependEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
184
187 Q_INVOKABLE void appendEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
188
191 void parseArguments(bool& exitWhenDone);
192
195 ExitSuccess = EXIT_SUCCESS,
196 ExitFailure = EXIT_FAILURE
197 };
198
212 int returnCode()const;
213
224 static int exec();
225
227 Q_INVOKABLE vtkMRMLScene* mrmlScene() const;
228
231
232 // Convenience method for getting a module logic from the application logic.
233 Q_INVOKABLE vtkMRMLAbstractLogic* moduleLogic(const QString& moduleName)const;
234
237 QString slicerHome() const;
238
243 QString defaultScenePath() const;
244
246 void setDefaultScenePath(const QString& path);
247
254 QString slicerSharePath() const;
255
258 bool isEmbeddedModule(const QString& moduleFileName)const;
259
261 QString defaultTemporaryPath() const;
262
264 QString temporaryPath() const;
265
267 void setTemporaryPath(const QString& path);
268
271 QString defaultCachePath() const;
272
276 QString cachePath() const;
277
280 void setCachePath(const QString& path);
281
284
287
290
294
298
302
305
307 QString extensionsInstallPath() const;
308
310 void setExtensionsInstallPath(const QString& path);
311
314 QString intDir()const;
315
317 bool isInstalled()const;
318
322 QString releaseType()const;
323
328 Q_INVOKABLE void addModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
329
331 Q_INVOKABLE void removeModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
332
334 Q_INVOKABLE QStringList modulesAssociatedWithNodeType(const QString& nodeClassName) const;
335
337 Q_INVOKABLE QStringList allModuleAssociatedNodeTypes() const;
338
339#ifdef Slicer_USE_PYTHONQT
341 qSlicerCorePythonManager* corePythonManager()const;
342
345 void setCorePythonManager(qSlicerCorePythonManager* pythonManager);
346
348 ctkPythonConsole* pythonConsole()const;
349
354 void setPythonConsole(ctkPythonConsole* pythonConsole);
355
356#endif
357
358#ifdef Slicer_BUILD_EXTENSIONMANAGER_SUPPORT
360 Q_INVOKABLE qSlicerExtensionsManagerModel* extensionsManagerModel()const;
361
364 void setExtensionsManagerModel(qSlicerExtensionsManagerModel* model);
365#endif
366
367#ifdef Slicer_BUILD_APPLICATIONUPDATE_SUPPORT
369 Q_INVOKABLE qSlicerApplicationUpdateManager* applicationUpdateManager()const;
370
373 void setapplicationUpdateManager(qSlicerApplicationUpdateManager* model);
374#endif
375
377 Q_INVOKABLE ctkErrorLogAbstractModel* errorLogModel()const;
378
381
384
388
391
395
398 Q_INVOKABLE QSettings* defaultSettings()const;
399
403 Q_INVOKABLE QSettings* userSettings()const;
404
408 Q_INVOKABLE QSettings* settings()const;
409
413 Q_INVOKABLE QSettings* revisionUserSettings()const;
414
417
419 QString mainApplicationName()const;
420
425
430
434
438
442
446
452 QString documentationBaseUrl()const;
453
457 QString documentationVersion()const;
458
463 QString documentationLanguage()const;
464
468 QLocale applicationLocale()const;
469
475 QString applicationLocaleName()const;
476
480 Q_INVOKABLE QString moduleDocumentationUrl(const QString &moduleName)const;
481
483 virtual QString copyrights()const;
484
486 virtual QString acknowledgment()const;
487
489 virtual QString libraries()const;
490
493 QString repositoryUrl()const;
494
497 QString repositoryBranch()const;
498
501 QString repositoryRevision()const;
502
504 QString revision()const;
505
507 int majorVersion() const;
508
510 int minorVersion() const;
511
514 QString platform()const;
515
518 QString arch()const;
519
522 QString os()const;
523
524#ifdef Slicer_BUILD_DICOM_SUPPORT
526 Q_INVOKABLE ctkDICOMDatabase* dicomDatabase() const;
527
530 QSharedPointer<ctkDICOMDatabase> dicomDatabaseShared() const;
531#endif
532
534 Q_INVOKABLE static QStringList translationFolders();
535
538 Q_INVOKABLE static void loadTranslations(const QString& dir);
539
542 Q_INVOKABLE static void loadLanguage();
543
549 Q_INVOKABLE static bool loadCaCertificates(const QString& slicerHome);
550
553 Q_INVOKABLE static QString caCertificatesPath(const QString& slicerHome);
554
555 Q_INVOKABLE int registerResource(const QByteArray& data);
556
559 Q_INVOKABLE void showConsoleMessage(QString message, bool error=true) const;
560
563 Q_INVOKABLE QString toSlicerHomeAbsolutePath(const QString& path) const;
564
567 Q_INVOKABLE QString toSlicerHomeRelativePath(const QString& path) const;
568
571 Q_INVOKABLE QStringList toSlicerHomeAbsolutePaths(const QStringList& path) const;
572
575 Q_INVOKABLE QStringList toSlicerHomeRelativePaths(const QStringList& path) const;
576
600 Q_INVOKABLE void logUsageEvent(const QString& component, const QString& event);
601
606
612 Q_INVOKABLE void handleURIArguments(const QStringList& fileNames);
613
624
625public slots:
626
629 static void restart();
630
631 bool unregisterResource(int handle);
632
639 virtual void setRenderPaused(bool pause) { Q_UNUSED(pause); };
642 virtual void pauseRender() {};
645 virtual void resumeRender() {};
646
650 virtual bool loadFiles(const QStringList& filePaths, vtkMRMLMessageCollection* userMessages=nullptr);
651
655 virtual void openUrl(const QString& url);
656
657protected:
658
663
666 virtual void setMRMLScene(vtkMRMLScene * scene);
667
668protected slots:
669
674
677 void onSlicerApplicationLogicRequest(vtkObject*, void* , unsigned long);
681
684 virtual void editNode(vtkObject*, void*, unsigned long) {};
685
688
690 virtual void onAboutToQuit();
691
696 void requestInvokeEvent(vtkObject* caller, void* callData);
697
701 void scheduleInvokeEvent(unsigned int delay, void* caller, unsigned long event, void* callData);
702
708
709signals:
711
715 void urlReceived(QString url);
716
719 void invokeEventRequested(unsigned int delay, void* caller,
720 unsigned long event, void* callData);
721
722 void usageEventLogged(const QString& component, const QString& event);
723
724protected:
725 qSlicerCoreApplication(qSlicerCoreApplicationPrivate* pimpl, int &argc, char **argv);
726 QScopedPointer<qSlicerCoreApplicationPrivate> d_ptr;
727
728private:
729 Q_DECLARE_PRIVATE(qSlicerCoreApplication);
730 Q_DISABLE_COPY(qSlicerCoreApplication);
731};
732
734
735
742class Q_SLICER_BASE_QTCORE_EXPORT SlicerRenderBlocker
743{
744public:
747 {
748 this->Application = qSlicerCoreApplication::application();
749 if (this->Application)
750 {
751 this->Application->pauseRender();
752 }
753 };
755 {
756 if (this->Application)
757 {
758 this->Application->resumeRender();
759 }
760 }
761};
762
763#endif
qSlicerCoreApplication * Application
Class querying application updates on the download server.
QString launcherSettingsFilePath() const
If any, return slicer launcher settings file path.
int mainApplicationMajorVersion() const
QString applicationLocaleName() const
QString defaultExtensionsInstallPath() const
Get slicer default extensions path.
virtual void onUserInformationModified()
void setDefaultScenePath(const QString &path)
Set default slicer scene directory.
void setCachePath(const QString &path)
virtual void onSlicerApplicationLogicModified()
Q_INVOKABLE void appendEnvironmentVariable(const QString &key, const QString &value, QChar separator=';')
qSlicerCoreCommandOptions * coreCommandOptions() const
Get coreCommandOptions.
Q_INVOKABLE ctkErrorLogAbstractModel * errorLogModel() const
Get errorLogModel.
Q_INVOKABLE int registerResource(const QByteArray &data)
virtual void openUrl(const QString &url)
Q_INVOKABLE QStringList toSlicerHomeRelativePaths(const QStringList &path) const
QString repositoryUrl() const
virtual void onAboutToQuit()
Perform application cleanup following a call to QCoreApplication::exit().
Q_INVOKABLE void setEnvironmentVariable(const QString &key, const QString &value)
Convenient function to set an environment variable.
QLocale applicationLocale() const
Q_INVOKABLE vtkSlicerApplicationLogic * applicationLogic() const
Get application logic.
QString mainApplicationName() const
Return the name of the main application.
void setTemporaryPath(const QString &path)
Set slicer temporary directory.
void setCoreCommandOptions(qSlicerCoreCommandOptions *options)
QString slicerHome() const
void requestInvokeEvent(vtkObject *caller, void *callData)
static Q_INVOKABLE QStringList translationFolders()
Return list of folders where the application looks for translations (*.qm files)
int minorVersion() const
Return the Slicer minor version number.
void setExtensionsInstallPath(const QString &path)
Set slicer extension directory.
virtual QString libraries() const
Return the libraries of Slicer.
static Q_INVOKABLE void loadLanguage()
QString launcherExecutableFilePath() const
If any, return slicer launcher executable file path.
Q_INVOKABLE void prependEnvironmentVariable(const QString &key, const QString &value, QChar separator=';')
void invokeEventRequested(unsigned int delay, void *caller, unsigned long event, void *callData)
static void restart()
}@
Q_INVOKABLE QProcessEnvironment environment() const
Returns the current environment.
QScopedPointer< qSlicerCoreApplicationPrivate > d_ptr
QString defaultTemporaryPath() const
Get slicer default temporary directory.
static Q_INVOKABLE bool loadCaCertificates(const QString &slicerHome)
virtual bool loadFiles(const QStringList &filePaths, vtkMRMLMessageCollection *userMessages=nullptr)
Q_INVOKABLE QString toSlicerHomeAbsolutePath(const QString &path) const
void terminate(int exitCode=qSlicerCoreApplication::ExitSuccess)
Set the ReturnCode flag and call QCoreApplication::exit()
Q_INVOKABLE qSlicerModuleManager * moduleManager() const
Get the module manager.
QString temporaryPath() const
Get slicer temporary directory.
Q_INVOKABLE bool isEnvironmentVariableValueSet(const QString &key, const QString &value)
Returns True if environment variable identified by key is set to value.
QString slicerRevisionUserSettingsFilePath() const
Q_INVOKABLE QString moduleDocumentationUrl(const QString &moduleName) const
Q_INVOKABLE QStringList toSlicerHomeAbsolutePaths(const QStringList &path) const
Q_INVOKABLE QSettings * settings() const
QString mainApplicationRevision() const
Q_INVOKABLE void addModuleAssociatedNodeType(const QString &nodeClassName, const QString &moduleName)
void onSlicerApplicationLogicRequest(vtkObject *, void *, unsigned long)
virtual void handleCommandLineArguments()
Q_INVOKABLE vtkMRMLAbstractLogic * moduleLogic(const QString &moduleName) const
static bool testAttribute(qSlicerCoreApplication::ApplicationAttribute attribute)
QString documentationLanguage() const
QString launcherRevisionSpecificUserSettingsFilePath() const
If any, return slicer user settings file path specific to a given revision of Slicer.
Q_INVOKABLE void showConsoleMessage(QString message, bool error=true) const
virtual QString copyrights() const
Return the copyrights of Slicer.
QString intDir() const
bool isUsageLoggingSupported() const
Q_INVOKABLE QSettings * userSettings() const
QString releaseType() const
Return the release type of this instance of Slicer.
QString extensionsInstallPath() const
Get slicer extension directory.
bool unregisterResource(int handle)
void setCoreIOManager(qSlicerCoreIOManager *ioManager)
qSlicerCoreApplication(qSlicerCoreApplicationPrivate *pimpl, int &argc, char **argv)
QString arch() const
void scheduleInvokeEvent(unsigned int delay, void *caller, unsigned long event, void *callData)
QString startupWorkingPath() const
Current working directory at the time the application was started.
QString mainApplicationRepositoryUrl() const
static qSlicerCoreApplication * application()
Q_INVOKABLE QStringList modulesAssociatedWithNodeType(const QString &nodeClassName) const
List of all modules that are associated with the specified node type.
QString slicerDefaultSettingsFilePath() const
void parseArguments(bool &exitWhenDone)
Q_INVOKABLE void handleURIArguments(const QStringList &fileNames)
int majorVersion() const
Return the Slicer major version number.
void urlReceived(QString url)
QString cachePath() const
void mrmlSceneChanged(vtkMRMLScene *mrmlScene)
QString slicerSharePath() const
QString mainApplicationRepositoryRevision() const
QString os() const
QString defaultScenePath() const
virtual void editNode(vtkObject *, void *, unsigned long)
Q_INVOKABLE QString toSlicerHomeRelativePath(const QString &path) const
bool isInstalled() const
Return true is this instance of Slicer is running from an installed directory.
QString documentationBaseUrl() const
bool isEmbeddedModule(const QString &moduleFileName) const
virtual void setRenderPaused(bool pause)
void usageEventLogged(const QString &component, const QString &event)
QString platform() const
virtual void handlePreApplicationCommandLineArguments()
void setURIArgumentHandlingEnabled(bool enabled)
qSlicerCoreApplication(int &argc, char **argv)
Q_INVOKABLE vtkMRMLScene * mrmlScene() const
Get MRML Scene.
int mainApplicationMinorVersion() const
static Q_INVOKABLE QString caCertificatesPath(const QString &slicerHome)
virtual QString acknowledgment() const
Return the acknowledgment text of Slicer.
QString documentationVersion() const
Q_INVOKABLE QStringList allModuleAssociatedNodeTypes() const
List of all node types that are associated with any module.
QString repositoryRevision() const
Q_INVOKABLE qSlicerCoreIOManager * coreIOManager() const
Get the IO manager.
QString repositoryBranch() const
static Q_INVOKABLE void loadTranslations(const QString &dir)
QString revision() const
Return Slicer's user-friendly revision identifier.
Q_INVOKABLE void removeModuleAssociatedNodeType(const QString &nodeClassName, const QString &moduleName)
Remove association between a module and a node type.
Q_INVOKABLE QProcessEnvironment startupEnvironment() const
Returns the environment without the Slicer specific values.
Q_INVOKABLE QSettings * defaultSettings() const
bool isCustomMainApplication() const
Return if main application is custom application (not Slicer).
QString slicerUserSettingsFilePath() const
Q_INVOKABLE void logUsageEvent(const QString &component, const QString &event)
bool isURIArgumentHandlingEnabled() const
QString defaultCachePath() const
static void setAttribute(qSlicerCoreApplication::ApplicationAttribute attribute, bool on=true)
int mainApplicationPatchVersion() const
Q_INVOKABLE QSettings * revisionUserSettings() const
virtual void setMRMLScene(vtkMRMLScene *scene)
Class querying and storing extensions data.
Superclass for MRML logic classes.
A set of MRML Nodes that supports serialization and undo/redo.
Q_DECLARE_METATYPE(qSlicerExtensionsManagerModel::ServerAPI)