Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
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)
109 Q_PROPERTY(QString mainApplicationRevision READ mainApplicationRevision CONSTANT)
114
115public:
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
194 {
196 ExitSuccess = EXIT_SUCCESS,
197 ExitFailure = EXIT_FAILURE
198 };
199
213 int returnCode() const;
214
225 static int exec();
226
228 Q_INVOKABLE vtkMRMLScene* mrmlScene() const;
229
232
233 // Convenience method for getting a module logic from the application logic.
234 Q_INVOKABLE vtkMRMLAbstractLogic* moduleLogic(const QString& moduleName) const;
235
238 QString slicerHome() const;
239
244 QString defaultScenePath() const;
245
247 void setDefaultScenePath(const QString& path);
248
255 QString slicerSharePath() const;
256
259 bool isEmbeddedModule(const QString& moduleFileName) const;
260
262 QString defaultTemporaryPath() const;
263
265 QString temporaryPath() const;
266
268 void setTemporaryPath(const QString& path);
269
272 QString defaultCachePath() const;
273
277 QString cachePath() const;
278
281 void setCachePath(const QString& path);
282
285
288
291
295
299
303
306
308 QString extensionsInstallPath() const;
309
311 void setExtensionsInstallPath(const QString& path);
312
315 QString intDir() const;
316
318 bool isInstalled() const;
319
323 QString releaseType() const;
324
329 Q_INVOKABLE void addModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
330
332 Q_INVOKABLE void removeModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
333
335 Q_INVOKABLE QStringList modulesAssociatedWithNodeType(const QString& nodeClassName) const;
336
338 Q_INVOKABLE QStringList allModuleAssociatedNodeTypes() const;
339
340#ifdef Slicer_USE_PYTHONQT
342 qSlicerCorePythonManager* corePythonManager() const;
343
346 void setCorePythonManager(qSlicerCorePythonManager* pythonManager);
347
349 ctkPythonConsole* pythonConsole() const;
350
355 void setPythonConsole(ctkPythonConsole* pythonConsole);
356
357#endif
358
359#ifdef Slicer_BUILD_EXTENSIONMANAGER_SUPPORT
361 Q_INVOKABLE qSlicerExtensionsManagerModel* extensionsManagerModel() const;
362
365 void setExtensionsManagerModel(qSlicerExtensionsManagerModel* model);
366#endif
367
368#ifdef Slicer_BUILD_APPLICATIONUPDATE_SUPPORT
370 Q_INVOKABLE qSlicerApplicationUpdateManager* applicationUpdateManager() const;
371
374 void setapplicationUpdateManager(qSlicerApplicationUpdateManager* model);
375#endif
376
378 Q_INVOKABLE ctkErrorLogAbstractModel* errorLogModel() const;
379
382
385
389
392
396
399 Q_INVOKABLE QSettings* defaultSettings() const;
400
404 Q_INVOKABLE QSettings* userSettings() const;
405
409 Q_INVOKABLE QSettings* settings() const;
410
414 Q_INVOKABLE QSettings* revisionUserSettings() const;
415
418
422 QString mainApplicationName() const;
423
429
434
439
442 QString mainApplicationRevision() const;
443
447
451
455
461 QString documentationBaseUrl() const;
462
466 QString documentationVersion() const;
467
472 QString documentationLanguage() const;
473
477 QLocale applicationLocale() const;
478
484 QString applicationLocaleName() const;
485
489 Q_INVOKABLE QString moduleDocumentationUrl(const QString& moduleName) const;
490
492 virtual QString copyrights() const;
493
495 virtual QString acknowledgment() const;
496
498 virtual QString libraries() const;
499
502 QString repositoryUrl() const;
503
506 QString repositoryBranch() const;
507
510 QString repositoryRevision() const;
511
513 QString revision() const;
514
516 int majorVersion() const;
517
519 int minorVersion() const;
520
523 QString platform() const;
524
527 QString arch() const;
528
531 QString os() const;
532
533#ifdef Slicer_BUILD_DICOM_SUPPORT
535 Q_INVOKABLE ctkDICOMDatabase* dicomDatabase() const;
536
539 QSharedPointer<ctkDICOMDatabase> dicomDatabaseShared() const;
540#endif
541
543 Q_INVOKABLE static QStringList translationFolders();
544
547 Q_INVOKABLE static void loadTranslations(const QString& dir);
548
551 Q_INVOKABLE static void loadLanguage();
552
558 Q_INVOKABLE static bool loadCaCertificates(const QString& slicerHome);
559
562 Q_INVOKABLE static QString caCertificatesPath(const QString& slicerHome);
563
564 Q_INVOKABLE int registerResource(const QByteArray& data);
565
568 Q_INVOKABLE void showConsoleMessage(QString message, bool error = true) const;
569
572 Q_INVOKABLE QString toSlicerHomeAbsolutePath(const QString& path) const;
573
576 Q_INVOKABLE QString toSlicerHomeRelativePath(const QString& path) const;
577
580 Q_INVOKABLE QStringList toSlicerHomeAbsolutePaths(const QStringList& path) const;
581
584 Q_INVOKABLE QStringList toSlicerHomeRelativePaths(const QStringList& path) const;
585
609 Q_INVOKABLE void logUsageEvent(const QString& component, const QString& event);
610
615
621 Q_INVOKABLE void handleURIArguments(const QStringList& fileNames);
622
633
634public slots:
635
638 static void restart();
639
640 bool unregisterResource(int handle);
641
648 virtual void setRenderPaused(bool pause) { Q_UNUSED(pause); };
651 virtual void pauseRender() {};
654 virtual void resumeRender() {};
655
659 virtual bool loadFiles(const QStringList& filePaths, vtkMRMLMessageCollection* userMessages = nullptr);
660
664 virtual void openUrl(const QString& url);
665
666protected:
671
674 virtual void setMRMLScene(vtkMRMLScene* scene);
675
676protected slots:
677
682
685 void onSlicerApplicationLogicRequest(vtkObject*, void*, unsigned long);
689
692 virtual void editNode(vtkObject*, void*, unsigned long) {};
693
696
698 virtual void onAboutToQuit();
699
704 void requestInvokeEvent(vtkObject* caller, void* callData);
705
709 void scheduleInvokeEvent(unsigned int delay, void* caller, unsigned long event, void* callData);
710
716
717signals:
719
723 void urlReceived(QString url);
724
727 void invokeEventRequested(unsigned int delay, void* caller, unsigned long event, void* callData);
728
729 void usageEventLogged(const QString& component, const QString& event);
730
731protected:
732 qSlicerCoreApplication(qSlicerCoreApplicationPrivate* pimpl, int& argc, char** argv);
733 QScopedPointer<qSlicerCoreApplicationPrivate> d_ptr;
734
735private:
736 Q_DECLARE_PRIVATE(qSlicerCoreApplication);
737 Q_DISABLE_COPY(qSlicerCoreApplication);
738};
739
741
742
749class Q_SLICER_BASE_QTCORE_EXPORT SlicerRenderBlocker
750{
751public:
754 {
755 this->Application = qSlicerCoreApplication::application();
756 if (this->Application)
757 {
758 this->Application->pauseRender();
759 }
760 };
762 {
763 if (this->Application)
764 {
765 this->Application->resumeRender();
766 }
767 }
768};
769
770#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. This property represents the internal, programmatic name of ...
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 mainApplicationDisplayName() const
Return the display name of the main application. This property represents the user-visible name of th...
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)