2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2017-01-20 10:55:49 +00:00
|
|
|
Copyright 2006-2017 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
This file is part of QElectroTech.
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2007-12-01 10:47:15 +00:00
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2007-12-01 10:47:15 +00:00
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2007-12-01 10:47:15 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-09-21 17:13:11 +00:00
|
|
|
#include "qetapp.h"
|
2009-06-19 19:31:48 +00:00
|
|
|
#include "aboutqet.h"
|
|
|
|
#include "configdialog.h"
|
2012-06-29 05:21:32 +00:00
|
|
|
#include "configpages.h"
|
2007-09-21 17:13:11 +00:00
|
|
|
#include "qetdiagrameditor.h"
|
|
|
|
#include "qetelementeditor.h"
|
2011-10-08 21:54:53 +00:00
|
|
|
#include "elementscollectioncache.h"
|
2010-12-20 02:45:36 +00:00
|
|
|
#include "titleblocktemplate.h"
|
2011-12-25 17:45:39 +00:00
|
|
|
#include "qettemplateeditor.h"
|
2009-04-03 19:30:25 +00:00
|
|
|
#include "qetproject.h"
|
2010-02-09 19:29:55 +00:00
|
|
|
#include "qtextorientationspinboxwidget.h"
|
2008-07-30 11:51:27 +00:00
|
|
|
#include "recentfiles.h"
|
2009-05-01 14:41:33 +00:00
|
|
|
#include "qeticons.h"
|
2012-01-08 17:04:34 +00:00
|
|
|
#include "templatescollection.h"
|
2018-05-24 18:08:06 +00:00
|
|
|
#include "generalconfigurationpage.h"
|
|
|
|
#include "qetmessagebox.h"
|
|
|
|
#include "projectview.h"
|
|
|
|
|
2008-05-20 20:37:17 +00:00
|
|
|
#include <cstdlib>
|
2007-10-28 01:32:57 +00:00
|
|
|
#include <iostream>
|
2007-10-13 15:26:01 +00:00
|
|
|
#define QUOTE(x) STRINGIFY(x)
|
|
|
|
#define STRINGIFY(x) #x
|
2013-12-19 16:11:52 +00:00
|
|
|
#include <QProcessEnvironment>
|
2013-12-20 20:30:55 +00:00
|
|
|
#include "factory/elementfactory.h"
|
2007-09-22 13:27:14 +00:00
|
|
|
|
2009-11-22 16:12:22 +00:00
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
|
2007-10-04 20:34:29 +00:00
|
|
|
QString QETApp::common_elements_dir = QString();
|
2009-11-22 16:12:22 +00:00
|
|
|
#endif
|
2012-01-08 17:04:34 +00:00
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CTBTD_OPTION
|
|
|
|
QString QETApp::common_tbt_dir_ = QString();
|
|
|
|
#endif
|
2009-11-22 16:12:22 +00:00
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CD_OPTION
|
2007-11-10 17:52:30 +00:00
|
|
|
QString QETApp::config_dir = QString();
|
2009-11-22 16:12:22 +00:00
|
|
|
#endif
|
2008-08-17 21:08:31 +00:00
|
|
|
QString QETApp::lang_dir = QString();
|
2018-05-24 18:08:06 +00:00
|
|
|
TitleBlockTemplatesFilesCollection *QETApp::m_common_tbt_collection;
|
|
|
|
TitleBlockTemplatesFilesCollection *QETApp::m_custom_tbt_collection;
|
2017-07-27 20:26:13 +00:00
|
|
|
ElementsCollectionCache *QETApp::collections_cache_ = nullptr;
|
2009-04-03 19:30:25 +00:00
|
|
|
QMap<uint, QETProject *> QETApp::registered_projects_ = QMap<uint, QETProject *>();
|
|
|
|
uint QETApp::next_project_id = 0;
|
2018-05-24 18:08:06 +00:00
|
|
|
RecentFiles *QETApp::m_projects_recent_files = nullptr;
|
|
|
|
RecentFiles *QETApp::m_elements_recent_files = nullptr;
|
2017-07-27 20:26:13 +00:00
|
|
|
TitleBlockTemplate *QETApp::default_titleblock_template_ = nullptr;
|
2018-08-03 16:35:40 +00:00
|
|
|
QString QETApp::m_user_common_elements_dir = QString();
|
|
|
|
QString QETApp::m_user_custom_elements_dir = QString();
|
2018-08-15 12:45:55 +00:00
|
|
|
QETApp *QETApp::m_qetapp = nullptr;
|
2007-10-04 20:34:29 +00:00
|
|
|
|
2018-07-25 17:34:50 +00:00
|
|
|
|
2007-09-21 17:13:11 +00:00
|
|
|
/**
|
2018-08-15 12:45:55 +00:00
|
|
|
* @brief QETApp::QETApp
|
|
|
|
*/
|
|
|
|
QETApp::QETApp() :
|
2018-05-24 18:08:06 +00:00
|
|
|
m_splash_screen(nullptr),
|
2008-07-19 17:34:13 +00:00
|
|
|
non_interactive_execution_(false)
|
2008-07-17 19:25:57 +00:00
|
|
|
{
|
2018-08-15 12:45:55 +00:00
|
|
|
m_qetapp = this;
|
2008-07-19 17:34:13 +00:00
|
|
|
parseArguments();
|
2014-01-21 19:23:44 +00:00
|
|
|
initConfiguration();
|
2008-07-19 17:34:13 +00:00
|
|
|
initLanguage();
|
2009-05-24 17:46:44 +00:00
|
|
|
QET::Icons::initIcons();
|
|
|
|
initStyle();
|
2008-08-02 16:53:42 +00:00
|
|
|
initSplashScreen();
|
2008-07-20 12:50:12 +00:00
|
|
|
initSystemTray();
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-05-11 20:05:18 +00:00
|
|
|
connect(&signal_map, SIGNAL(mapped(QWidget *)), this, SLOT(invertMainWindowVisibility(QWidget *)));
|
2018-08-15 12:45:55 +00:00
|
|
|
qApp->setQuitOnLastWindowClosed(false);
|
|
|
|
connect(qApp, &QApplication::lastWindowClosed, this, &QETApp::checkRemainingWindows);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2015-03-02 20:14:56 +00:00
|
|
|
setSplashScreenStep(tr("Chargement... Initialisation du cache des collections d'éléments", "splash screen caption"));
|
2011-10-08 21:54:53 +00:00
|
|
|
if (!collections_cache_) {
|
|
|
|
QString cache_path = QETApp::configDir() + "/elements_cache.sqlite";
|
|
|
|
collections_cache_ = new ElementsCollectionCache(cache_path, this);
|
2014-01-21 19:23:44 +00:00
|
|
|
collections_cache_->setLocale(langFromSetting());
|
2011-10-08 21:54:53 +00:00
|
|
|
}
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2018-08-15 12:45:55 +00:00
|
|
|
if (qet_arguments_.files().isEmpty())
|
|
|
|
{
|
2015-09-10 16:29:39 +00:00
|
|
|
setSplashScreenStep(tr("Chargement... Éditeur de schéma", "splash screen caption"));
|
2008-07-26 15:26:19 +00:00
|
|
|
new QETDiagramEditor();
|
2018-08-15 12:45:55 +00:00
|
|
|
} else
|
|
|
|
{
|
2009-04-03 19:30:25 +00:00
|
|
|
setSplashScreenStep(tr("Chargement... Ouverture des fichiers", "splash screen caption"));
|
2008-07-26 15:26:19 +00:00
|
|
|
openFiles(qet_arguments_);
|
|
|
|
}
|
2018-08-15 12:45:55 +00:00
|
|
|
|
2007-10-19 16:21:35 +00:00
|
|
|
buildSystemTrayMenu();
|
2018-05-24 18:08:06 +00:00
|
|
|
m_splash_screen -> hide();
|
|
|
|
|
|
|
|
checkBackupFiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief QETApp::~QETApp
|
|
|
|
*/
|
|
|
|
QETApp::~QETApp()
|
|
|
|
{
|
|
|
|
m_elements_recent_files->save();
|
|
|
|
m_projects_recent_files->save();
|
|
|
|
|
|
|
|
delete m_splash_screen;
|
|
|
|
delete m_elements_recent_files;
|
|
|
|
delete m_projects_recent_files;
|
|
|
|
delete m_qsti;
|
|
|
|
|
|
|
|
if (m_custom_tbt_collection)
|
|
|
|
delete m_custom_tbt_collection;
|
|
|
|
if (m_common_tbt_collection)
|
|
|
|
delete m_common_tbt_collection;
|
|
|
|
|
2013-12-20 20:30:55 +00:00
|
|
|
ElementFactory::dropInstance();
|
2018-05-24 18:08:06 +00:00
|
|
|
|
|
|
|
//Delete all backup files
|
|
|
|
QDir dir(configDir() + "backup");
|
|
|
|
if(dir.exists())
|
|
|
|
{
|
|
|
|
QStringList extension_filter("*.qet");
|
|
|
|
QStringList list = dir.entryList(extension_filter);
|
2018-07-19 14:14:31 +00:00
|
|
|
for(const QString& str : list)
|
2018-06-01 18:33:08 +00:00
|
|
|
dir.remove(str);
|
2018-05-24 18:08:06 +00:00
|
|
|
}
|
2007-09-21 17:13:11 +00:00
|
|
|
}
|
|
|
|
|
2008-07-20 11:37:31 +00:00
|
|
|
/**
|
|
|
|
@return l'instance de la QETApp
|
|
|
|
*/
|
2018-08-15 12:45:55 +00:00
|
|
|
QETApp *QETApp::instance()
|
|
|
|
{
|
|
|
|
return m_qetapp;
|
2008-07-20 11:37:31 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 17:13:11 +00:00
|
|
|
/**
|
|
|
|
Change le langage utilise par l'application.
|
|
|
|
@param desired_language langage voulu
|
|
|
|
*/
|
|
|
|
void QETApp::setLanguage(const QString &desired_language) {
|
2007-12-21 18:20:18 +00:00
|
|
|
QString languages_path = languagesPath();
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2012-02-25 16:44:11 +00:00
|
|
|
// load Qt library translations
|
|
|
|
QString qt_l10n_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
|
|
|
if (!qtTranslator.load("qt_" + desired_language, qt_l10n_path)) {
|
|
|
|
qtTranslator.load("qt_" + desired_language, languages_path);
|
|
|
|
}
|
2018-08-15 12:45:55 +00:00
|
|
|
qApp->installTranslator(&qtTranslator);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// charge les traductions pour l'application QET
|
|
|
|
if (!qetTranslator.load("qet_" + desired_language, languages_path)) {
|
|
|
|
// en cas d'echec, on retombe sur les chaines natives pour le francais
|
|
|
|
if (desired_language != "fr") {
|
|
|
|
// utilisation de la version anglaise par defaut
|
2007-09-21 17:13:11 +00:00
|
|
|
qetTranslator.load("qet_en", languages_path);
|
|
|
|
}
|
|
|
|
}
|
2018-08-15 12:45:55 +00:00
|
|
|
qApp->installTranslator(&qetTranslator);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2012-02-20 21:20:34 +00:00
|
|
|
QString ltr_special_string = tr(
|
|
|
|
"LTR",
|
|
|
|
"Translate this string to RTL if you are translating to a Right-to-Left language, else translate to LTR"
|
|
|
|
);
|
|
|
|
if (ltr_special_string == "RTL") switchLayout(Qt::RightToLeft);
|
|
|
|
}
|
|
|
|
|
2014-01-21 19:23:44 +00:00
|
|
|
/**
|
|
|
|
* @brief QETApp::langFromSetting
|
|
|
|
* @return the langage found in setting file
|
|
|
|
* if nothing was found return the system local.
|
|
|
|
*/
|
2015-09-16 15:11:13 +00:00
|
|
|
QString QETApp::langFromSetting()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
QString system_language = settings.value("lang", "system").toString();
|
2014-01-21 19:23:44 +00:00
|
|
|
if(system_language == "system") {system_language = QLocale::system().name().left(2);}
|
|
|
|
return system_language;
|
|
|
|
}
|
2012-02-20 21:20:34 +00:00
|
|
|
/**
|
|
|
|
Switches the application to the provided layout.
|
|
|
|
*/
|
|
|
|
void QETApp::switchLayout(Qt::LayoutDirection direction) {
|
2018-08-15 12:45:55 +00:00
|
|
|
qApp->setLayoutDirection(direction);
|
2007-09-21 17:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gere les evenements relatifs au QSystemTrayIcon
|
2007-10-21 16:10:21 +00:00
|
|
|
@param reason un entier representant l'evenement survenu sur le systray
|
2007-09-21 17:13:11 +00:00
|
|
|
*/
|
|
|
|
void QETApp::systray(QSystemTrayIcon::ActivationReason reason) {
|
|
|
|
if (!QSystemTrayIcon::isSystemTrayAvailable()) return;
|
|
|
|
switch(reason) {
|
|
|
|
case QSystemTrayIcon::Context:
|
|
|
|
// affichage du menu
|
2007-09-22 13:27:14 +00:00
|
|
|
buildSystemTrayMenu();
|
2018-05-24 18:08:06 +00:00
|
|
|
m_qsti -> contextMenu() -> show();
|
2007-09-21 17:13:11 +00:00
|
|
|
break;
|
|
|
|
case QSystemTrayIcon::DoubleClick:
|
|
|
|
case QSystemTrayIcon::Trigger:
|
|
|
|
// reduction ou restauration de l'application
|
2011-12-27 01:39:45 +00:00
|
|
|
fetchWindowStats(diagramEditors(), elementEditors(), titleBlockTemplateEditors());
|
2007-09-22 13:27:14 +00:00
|
|
|
if (every_editor_reduced) restoreEveryEditor(); else reduceEveryEditor();
|
2007-09-21 17:13:11 +00:00
|
|
|
break;
|
|
|
|
case QSystemTrayIcon::Unknown:
|
|
|
|
default: // ne rien faire
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-22 13:27:14 +00:00
|
|
|
/// Reduit toutes les fenetres de l'application dans le systray
|
|
|
|
void QETApp::reduceEveryEditor() {
|
|
|
|
reduceDiagramEditors();
|
|
|
|
reduceElementEditors();
|
2011-12-27 01:39:45 +00:00
|
|
|
reduceTitleBlockTemplateEditors();
|
2007-09-21 18:07:05 +00:00
|
|
|
every_editor_reduced = true;
|
2007-09-21 17:13:11 +00:00
|
|
|
}
|
|
|
|
|
2007-09-22 13:27:14 +00:00
|
|
|
/// Restaure toutes les fenetres de l'application dans le systray
|
|
|
|
void QETApp::restoreEveryEditor() {
|
|
|
|
restoreDiagramEditors();
|
|
|
|
restoreElementEditors();
|
2011-12-27 01:39:45 +00:00
|
|
|
restoreTitleBlockTemplateEditors();
|
2007-09-22 13:27:14 +00:00
|
|
|
every_editor_reduced = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Reduit tous les editeurs de schemas dans le systray
|
|
|
|
void QETApp::reduceDiagramEditors() {
|
2011-12-27 01:39:45 +00:00
|
|
|
setMainWindowsVisible<QETDiagramEditor>(false);
|
2007-09-22 13:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Restaure tous les editeurs de schemas dans le systray
|
|
|
|
void QETApp::restoreDiagramEditors() {
|
2011-12-27 01:39:45 +00:00
|
|
|
setMainWindowsVisible<QETDiagramEditor>(true);
|
2007-09-22 13:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Reduit tous les editeurs d'element dans le systray
|
|
|
|
void QETApp::reduceElementEditors() {
|
2011-12-27 01:39:45 +00:00
|
|
|
setMainWindowsVisible<QETElementEditor>(false);
|
2007-09-22 13:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Restaure tous les editeurs d'element dans le systray
|
|
|
|
void QETApp::restoreElementEditors() {
|
2011-12-27 01:39:45 +00:00
|
|
|
setMainWindowsVisible<QETElementEditor>(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Reduce all known template editors
|
|
|
|
void QETApp::reduceTitleBlockTemplateEditors() {
|
|
|
|
setMainWindowsVisible<QETTitleBlockTemplateEditor>(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Restore all known template editors
|
|
|
|
void QETApp::restoreTitleBlockTemplateEditors() {
|
|
|
|
setMainWindowsVisible<QETTitleBlockTemplateEditor>(true);
|
2007-09-22 13:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// lance un nouvel editeur de schemas
|
|
|
|
void QETApp::newDiagramEditor() {
|
|
|
|
new QETDiagramEditor();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// lance un nouvel editeur d'element
|
|
|
|
void QETApp::newElementEditor() {
|
|
|
|
new QETElementEditor();
|
2007-09-21 17:13:11 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:19:58 +00:00
|
|
|
/**
|
|
|
|
@return the collection cache provided by the application itself.
|
|
|
|
*/
|
|
|
|
ElementsCollectionCache *QETApp::collectionCache() {
|
|
|
|
return(collections_cache_);
|
|
|
|
}
|
|
|
|
|
2014-02-12 17:36:35 +00:00
|
|
|
/**
|
|
|
|
* @brief QETApp::elementInfoKeys
|
|
|
|
* @return all available key for describe an element
|
|
|
|
*/
|
2016-11-24 16:45:55 +00:00
|
|
|
QStringList QETApp::elementInfoKeys()
|
|
|
|
{
|
2014-02-12 17:36:35 +00:00
|
|
|
QStringList info_list;
|
2016-11-24 16:45:55 +00:00
|
|
|
info_list << "formula"
|
|
|
|
<< "label"
|
2014-02-12 17:36:35 +00:00
|
|
|
<< "comment"
|
2017-10-02 16:59:53 +00:00
|
|
|
<< "description"
|
2014-11-30 11:53:23 +00:00
|
|
|
<< "designation"
|
2014-02-12 17:36:35 +00:00
|
|
|
<< "manufacturer"
|
|
|
|
<< "manufacturer-reference"
|
2017-10-03 12:11:28 +00:00
|
|
|
<< "provider"
|
2015-09-29 09:20:38 +00:00
|
|
|
<< "auxiliary1"
|
|
|
|
<< "auxiliary2"
|
2015-04-02 15:48:04 +00:00
|
|
|
<< "machine-manufacturer-reference"
|
2015-04-29 14:27:31 +00:00
|
|
|
<< "location"
|
2018-08-07 09:14:00 +00:00
|
|
|
<< "function"
|
|
|
|
<< "tension-protocol";
|
2014-02-12 17:36:35 +00:00
|
|
|
return info_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ElementsProperties::translatedInfo
|
|
|
|
* Return the translated information key given by @info
|
|
|
|
* If @info don't match, return an empty string
|
|
|
|
* @param info the key to be translated
|
|
|
|
* @return
|
|
|
|
*/
|
2017-08-06 10:18:33 +00:00
|
|
|
QString QETApp::elementTranslatedInfoKey(const QString &info)
|
2016-11-24 16:45:55 +00:00
|
|
|
{
|
|
|
|
if (info == "formula") return tr("formule du label");
|
|
|
|
else if (info == "label") return tr("Label");
|
2014-02-12 17:36:35 +00:00
|
|
|
else if (info == "comment") return tr("Commentaire");
|
2017-10-03 12:11:28 +00:00
|
|
|
else if (info == "description") return tr("Description textuelle");
|
|
|
|
else if (info == "designation") return tr("Numéro d'article");
|
2017-10-04 23:07:35 +00:00
|
|
|
else if (info == "manufacturer") return tr("Fabricant");
|
2017-10-03 12:11:28 +00:00
|
|
|
else if (info == "manufacturer-reference") return tr("Numéro de commande");
|
2017-10-04 23:07:35 +00:00
|
|
|
else if (info == "provider") return tr("Fournisseur");
|
2015-09-29 09:20:38 +00:00
|
|
|
else if (info == "auxiliary1") return tr("Bloc auxiliaire 1");
|
|
|
|
else if (info == "auxiliary2") return tr("Bloc auxiliaire 2");
|
2017-10-03 12:11:28 +00:00
|
|
|
else if (info == "machine-manufacturer-reference") return tr("Numéro interne");
|
2015-04-02 15:48:04 +00:00
|
|
|
else if (info == "location") return tr("Localisation");
|
2015-04-29 14:27:31 +00:00
|
|
|
else if (info == "function") return tr("Fonction");
|
2017-09-13 16:38:16 +00:00
|
|
|
else if (info == "tension-protocol") return tr("Tension / Protocole");
|
2014-02-12 17:36:35 +00:00
|
|
|
return (info);
|
|
|
|
}
|
|
|
|
|
2017-08-16 13:52:15 +00:00
|
|
|
/**
|
|
|
|
* @brief QETApp::elementInfoToVar
|
|
|
|
* @param info
|
|
|
|
* @return var in form %{my-var} corresponding to the info, if there is not available var for the given info
|
|
|
|
* the returned var is %{void}
|
|
|
|
*/
|
|
|
|
QString QETApp::elementInfoToVar(const QString &info)
|
|
|
|
{
|
|
|
|
if (info == "formula") return QString("%{formula}");
|
|
|
|
else if (info == "label") return QString("%{label}");
|
|
|
|
else if (info == "comment") return QString("%{comment}");
|
2017-10-02 16:59:53 +00:00
|
|
|
else if (info == "description") return QString("%{description}");
|
2017-08-16 13:52:15 +00:00
|
|
|
else if (info == "designation") return QString("%{designation}");
|
|
|
|
else if (info == "manufacturer") return QString("%{manufacturer}");
|
|
|
|
else if (info == "manufacturer-reference") return QString("%{manufacturer-reference}");
|
2017-10-03 12:11:28 +00:00
|
|
|
else if (info == "provider") return QString("%{provider}");
|
2017-08-16 13:52:15 +00:00
|
|
|
else if (info == "auxiliary1") return QString("%{auxiliary1}");
|
|
|
|
else if (info == "auxiliary2") return QString("%{auxiliary2}");
|
|
|
|
else if (info == "machine-manufacturer-reference") return QString("%{machine-manufacturer-reference}");
|
|
|
|
else if (info == "location") return QString("%{location}");
|
|
|
|
else if (info == "function") return QString("%{function}");
|
2017-09-13 16:38:16 +00:00
|
|
|
else if (info == "tension-protocol") return QString("%{tension-protocol}");
|
2017-08-16 13:52:15 +00:00
|
|
|
|
|
|
|
return (QString ("%{void}"));
|
|
|
|
}
|
|
|
|
|
2012-01-08 17:04:34 +00:00
|
|
|
/**
|
|
|
|
@return the common title block templates collection, i.e. the one provided
|
|
|
|
by QElecrotTech
|
|
|
|
*/
|
|
|
|
TitleBlockTemplatesFilesCollection *QETApp::commonTitleBlockTemplatesCollection() {
|
2018-05-24 18:08:06 +00:00
|
|
|
if (!m_common_tbt_collection) {
|
|
|
|
m_common_tbt_collection = new TitleBlockTemplatesFilesCollection(QETApp::commonTitleBlockTemplatesDir());
|
|
|
|
m_common_tbt_collection -> setTitle(tr("Cartouches QET", "title of the title block templates collection provided by QElectroTech"));
|
|
|
|
m_common_tbt_collection -> setProtocol(QETAPP_COMMON_TBT_PROTOCOL);
|
|
|
|
m_common_tbt_collection -> setCollection(QET::QetCollection::Common);
|
2012-01-08 17:04:34 +00:00
|
|
|
}
|
2018-05-24 18:08:06 +00:00
|
|
|
return(m_common_tbt_collection);
|
2012-01-08 17:04:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return the custom title block templates collection, i.e. the one managed
|
|
|
|
by the end user
|
|
|
|
*/
|
|
|
|
TitleBlockTemplatesFilesCollection *QETApp::customTitleBlockTemplatesCollection() {
|
2018-05-24 18:08:06 +00:00
|
|
|
if (!m_custom_tbt_collection) {
|
|
|
|
m_custom_tbt_collection = new TitleBlockTemplatesFilesCollection(QETApp::customTitleBlockTemplatesDir());
|
|
|
|
m_custom_tbt_collection -> setTitle(tr("Cartouches utilisateur", "title of the user's title block templates collection"));
|
|
|
|
m_custom_tbt_collection -> setProtocol(QETAPP_CUSTOM_TBT_PROTOCOL);
|
|
|
|
m_custom_tbt_collection -> setCollection(QET::QetCollection::Custom);
|
2012-01-08 17:04:34 +00:00
|
|
|
}
|
2018-05-24 18:08:06 +00:00
|
|
|
return(m_custom_tbt_collection);
|
2012-01-08 17:04:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return the list of all available title block tempaltes collections,
|
|
|
|
beginning with the common and custom ones, plus the projects-embedded ones.
|
|
|
|
*/
|
|
|
|
QList<TitleBlockTemplatesCollection *> QETApp::availableTitleBlockTemplatesCollections() {
|
|
|
|
QList<TitleBlockTemplatesCollection *> collections_list;
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2018-05-24 18:08:06 +00:00
|
|
|
collections_list << m_common_tbt_collection;
|
|
|
|
collections_list << m_custom_tbt_collection;
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QETProject *opened_project, registered_projects_) {
|
2012-01-08 17:04:34 +00:00
|
|
|
collections_list << opened_project -> embeddedTitleBlockTemplatesCollection();
|
|
|
|
}
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2012-01-08 17:04:34 +00:00
|
|
|
return(collections_list);
|
|
|
|
}
|
|
|
|
|
2012-01-15 19:26:40 +00:00
|
|
|
/**
|
|
|
|
@param protocol Protocol string
|
|
|
|
@return the templates collection matching the provided protocol, or 0 if none could be found
|
|
|
|
*/
|
|
|
|
TitleBlockTemplatesCollection *QETApp::titleBlockTemplatesCollection(const QString &protocol) {
|
|
|
|
if (protocol == QETAPP_COMMON_TBT_PROTOCOL) {
|
2018-05-24 18:08:06 +00:00
|
|
|
return(m_common_tbt_collection);
|
2012-01-15 19:26:40 +00:00
|
|
|
} else if (protocol == QETAPP_CUSTOM_TBT_PROTOCOL) {
|
2018-05-24 18:08:06 +00:00
|
|
|
return(m_custom_tbt_collection);
|
2012-01-15 19:26:40 +00:00
|
|
|
} else {
|
|
|
|
QETProject *project = QETApp::projectFromString(protocol);
|
|
|
|
if (project) {
|
|
|
|
return(project -> embeddedTitleBlockTemplatesCollection());
|
|
|
|
}
|
|
|
|
}
|
2017-08-05 02:06:59 +00:00
|
|
|
return(nullptr);
|
2012-01-15 19:26:40 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 17:13:11 +00:00
|
|
|
/**
|
2018-07-25 17:34:50 +00:00
|
|
|
* @brief QETApp::commonElementsDir
|
|
|
|
* @return the dir path of the common elements collection.
|
|
|
|
*/
|
|
|
|
QString QETApp::commonElementsDir()
|
|
|
|
{
|
2018-08-03 16:35:40 +00:00
|
|
|
if (m_user_common_elements_dir.isEmpty())
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
QString path = settings.value("elements-collections/common-collection-path", "default").toString();
|
|
|
|
if (path != "default" && !path.isEmpty())
|
|
|
|
{
|
|
|
|
QDir dir(path);
|
|
|
|
if (dir.exists())
|
|
|
|
{
|
|
|
|
m_user_common_elements_dir = path;
|
|
|
|
return m_user_common_elements_dir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_user_common_elements_dir = "default";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (m_user_common_elements_dir != "default") {
|
|
|
|
return m_user_common_elements_dir;
|
|
|
|
}
|
2018-07-30 15:24:29 +00:00
|
|
|
|
2007-10-04 20:34:29 +00:00
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
|
|
|
|
if (common_elements_dir != QString()) return(common_elements_dir);
|
|
|
|
#endif
|
2009-05-09 19:58:43 +00:00
|
|
|
#ifndef QET_COMMON_COLLECTION_PATH
|
|
|
|
// en l'absence d'option de compilation, on utilise le dossier elements, situe a cote du binaire executable
|
2009-05-09 18:04:58 +00:00
|
|
|
return(QCoreApplication::applicationDirPath() + "/elements/");
|
2009-05-09 19:58:43 +00:00
|
|
|
#else
|
|
|
|
#ifndef QET_COMMON_COLLECTION_PATH_RELATIVE_TO_BINARY_PATH
|
|
|
|
// l'option de compilation represente un chemin absolu ou relatif classique
|
|
|
|
return(QUOTE(QET_COMMON_COLLECTION_PATH));
|
|
|
|
#else
|
|
|
|
// l'option de compilation represente un chemin relatif au dossier contenant le binaire executable
|
2009-05-09 20:34:58 +00:00
|
|
|
return(QCoreApplication::applicationDirPath() + "/" + QUOTE(QET_COMMON_COLLECTION_PATH));
|
2009-05-09 19:58:43 +00:00
|
|
|
#endif
|
2007-10-04 20:34:29 +00:00
|
|
|
#endif
|
2007-09-21 17:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-25 17:34:50 +00:00
|
|
|
* @brief QETApp::customElementsDir
|
|
|
|
* @return the dir path of user elements collection
|
|
|
|
*/
|
|
|
|
QString QETApp::customElementsDir()
|
|
|
|
{
|
2018-08-03 16:35:40 +00:00
|
|
|
if (m_user_custom_elements_dir.isEmpty())
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
QString path = settings.value("elements-collections/custom-collection-path", "default").toString();
|
|
|
|
if (path != "default" && !path.isEmpty())
|
|
|
|
{
|
|
|
|
QDir dir(path);
|
|
|
|
if (dir.exists())
|
|
|
|
{
|
|
|
|
m_user_custom_elements_dir = path;
|
|
|
|
return m_user_custom_elements_dir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_user_custom_elements_dir = "default";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (m_user_custom_elements_dir != "default") {
|
|
|
|
return m_user_custom_elements_dir;
|
|
|
|
}
|
2018-07-30 15:24:29 +00:00
|
|
|
|
2007-12-21 18:20:18 +00:00
|
|
|
return(configDir() + "elements/");
|
2007-09-21 17:13:11 +00:00
|
|
|
}
|
|
|
|
|
2016-02-13 12:51:56 +00:00
|
|
|
/**
|
|
|
|
* @brief QETApp::commonElementsDirN
|
|
|
|
* like QString QETApp::commonElementsDir but without "/" at the end
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
QString QETApp::commonElementsDirN()
|
|
|
|
{
|
|
|
|
QString path = commonElementsDir();
|
|
|
|
if (path.endsWith("/")) path.remove(path.length()-1, 1);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief QETApp::customElementsDirN
|
|
|
|
* like QString QETApp::customElementsDir but without "/" at the end
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
QString QETApp::customElementsDirN()
|
|
|
|
{
|
|
|
|
QString path = customElementsDir();
|
|
|
|
if (path.endsWith("/")) path.remove(path.length()-1, 1);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2018-08-03 16:35:40 +00:00
|
|
|
/**
|
|
|
|
* @brief QETApp::resetUserElementsDir
|
|
|
|
* Reset the path of the user common and custom elements dir.
|
|
|
|
* Use this function when the user path (common and/or custom) change.
|
|
|
|
*/
|
|
|
|
void QETApp::resetUserElementsDir()
|
|
|
|
{
|
|
|
|
m_user_common_elements_dir.clear();
|
|
|
|
m_user_custom_elements_dir.clear();
|
|
|
|
}
|
|
|
|
|
2012-01-08 17:04:34 +00:00
|
|
|
/**
|
|
|
|
@return the path of the directory containing the common title block
|
|
|
|
templates collection.
|
|
|
|
*/
|
|
|
|
QString QETApp::commonTitleBlockTemplatesDir() {
|
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CTBTD_OPTION
|
|
|
|
if (common_tbt_dir_ != QString()) return(common_tbt_dir_);
|
|
|
|
#endif
|
|
|
|
#ifndef QET_COMMON_TBT_PATH
|
|
|
|
// without any compile-time option, use the "titleblocks" directory next to the executable binary
|
|
|
|
return(QCoreApplication::applicationDirPath() + "/titleblocks/");
|
|
|
|
#else
|
|
|
|
#ifndef QET_COMMON_COLLECTION_PATH_RELATIVE_TO_BINARY_PATH
|
|
|
|
// the compile-time option represents a usual path (be it absolute or relative)
|
|
|
|
return(QUOTE(QET_COMMON_TBT_PATH));
|
|
|
|
#else
|
|
|
|
// the compile-time option represents a path relative to the directory that contains the executable binary
|
|
|
|
return(QCoreApplication::applicationDirPath() + "/" + QUOTE(QET_COMMON_TBT_PATH));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return the path of the directory containing the custom title block
|
|
|
|
templates collection.
|
|
|
|
*/
|
|
|
|
QString QETApp::customTitleBlockTemplatesDir() {
|
|
|
|
return(configDir() + "titleblocks/");
|
|
|
|
}
|
|
|
|
|
2007-09-21 17:13:11 +00:00
|
|
|
/**
|
|
|
|
Renvoie le dossier de configuration de QET, c-a-d le chemin du dossier dans
|
|
|
|
lequel QET lira les informations de configuration et de personnalisation
|
|
|
|
propres a l'utilisateur courant. Ce dossier est generalement
|
2007-10-21 16:10:21 +00:00
|
|
|
C:\\Documents And Settings\\utilisateur\\Application Data\\qet sous Windows et
|
2007-09-21 17:13:11 +00:00
|
|
|
~/.qet sous les systemes type UNIX.
|
|
|
|
@return Le chemin du dossier de configuration de QElectroTech
|
|
|
|
*/
|
|
|
|
QString QETApp::configDir() {
|
2007-11-10 17:52:30 +00:00
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CD_OPTION
|
|
|
|
if (config_dir != QString()) return(config_dir);
|
|
|
|
#endif
|
2007-09-21 17:13:11 +00:00
|
|
|
#ifdef Q_OS_WIN32
|
2007-12-01 21:19:01 +00:00
|
|
|
// recupere l'emplacement du dossier Application Data
|
2013-12-19 16:11:52 +00:00
|
|
|
// char *app_data_env = getenv("APPDATA");
|
|
|
|
// QString app_data_str(app_data_env);
|
|
|
|
QProcess * process = new QProcess();
|
|
|
|
QString app_data_str = (process->processEnvironment()).value("APPDATA");
|
|
|
|
// delete app_data_env;
|
|
|
|
delete process;
|
2007-12-01 21:19:01 +00:00
|
|
|
if (app_data_str.isEmpty()) {
|
|
|
|
app_data_str = QDir::homePath() + "/Application Data";
|
|
|
|
}
|
|
|
|
return(app_data_str + "/qet/");
|
2007-09-21 17:13:11 +00:00
|
|
|
#else
|
|
|
|
return(QDir::homePath() + "/.qet/");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Permet de connaitre le chemin absolu du fichier *.elmt correspondant a un
|
|
|
|
chemin symbolique (du type custom://outils_pervers/sado_maso/contact_bizarre)
|
|
|
|
@param sym_path Chaine de caracteres representant le chemin absolu du fichier
|
|
|
|
@return Une chaine de caracteres vide en cas d'erreur ou le chemin absolu du
|
|
|
|
fichier *.elmt.
|
|
|
|
*/
|
2007-10-04 20:34:29 +00:00
|
|
|
QString QETApp::realPath(const QString &sym_path) {
|
2007-09-21 17:13:11 +00:00
|
|
|
QString directory;
|
|
|
|
if (sym_path.startsWith("common://")) {
|
|
|
|
directory = commonElementsDir();
|
|
|
|
} else if (sym_path.startsWith("custom://")) {
|
|
|
|
directory = customElementsDir();
|
2012-01-15 19:26:40 +00:00
|
|
|
} else if (sym_path.startsWith(QETAPP_COMMON_TBT_PROTOCOL "://")) {
|
2012-01-08 17:04:34 +00:00
|
|
|
directory = commonTitleBlockTemplatesDir();
|
2012-01-15 19:26:40 +00:00
|
|
|
} else if (sym_path.startsWith(QETAPP_CUSTOM_TBT_PROTOCOL "://")) {
|
2012-01-08 17:04:34 +00:00
|
|
|
directory = customTitleBlockTemplatesDir();
|
2007-09-21 17:13:11 +00:00
|
|
|
} else return(QString());
|
|
|
|
return(directory + QDir::toNativeSeparators(sym_path.right(sym_path.length() - 9)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Construit le chemin symbolique (du type custom://outils_pervers/sado_maso/
|
|
|
|
contact_bizarre) correspondant a un fichier.
|
2007-10-21 16:10:21 +00:00
|
|
|
@param real_path Chaine de caracteres representant le chemin symbolique du fichier
|
2007-09-21 17:13:11 +00:00
|
|
|
@return Une chaine de caracteres vide en cas d'erreur ou le chemin
|
|
|
|
symbolique designant l'element.
|
|
|
|
*/
|
2007-10-04 20:34:29 +00:00
|
|
|
QString QETApp::symbolicPath(const QString &real_path) {
|
2007-09-21 17:13:11 +00:00
|
|
|
// recupere les dossier common et custom
|
|
|
|
QString commond = commonElementsDir();
|
|
|
|
QString customd = customElementsDir();
|
|
|
|
QString chemin;
|
|
|
|
// analyse le chemin de fichier passe en parametre
|
|
|
|
if (real_path.startsWith(commond)) {
|
|
|
|
chemin = "common://" + real_path.right(real_path.length() - commond.length());
|
|
|
|
} else if (real_path.startsWith(customd)) {
|
|
|
|
chemin = "custom://" + real_path.right(real_path.length() - customd.length());
|
|
|
|
} else chemin = QString();
|
|
|
|
return(chemin);
|
|
|
|
}
|
|
|
|
|
2012-05-24 17:27:15 +00:00
|
|
|
/**
|
|
|
|
@return the list of file extensions QElectroTech is able to open and
|
|
|
|
supposed to handle. Note they are provided with no leading point.
|
|
|
|
*/
|
|
|
|
QStringList QETApp::handledFileExtensions() {
|
|
|
|
static QStringList ext;
|
|
|
|
if (!ext.count()) {
|
|
|
|
ext << "qet";
|
|
|
|
ext << "elmt";
|
2012-05-25 08:57:15 +00:00
|
|
|
ext << QString(TITLEBLOCKS_FILE_EXTENSION).remove(QRegExp("^\\."));
|
2012-05-24 17:27:15 +00:00
|
|
|
}
|
|
|
|
return(ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param an URLs list
|
|
|
|
@return the list of filepaths QElectroTech is able to open.
|
|
|
|
*/
|
|
|
|
QStringList QETApp::handledFiles(const QList<QUrl> &urls) {
|
|
|
|
QList<QString> filepaths;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (QUrl url, urls) {
|
2012-05-25 09:06:55 +00:00
|
|
|
if (url.scheme() != "file") continue;
|
2012-05-24 17:27:15 +00:00
|
|
|
QString local_path = url.toLocalFile();
|
|
|
|
QFileInfo local_path_info(local_path);
|
|
|
|
QString local_path_ext = local_path_info.completeSuffix();
|
|
|
|
if (handledFileExtensions().contains(local_path_ext)) {
|
|
|
|
filepaths << local_path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(filepaths);
|
|
|
|
}
|
|
|
|
|
2008-07-20 11:37:31 +00:00
|
|
|
/**
|
|
|
|
@param filepath Un chemin de fichier
|
|
|
|
Note : si filepath est une chaine vide, cette methode retourne 0.
|
|
|
|
@return le QETDiagramEditor editant le fichier filepath, ou 0 si ce fichier
|
|
|
|
n'est pas edite par l'application.
|
|
|
|
*/
|
|
|
|
QETDiagramEditor *QETApp::diagramEditorForFile(const QString &filepath) {
|
2017-08-05 02:06:59 +00:00
|
|
|
if (filepath.isEmpty()) return(nullptr);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-20 11:37:31 +00:00
|
|
|
QETApp *qet_app(QETApp::instance());
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (QETDiagramEditor *diagram_editor, qet_app -> diagramEditors()) {
|
2008-07-20 11:37:31 +00:00
|
|
|
if (diagram_editor -> viewForFile(filepath)) {
|
|
|
|
return(diagram_editor);
|
|
|
|
}
|
|
|
|
}
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2017-08-05 02:06:59 +00:00
|
|
|
return(nullptr);
|
2008-07-20 11:37:31 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 19:49:33 +00:00
|
|
|
/**
|
|
|
|
* @brief QETApp::diagramEditorAncestorOf
|
|
|
|
* @param child
|
|
|
|
* @return the parent QETDiagramEditor (or grandparent and so on to any level) of the given child.
|
|
|
|
* If not return nullptr;
|
|
|
|
*/
|
|
|
|
QETDiagramEditor *QETApp::diagramEditorAncestorOf (const QWidget *child)
|
|
|
|
{
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (QETDiagramEditor *qde, QETApp::diagramEditors()) {
|
2016-11-10 19:49:33 +00:00
|
|
|
if (qde->isAncestorOf(child)) {
|
|
|
|
return qde;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2007-10-04 20:34:29 +00:00
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
|
|
|
|
/**
|
2007-11-10 17:52:30 +00:00
|
|
|
Redefinit le chemin du dossier des elements communs
|
|
|
|
@param new_ced Nouveau chemin du dossier des elements communs
|
2007-10-04 20:34:29 +00:00
|
|
|
*/
|
|
|
|
void QETApp::overrideCommonElementsDir(const QString &new_ced) {
|
|
|
|
QFileInfo new_ced_info(new_ced);
|
|
|
|
if (new_ced_info.isDir()) {
|
|
|
|
common_elements_dir = new_ced_info.absoluteFilePath();
|
|
|
|
if (!common_elements_dir.endsWith("/")) common_elements_dir += "/";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-01-08 17:04:34 +00:00
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CTBTD_OPTION
|
|
|
|
/**
|
|
|
|
Define the path of the directory containing the common title block
|
|
|
|
tempaltes collection.
|
|
|
|
*/
|
|
|
|
void QETApp::overrideCommonTitleBlockTemplatesDir(const QString &new_ctbtd) {
|
|
|
|
QFileInfo new_ctbtd_info(new_ctbtd);
|
|
|
|
if (new_ctbtd_info.isDir()) {
|
|
|
|
common_tbt_dir_ = new_ctbtd_info.absoluteFilePath();
|
|
|
|
if (!common_tbt_dir_.endsWith("/")) common_tbt_dir_ += "/";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-11-10 17:52:30 +00:00
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CD_OPTION
|
|
|
|
/**
|
|
|
|
Redefinit le chemin du dossier de configuration
|
|
|
|
@param new_cd Nouveau chemin du dossier de configuration
|
|
|
|
*/
|
|
|
|
void QETApp::overrideConfigDir(const QString &new_cd) {
|
|
|
|
QFileInfo new_cd_info(new_cd);
|
|
|
|
if (new_cd_info.isDir()) {
|
|
|
|
config_dir = new_cd_info.absoluteFilePath();
|
|
|
|
if (!config_dir.endsWith("/")) config_dir += "/";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-08-17 21:08:31 +00:00
|
|
|
/**
|
|
|
|
Redefinit le chemin du dossier contenant les fichiers de langue
|
|
|
|
@param new_ld Nouveau chemin du dossier contenant les fichiers de langue
|
|
|
|
*/
|
|
|
|
void QETApp::overrideLangDir(const QString &new_ld) {
|
|
|
|
QFileInfo new_ld_info(new_ld);
|
|
|
|
if (new_ld_info.isDir()) {
|
|
|
|
lang_dir = new_ld_info.absoluteFilePath();
|
|
|
|
if (!lang_dir.endsWith("/")) lang_dir += "/";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-21 17:13:11 +00:00
|
|
|
/**
|
|
|
|
@return Le chemin du dossier contenant les fichiers de langue
|
|
|
|
*/
|
|
|
|
QString QETApp::languagesPath() {
|
2008-08-17 21:08:31 +00:00
|
|
|
if (!lang_dir.isEmpty()) {
|
|
|
|
return(lang_dir);
|
|
|
|
} else {
|
2007-10-04 20:34:29 +00:00
|
|
|
#ifndef QET_LANG_PATH
|
2009-05-09 19:58:43 +00:00
|
|
|
// en l'absence d'option de compilation, on utilise le dossier lang, situe a cote du binaire executable
|
2009-05-09 18:04:58 +00:00
|
|
|
return(QCoreApplication::applicationDirPath() + "/lang/");
|
2007-10-04 20:34:29 +00:00
|
|
|
#else
|
2009-05-09 19:58:43 +00:00
|
|
|
#ifndef QET_LANG_PATH_RELATIVE_TO_BINARY_PATH
|
|
|
|
// l'option de compilation represente un chemin absolu ou relatif classique
|
|
|
|
return(QUOTE(QET_LANG_PATH));
|
|
|
|
#else
|
|
|
|
// l'option de compilation represente un chemin relatif au dossier contenant le binaire executable
|
2009-05-09 20:34:58 +00:00
|
|
|
return(QCoreApplication::applicationDirPath() + "/" + QUOTE(QET_LANG_PATH));
|
2009-05-09 19:58:43 +00:00
|
|
|
#endif
|
2007-10-04 20:34:29 +00:00
|
|
|
#endif
|
2008-08-17 21:08:31 +00:00
|
|
|
}
|
2007-09-21 17:13:11 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 18:07:05 +00:00
|
|
|
/**
|
|
|
|
Ferme tous les editeurs
|
2007-10-04 12:19:01 +00:00
|
|
|
@return true si l'utilisateur a accepte toutes les fermetures, false sinon
|
2007-09-21 18:07:05 +00:00
|
|
|
*/
|
2007-10-04 12:19:01 +00:00
|
|
|
bool QETApp::closeEveryEditor() {
|
2007-09-21 18:07:05 +00:00
|
|
|
// s'assure que toutes les fenetres soient visibles avant de quitter
|
2007-09-22 13:27:14 +00:00
|
|
|
restoreEveryEditor();
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QETProject *project, registered_projects_) {
|
2009-04-03 19:30:25 +00:00
|
|
|
project -> close();
|
|
|
|
}
|
2007-10-04 12:19:01 +00:00
|
|
|
bool every_window_closed = true;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QETDiagramEditor *e, diagramEditors()) {
|
2007-10-04 12:19:01 +00:00
|
|
|
every_window_closed = every_window_closed && e -> close();
|
|
|
|
}
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QETElementEditor *e, elementEditors()) {
|
2007-10-04 12:19:01 +00:00
|
|
|
every_window_closed = every_window_closed && e -> close();
|
|
|
|
}
|
|
|
|
return(every_window_closed);
|
2007-09-21 18:07:05 +00:00
|
|
|
}
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
2015-09-16 15:11:13 +00:00
|
|
|
* @brief QETApp::diagramTextsFont
|
|
|
|
* The font to use
|
|
|
|
* By default the font is "sans Serif" and size 9.
|
|
|
|
* @param size : the size of font
|
|
|
|
* @return the font to use
|
|
|
|
*/
|
|
|
|
QFont QETApp::diagramTextsFont(qreal size)
|
|
|
|
{
|
|
|
|
QSettings settings;
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2015-09-16 15:11:13 +00:00
|
|
|
//Font to use
|
|
|
|
QString diagram_texts_family = settings.value("diagramfont", "Sans Serif").toString();
|
|
|
|
qreal diagram_texts_size = settings.value("diagramsize", 9.0).toDouble();
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2011-02-08 06:53:47 +00:00
|
|
|
if (size != -1.0) {
|
2009-04-12 17:21:19 +00:00
|
|
|
diagram_texts_size = size;
|
|
|
|
}
|
2011-02-08 06:53:47 +00:00
|
|
|
QFont diagram_texts_font = QFont(diagram_texts_family);
|
|
|
|
diagram_texts_font.setPointSizeF(diagram_texts_size);
|
|
|
|
if (diagram_texts_size <= 4.0) {
|
2009-04-12 17:21:19 +00:00
|
|
|
diagram_texts_font.setWeight(QFont::Light);
|
|
|
|
}
|
2007-12-21 18:20:18 +00:00
|
|
|
return(diagram_texts_font);
|
|
|
|
}
|
2017-12-10 01:03:36 +00:00
|
|
|
/**
|
|
|
|
* @brief QETApp::diagramTextsItemFont
|
|
|
|
* the font for to use in independent text item
|
|
|
|
* @param size of font
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
QFont QETApp::diagramTextsItemFont(qreal size)
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
//Font to use
|
|
|
|
QString diagram_texts_item_family = settings.value("diagramitemfont", "Sans Serif").toString();
|
|
|
|
qreal diagram_texts_item_size = settings.value("diagramitemsize", 9.0).toDouble();
|
2017-12-10 16:10:19 +00:00
|
|
|
qreal diagram_texts_item_weight = settings.value("diagramitemweight").toDouble();
|
2017-12-12 18:05:22 +00:00
|
|
|
QString diagram_texts_item_style = settings.value("diagramitemstyle", "normal").toString();
|
2017-12-10 16:10:19 +00:00
|
|
|
|
2017-12-10 01:03:36 +00:00
|
|
|
if (size != -1.0) {
|
|
|
|
diagram_texts_item_size = size;
|
|
|
|
}
|
|
|
|
QFont diagram_texts_item_font = QFont(diagram_texts_item_family);
|
|
|
|
diagram_texts_item_font.setPointSizeF(diagram_texts_item_size);
|
2017-12-10 16:10:19 +00:00
|
|
|
diagram_texts_item_font.setWeight(diagram_texts_item_weight);
|
|
|
|
diagram_texts_item_font.setStyleName(diagram_texts_item_style);
|
2017-12-10 01:03:36 +00:00
|
|
|
if (diagram_texts_item_size <= 4.0) {
|
|
|
|
diagram_texts_item_font.setWeight(QFont::Light);
|
|
|
|
}
|
|
|
|
return(diagram_texts_item_font);
|
|
|
|
}
|
2017-12-17 14:43:39 +00:00
|
|
|
/**
|
|
|
|
* @brief QETApp::foliolistTextsFont
|
|
|
|
* the font for to use in summary pages
|
|
|
|
* @param size
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
QFont QETApp::foliolistTextsFont(qreal size)
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
//Font to use
|
|
|
|
QString foliolist_texts_family = settings.value("foliolistfont", "Sans Serif").toString();
|
|
|
|
qreal foliolist_texts_size = settings.value("foliolistsize", 9.0).toDouble();
|
|
|
|
|
|
|
|
if (size != -1.0) {
|
|
|
|
foliolist_texts_size = size;
|
|
|
|
}
|
|
|
|
QFont foliolist_texts_font = QFont(foliolist_texts_family);
|
|
|
|
foliolist_texts_font.setPointSizeF(foliolist_texts_size);
|
|
|
|
if (foliolist_texts_size <= 4.0) {
|
|
|
|
foliolist_texts_font.setWeight(QFont::Light);
|
|
|
|
}
|
|
|
|
return(foliolist_texts_font);
|
|
|
|
}
|
2017-12-10 01:03:36 +00:00
|
|
|
|
2007-12-21 18:20:18 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
|
|
|
@return les editeurs de schemas
|
|
|
|
*/
|
|
|
|
QList<QETDiagramEditor *> QETApp::diagramEditors() {
|
2011-12-27 01:39:45 +00:00
|
|
|
return(QETApp::instance() -> detectWindows<QETDiagramEditor>());
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return les editeurs d'elements
|
|
|
|
*/
|
|
|
|
QList<QETElementEditor *> QETApp::elementEditors() {
|
2011-12-27 01:39:45 +00:00
|
|
|
return(QETApp::instance() -> detectWindows<QETElementEditor>());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return the title block template editors
|
|
|
|
*/
|
|
|
|
QList<QETTitleBlockTemplateEditor *> QETApp::titleBlockTemplateEditors() {
|
|
|
|
return(QETApp::instance() -> detectWindows<QETTitleBlockTemplateEditor>());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param project Opened project object.
|
|
|
|
@return the list of title block template editors which are currently
|
|
|
|
editing a template embedded within \a project.
|
|
|
|
*/
|
|
|
|
QList<QETTitleBlockTemplateEditor *> QETApp::titleBlockTemplateEditors(QETProject *project) {
|
|
|
|
QList<QETTitleBlockTemplateEditor *> editors;
|
|
|
|
if (!project) return(editors);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2017-02-05 16:18:50 +00:00
|
|
|
// foreach known template editor
|
|
|
|
foreach (QETTitleBlockTemplateEditor *tbt_editor, titleBlockTemplateEditors()) {
|
2012-01-08 17:04:34 +00:00
|
|
|
if (tbt_editor -> location().parentProject() == project) {
|
2011-12-27 01:39:45 +00:00
|
|
|
editors << tbt_editor;
|
|
|
|
}
|
|
|
|
}
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2011-12-27 01:39:45 +00:00
|
|
|
return(editors);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
2010-02-09 19:29:55 +00:00
|
|
|
/**
|
|
|
|
Instancie un QTextOrientationSpinBoxWidget et configure :
|
|
|
|
* sa police de caracteres
|
|
|
|
* ses chaines de caracteres
|
|
|
|
A noter que la suppression du widget ainsi alloue est a la charge de
|
|
|
|
l'appelant.
|
|
|
|
@return un QTextOrientationSpinBoxWidget adapte pour une utilisation
|
|
|
|
"directe" dans QET.
|
|
|
|
@see QTextOrientationSpinBoxWidget
|
|
|
|
*/
|
|
|
|
QTextOrientationSpinBoxWidget *QETApp::createTextOrientationSpinBoxWidget() {
|
2018-07-30 15:24:29 +00:00
|
|
|
QTextOrientationSpinBoxWidget *widget = new QTextOrientationSpinBoxWidget();
|
2010-02-09 19:29:55 +00:00
|
|
|
widget -> orientationWidget() -> setFont(QETApp::diagramTextsFont());
|
|
|
|
widget -> orientationWidget() -> setUsableTexts(QList<QString>()
|
|
|
|
<< QETApp::tr("Q", "Single-letter example text - translate length, not meaning")
|
|
|
|
<< QETApp::tr("QET", "Small example text - translate length, not meaning")
|
|
|
|
<< QETApp::tr("Schema", "Normal example text - translate length, not meaning")
|
|
|
|
<< QETApp::tr("Electrique", "Normal example text - translate length, not meaning")
|
|
|
|
<< QETApp::tr("QElectroTech", "Long example text - translate length, not meaning")
|
|
|
|
);
|
|
|
|
return(widget);
|
|
|
|
}
|
2010-12-19 18:12:56 +00:00
|
|
|
|
|
|
|
/**
|
2010-12-20 02:45:36 +00:00
|
|
|
@return the default titleblock template for diagrams
|
2010-12-19 18:12:56 +00:00
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
TitleBlockTemplate *QETApp::defaultTitleBlockTemplate() {
|
|
|
|
if (!QETApp::default_titleblock_template_) {
|
2018-07-30 15:24:29 +00:00
|
|
|
TitleBlockTemplate *titleblock_template = new TitleBlockTemplate(QETApp::instance());
|
2010-12-20 02:45:36 +00:00
|
|
|
if (titleblock_template -> loadFromXmlFile(":/titleblocks/default.titleblock")) {
|
|
|
|
QETApp::default_titleblock_template_ = titleblock_template;
|
2010-12-19 18:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-20 02:45:36 +00:00
|
|
|
return(default_titleblock_template_);
|
2010-12-19 18:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
|
|
|
@param project un projet
|
|
|
|
@return les editeurs d'elements editant un element appartenant au projet
|
|
|
|
project
|
|
|
|
*/
|
|
|
|
QList<QETElementEditor *> QETApp::elementEditors(QETProject *project) {
|
|
|
|
QList<QETElementEditor *> editors;
|
|
|
|
if (!project) return(editors);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// pour chaque editeur d'element...
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QETElementEditor *elmt_editor, elementEditors()) {
|
2009-04-03 19:30:25 +00:00
|
|
|
// on recupere l'emplacement de l'element qu'il edite
|
|
|
|
ElementsLocation elmt_editor_loc(elmt_editor -> location());
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// il se peut que l'editeur edite un element non enregistre ou un fichier
|
|
|
|
if (elmt_editor_loc.isNull()) continue;
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
if (elmt_editor_loc.project() == project) {
|
|
|
|
editors << elmt_editor;
|
|
|
|
}
|
|
|
|
}
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
return(editors);
|
|
|
|
}
|
|
|
|
|
2018-08-15 12:45:55 +00:00
|
|
|
void QETApp::receiveMessage(int instanceId, QByteArray message)
|
|
|
|
{
|
|
|
|
Q_UNUSED(instanceId);
|
|
|
|
|
|
|
|
QString str(message);
|
|
|
|
|
|
|
|
if (str.startsWith("launched-with-args: "))
|
|
|
|
{
|
|
|
|
QString my_message(str.mid(20));
|
|
|
|
QStringList args_list = QET::splitWithSpaces(my_message);
|
|
|
|
openFiles(QETArguments(args_list));
|
|
|
|
}
|
2007-09-21 17:13:11 +00:00
|
|
|
}
|
|
|
|
|
2011-12-27 01:39:45 +00:00
|
|
|
/**
|
|
|
|
@param T a class inheriting QMainWindow
|
|
|
|
@return the list of windows of type T
|
|
|
|
*/
|
|
|
|
template <class T> QList<T *> QETApp::detectWindows() const {
|
|
|
|
QList<T *> windows;
|
2018-08-15 12:45:55 +00:00
|
|
|
foreach(QWidget *widget, qApp->topLevelWidgets()) {
|
2011-12-27 01:39:45 +00:00
|
|
|
if (!widget -> isWindow()) continue;
|
|
|
|
if (T *window = qobject_cast<T *>(widget)) {
|
|
|
|
windows << window;
|
2007-09-21 17:13:11 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-27 01:39:45 +00:00
|
|
|
return(windows);
|
2007-09-21 17:13:11 +00:00
|
|
|
}
|
|
|
|
|
2011-12-27 01:39:45 +00:00
|
|
|
/**
|
|
|
|
@param T a class inheriting QMainWindow
|
|
|
|
@param visible whether detected main windows should be visible
|
|
|
|
*/
|
|
|
|
template <class T> void QETApp::setMainWindowsVisible(bool visible) {
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(T *e, detectWindows<T>()) {
|
2011-12-27 01:39:45 +00:00
|
|
|
setMainWindowVisible(e, visible);
|
2007-09-21 17:13:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-30 11:51:27 +00:00
|
|
|
/**
|
|
|
|
@return La liste des fichiers recents pour les projets
|
|
|
|
*/
|
|
|
|
RecentFiles *QETApp::projectsRecentFiles() {
|
2018-05-24 18:08:06 +00:00
|
|
|
return(m_projects_recent_files);
|
2008-07-30 11:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return La liste des fichiers recents pour les elements
|
|
|
|
*/
|
|
|
|
RecentFiles *QETApp::elementsRecentFiles() {
|
2018-05-24 18:08:06 +00:00
|
|
|
return(m_elements_recent_files);
|
2008-07-30 11:51:27 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 17:13:11 +00:00
|
|
|
/**
|
2007-12-05 21:16:01 +00:00
|
|
|
Affiche ou cache une fenetre (editeurs de schemas / editeurs d'elements)
|
2007-09-21 17:13:11 +00:00
|
|
|
@param window fenetre a afficher / cacher
|
|
|
|
@param visible true pour affiche la fenetre, false sinon
|
|
|
|
*/
|
|
|
|
void QETApp::setMainWindowVisible(QMainWindow *window, bool visible) {
|
|
|
|
if (window -> isVisible() == visible) return;
|
|
|
|
if (!visible) {
|
|
|
|
window_geometries.insert(window, window -> saveGeometry());
|
|
|
|
window_states.insert(window, window -> saveState());
|
|
|
|
window -> hide();
|
2007-09-21 18:59:43 +00:00
|
|
|
// cache aussi les toolbars et les docks
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (QWidget *qw, floatingToolbarsAndDocksForMainWindow(window)) {
|
2007-09-21 18:59:43 +00:00
|
|
|
qw -> hide();
|
|
|
|
}
|
2007-09-21 17:13:11 +00:00
|
|
|
} else {
|
|
|
|
window -> show();
|
2007-09-22 13:27:14 +00:00
|
|
|
#ifndef Q_OS_WIN32
|
2007-09-21 17:13:11 +00:00
|
|
|
window -> restoreGeometry(window_geometries[window]);
|
2007-09-22 13:27:14 +00:00
|
|
|
#endif
|
2007-09-21 17:13:11 +00:00
|
|
|
window -> restoreState(window_states[window]);
|
|
|
|
}
|
|
|
|
}
|
2007-09-21 18:59:43 +00:00
|
|
|
|
2007-09-22 13:27:14 +00:00
|
|
|
/**
|
2007-12-05 21:16:01 +00:00
|
|
|
Affiche une fenetre (editeurs de schemas / editeurs d'elements) si
|
2007-09-22 13:27:14 +00:00
|
|
|
celle-ci est cachee ou la cache si elle est affichee.
|
|
|
|
@param window fenetre a afficher / cacher
|
|
|
|
*/
|
|
|
|
void QETApp::invertMainWindowVisibility(QWidget *window) {
|
2018-07-30 15:24:29 +00:00
|
|
|
if (QMainWindow *w = qobject_cast<QMainWindow *>(window)) setMainWindowVisible(w, !w -> isVisible());
|
2007-09-22 13:27:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 13:08:43 +00:00
|
|
|
/**
|
|
|
|
Autodetec Windows style
|
|
|
|
@param Windows style
|
|
|
|
*/
|
2015-03-02 20:14:56 +00:00
|
|
|
#if defined(Q_OS_WIN) && defined(Q_OS_WINCE)
|
2014-08-17 23:02:32 +00:00
|
|
|
|
2015-03-02 20:14:56 +00:00
|
|
|
if defined(Q_OS_WIN)
|
2014-08-11 13:08:43 +00:00
|
|
|
if ((QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA
|
|
|
|
&& QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
|
|
|
|
style = QLatin1String("WindowsVista");
|
2014-08-17 23:02:32 +00:00
|
|
|
else if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
|
2014-08-11 13:08:43 +00:00
|
|
|
&& QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
|
|
|
|
style = QLatin1String("WindowsXP");
|
|
|
|
else
|
|
|
|
style = QLatin1String("Windows"); // default styles for Windows
|
|
|
|
#endif
|
|
|
|
|
2014-08-17 23:02:32 +00:00
|
|
|
|
2009-05-24 17:46:44 +00:00
|
|
|
/**
|
|
|
|
Change la palette de l'application
|
|
|
|
@param use true pour utiliser les couleurs du systeme, false pour utiliser celles du theme en cours
|
|
|
|
*/
|
|
|
|
void QETApp::useSystemPalette(bool use) {
|
|
|
|
if (use) {
|
2018-08-15 12:45:55 +00:00
|
|
|
qApp->setPalette(initial_palette_);
|
|
|
|
qApp->setStyleSheet(
|
2014-06-21 12:17:00 +00:00
|
|
|
"QTabBar::tab:!selected { background-color: transparent; }"
|
|
|
|
"QAbstractScrollArea#mdiarea {"
|
2014-10-27 13:51:27 +00:00
|
|
|
"background-color -> setPalette(initial_palette_);"
|
|
|
|
"}"
|
2014-06-21 12:17:00 +00:00
|
|
|
);
|
2009-05-24 17:46:44 +00:00
|
|
|
} else {
|
2014-06-24 15:09:09 +00:00
|
|
|
QFile file(configDir() + "style.css");
|
2014-06-23 15:17:35 +00:00
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
QString styleSheet = QLatin1String(file.readAll());
|
2018-08-15 12:45:55 +00:00
|
|
|
qApp->setStyleSheet(styleSheet);
|
2014-06-23 22:42:16 +00:00
|
|
|
file.close();
|
2009-05-24 17:46:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-04 12:19:01 +00:00
|
|
|
/**
|
|
|
|
Demande la fermeture de toutes les fenetres ; si l'utilisateur les accepte,
|
|
|
|
l'application quitte
|
|
|
|
*/
|
|
|
|
void QETApp::quitQET() {
|
|
|
|
if (closeEveryEditor()) {
|
2018-08-15 12:45:55 +00:00
|
|
|
qApp->quit();
|
2007-10-04 12:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Verifie s'il reste des fenetres (cachees ou non) et quitte s'il n'en reste
|
|
|
|
plus.
|
|
|
|
*/
|
|
|
|
void QETApp::checkRemainingWindows() {
|
|
|
|
/* petite bidouille : le slot se rappelle apres 500 ms d'attente
|
|
|
|
afin de compenser le fait que certaines fenetres peuvent encore
|
|
|
|
paraitre vivantes alors qu'elles viennent d'etre fermees
|
|
|
|
*/
|
|
|
|
static bool sleep = true;
|
|
|
|
if (sleep) {
|
|
|
|
QTimer::singleShot(500, this, SLOT(checkRemainingWindows()));
|
|
|
|
} else {
|
|
|
|
if (!diagramEditors().count() && !elementEditors().count()) {
|
2018-08-15 12:45:55 +00:00
|
|
|
qApp->quit();
|
2007-10-04 12:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sleep = !sleep;
|
|
|
|
}
|
|
|
|
|
2008-07-26 15:26:19 +00:00
|
|
|
/**
|
|
|
|
Ouvre les fichiers passes en arguments
|
2015-09-10 16:29:39 +00:00
|
|
|
@param args Objet contenant des arguments ; les fichiers
|
2008-07-26 15:26:19 +00:00
|
|
|
@see openProjectFiles openElementFiles
|
|
|
|
*/
|
|
|
|
void QETApp::openFiles(const QETArguments &args) {
|
|
|
|
openProjectFiles(args.projectFiles());
|
|
|
|
openElementFiles(args.elementFiles());
|
2012-04-09 15:27:15 +00:00
|
|
|
openTitleBlockTemplateFiles(args.titleBlockTemplateFiles());
|
2008-07-26 15:26:19 +00:00
|
|
|
}
|
|
|
|
|
2008-07-17 19:25:57 +00:00
|
|
|
/**
|
|
|
|
Ouvre une liste de fichiers.
|
|
|
|
Les fichiers sont ouverts dans le premier editeur de schemas visible venu.
|
|
|
|
Sinon, le premier editeur de schemas existant venu devient visible et est
|
|
|
|
utilise. S'il n'y a aucun editeur de schemas ouvert, un nouveau est cree et
|
|
|
|
utilise.
|
2009-11-22 16:12:22 +00:00
|
|
|
@param files_list Fichiers a ouvrir
|
2008-07-17 19:25:57 +00:00
|
|
|
*/
|
2008-07-26 15:26:19 +00:00
|
|
|
void QETApp::openProjectFiles(const QStringList &files_list) {
|
2008-07-17 19:25:57 +00:00
|
|
|
if (files_list.isEmpty()) return;
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-17 19:25:57 +00:00
|
|
|
// liste des editeurs de schema ouverts
|
|
|
|
QList<QETDiagramEditor *> diagrams_editors = diagramEditors();
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-17 19:25:57 +00:00
|
|
|
// s'il y a des editeur de schemas ouvert, on cherche ceux qui sont visibles
|
|
|
|
if (diagrams_editors.count()) {
|
|
|
|
QList<QETDiagramEditor *> visible_diagrams_editors;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QETDiagramEditor *de, diagrams_editors) {
|
2008-07-17 19:25:57 +00:00
|
|
|
if (de -> isVisible()) visible_diagrams_editors << de;
|
|
|
|
}
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-17 19:25:57 +00:00
|
|
|
// on choisit soit le premier visible soit le premier tout court
|
|
|
|
QETDiagramEditor *de_open;
|
|
|
|
if (visible_diagrams_editors.count()) {
|
|
|
|
de_open = visible_diagrams_editors.first();
|
|
|
|
} else {
|
|
|
|
de_open = diagrams_editors.first();
|
|
|
|
de_open -> setVisible(true);
|
|
|
|
}
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-17 19:25:57 +00:00
|
|
|
// ouvre les fichiers dans l'editeur ainsi choisi
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QString file, files_list) {
|
2009-04-03 19:30:25 +00:00
|
|
|
de_open -> openAndAddProject(file);
|
2008-07-17 19:25:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// cree un nouvel editeur qui ouvrira les fichiers
|
|
|
|
new QETDiagramEditor(files_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-26 15:26:19 +00:00
|
|
|
/**
|
|
|
|
Ouvre les fichiers elements passes en parametre. Si un element est deja
|
2012-04-09 15:27:15 +00:00
|
|
|
ouvert, la fenetre qui l'edite est activee.
|
2009-11-22 16:12:22 +00:00
|
|
|
@param files_list Fichiers a ouvrir
|
2008-07-26 15:26:19 +00:00
|
|
|
*/
|
|
|
|
void QETApp::openElementFiles(const QStringList &files_list) {
|
|
|
|
if (files_list.isEmpty()) return;
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2010-03-28 16:27:48 +00:00
|
|
|
// evite autant que possible les doublons dans la liste fournie
|
|
|
|
QSet<QString> files_set;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QString file, files_list) {
|
2010-03-28 16:27:48 +00:00
|
|
|
QString canonical_filepath = QFileInfo(file).canonicalFilePath();
|
|
|
|
if (!canonical_filepath.isEmpty()) files_set << canonical_filepath;
|
|
|
|
}
|
|
|
|
// a ce stade, tous les fichiers dans le Set existent et sont a priori differents
|
|
|
|
if (files_set.isEmpty()) return;
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2010-03-28 16:27:48 +00:00
|
|
|
// liste des editeurs d'element ouverts
|
|
|
|
QList<QETElementEditor *> element_editors = elementEditors();
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2010-03-28 16:27:48 +00:00
|
|
|
// on traite les fichiers a la queue leu leu...
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QString element_file, files_set) {
|
2010-03-28 16:27:48 +00:00
|
|
|
bool already_opened_in_existing_element_editor = false;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QETElementEditor *element_editor, element_editors) {
|
2010-03-28 16:27:48 +00:00
|
|
|
if (element_editor -> isEditing(element_file)) {
|
|
|
|
// ce fichier est deja ouvert dans un editeur
|
|
|
|
already_opened_in_existing_element_editor = true;
|
|
|
|
element_editor -> setVisible(true);
|
|
|
|
element_editor -> raise();
|
|
|
|
element_editor -> activateWindow();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!already_opened_in_existing_element_editor) {
|
|
|
|
// ce fichier n'est ouvert dans aucun editeur
|
2018-07-30 15:24:29 +00:00
|
|
|
QETElementEditor *element_editor = new QETElementEditor();
|
2010-03-28 16:27:48 +00:00
|
|
|
element_editor -> fromFile(element_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Ouvre les elements dont l'emplacement est passe en parametre. Si un element
|
|
|
|
est deja ouvert, la fentre qui l'edite est activee.
|
|
|
|
@param locations_list Emplacements a ouvrir
|
|
|
|
*/
|
|
|
|
void QETApp::openElementLocations(const QList<ElementsLocation> &locations_list) {
|
|
|
|
if (locations_list.isEmpty()) return;
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2010-03-28 16:27:48 +00:00
|
|
|
// liste des editeurs d'element ouverts
|
|
|
|
QList<QETElementEditor *> element_editors = elementEditors();
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2010-03-28 16:27:48 +00:00
|
|
|
// on traite les emplacements a la queue leu leu...
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(ElementsLocation element_location, locations_list) {
|
2010-03-28 16:27:48 +00:00
|
|
|
bool already_opened_in_existing_element_editor = false;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QETElementEditor *element_editor, element_editors) {
|
2010-03-28 16:27:48 +00:00
|
|
|
if (element_editor -> isEditing(element_location)) {
|
|
|
|
// cet emplacement est deja ouvert dans un editeur
|
|
|
|
already_opened_in_existing_element_editor = true;
|
|
|
|
element_editor -> setVisible(true);
|
|
|
|
element_editor -> raise();
|
|
|
|
element_editor -> activateWindow();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!already_opened_in_existing_element_editor) {
|
|
|
|
// cet emplacement n'est ouvert dans aucun editeur
|
2018-07-30 15:24:29 +00:00
|
|
|
QETElementEditor *element_editor = new QETElementEditor();
|
2010-03-28 16:27:48 +00:00
|
|
|
element_editor -> fromLocation(element_location);
|
|
|
|
}
|
2008-07-26 15:26:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-24 21:00:11 +00:00
|
|
|
/**
|
|
|
|
Launch a new title block template editor to edit the given template
|
2012-01-12 07:04:09 +00:00
|
|
|
@param location location of the title block template to be edited
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2012-01-25 07:29:50 +00:00
|
|
|
@param duplicate if true, the template is opened for duplication, which means
|
|
|
|
the user will be prompter for a new template name.
|
|
|
|
@see QETTitleBlockTemplateEditor::setOpenForDuplication()
|
2010-12-24 21:00:11 +00:00
|
|
|
*/
|
2012-01-25 07:29:50 +00:00
|
|
|
void QETApp::openTitleBlockTemplate(const TitleBlockTemplateLocation &location, bool duplicate) {
|
2018-07-30 15:24:29 +00:00
|
|
|
QETTitleBlockTemplateEditor *qet_template_editor = new QETTitleBlockTemplateEditor();
|
2012-01-25 07:29:50 +00:00
|
|
|
qet_template_editor -> setOpenForDuplication(duplicate);
|
2012-01-08 17:04:34 +00:00
|
|
|
qet_template_editor -> edit(location);
|
2012-04-09 18:56:17 +00:00
|
|
|
qet_template_editor -> show();
|
2010-12-24 21:00:11 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 07:04:09 +00:00
|
|
|
/**
|
|
|
|
Launch a new title block template editor to edit the given template
|
|
|
|
@param filepath Path of the .titleblock file to be opened
|
|
|
|
*/
|
|
|
|
void QETApp::openTitleBlockTemplate(const QString &filepath) {
|
2018-07-30 15:24:29 +00:00
|
|
|
QETTitleBlockTemplateEditor *qet_template_editor = new QETTitleBlockTemplateEditor();
|
2012-01-12 07:04:09 +00:00
|
|
|
qet_template_editor -> edit(filepath);
|
2012-04-09 18:56:17 +00:00
|
|
|
qet_template_editor -> show();
|
2012-01-12 07:04:09 +00:00
|
|
|
}
|
|
|
|
|
2012-04-09 15:27:15 +00:00
|
|
|
/**
|
|
|
|
Open provided title block template files. If a title block template is already
|
|
|
|
opened, the adequate window is activated.
|
|
|
|
@param files_list Files to be opened
|
|
|
|
*/
|
|
|
|
void QETApp::openTitleBlockTemplateFiles(const QStringList &files_list) {
|
|
|
|
if (files_list.isEmpty()) return;
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2012-04-09 15:27:15 +00:00
|
|
|
// avoid duplicates in the provided files list
|
|
|
|
QSet<QString> files_set;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (QString file, files_list) {
|
2012-04-09 15:27:15 +00:00
|
|
|
QString canonical_filepath = QFileInfo(file).canonicalFilePath();
|
|
|
|
if (!canonical_filepath.isEmpty()) files_set << canonical_filepath;
|
|
|
|
}
|
|
|
|
// here, we can assume all files in the set exist and are different
|
|
|
|
if (files_set.isEmpty()) return;
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2012-04-09 15:27:15 +00:00
|
|
|
// opened title block template editors
|
|
|
|
QList<QETTitleBlockTemplateEditor *> tbt_editors = titleBlockTemplateEditors();
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QString tbt_file, files_set) {
|
2012-04-09 15:27:15 +00:00
|
|
|
bool already_opened_in_existing_tbt_editor = false;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QETTitleBlockTemplateEditor *tbt_editor, tbt_editors) {
|
2012-04-09 15:27:15 +00:00
|
|
|
if (tbt_editor -> isEditing(tbt_file)) {
|
|
|
|
// this file is already opened
|
|
|
|
already_opened_in_existing_tbt_editor = true;
|
|
|
|
tbt_editor -> setVisible(true);
|
|
|
|
tbt_editor -> raise();
|
|
|
|
tbt_editor -> activateWindow();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!already_opened_in_existing_tbt_editor) {
|
|
|
|
// this file is not opened yet
|
|
|
|
openTitleBlockTemplate(tbt_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-19 19:31:48 +00:00
|
|
|
/**
|
|
|
|
Permet a l'utilisateur de configurer QET en lancant un dialogue approprie.
|
|
|
|
@see ConfigDialog
|
|
|
|
*/
|
|
|
|
void QETApp::configureQET() {
|
|
|
|
// determine le widget parent a utiliser pour le dialogue
|
2018-08-15 12:45:55 +00:00
|
|
|
QWidget *parent_widget = qApp->activeWindow();
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2009-06-19 19:31:48 +00:00
|
|
|
// cree le dialogue
|
|
|
|
ConfigDialog cd;
|
2012-06-29 05:21:32 +00:00
|
|
|
cd.setWindowTitle(tr("Configurer QElectroTech", "window title"));
|
2016-08-10 06:55:16 +00:00
|
|
|
cd.setWindowModality(Qt::WindowModal);
|
2012-06-29 05:21:32 +00:00
|
|
|
cd.addPage(new GeneralConfigurationPage());
|
|
|
|
cd.addPage(new NewDiagramPage());
|
|
|
|
cd.addPage(new ExportConfigPage());
|
|
|
|
cd.addPage(new PrintConfigPage());
|
2015-09-10 16:29:39 +00:00
|
|
|
|
|
|
|
|
2009-06-19 19:31:48 +00:00
|
|
|
// associe le dialogue a un eventuel widget parent
|
|
|
|
if (parent_widget) {
|
|
|
|
cd.setParent(parent_widget, cd.windowFlags());
|
|
|
|
}
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2009-06-19 19:31:48 +00:00
|
|
|
// affiche le dialogue puis evite de le lier a un quelconque widget parent
|
|
|
|
cd.exec();
|
2017-08-05 02:06:59 +00:00
|
|
|
cd.setParent(nullptr, cd.windowFlags());
|
2009-06-19 19:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-07-27 20:26:13 +00:00
|
|
|
* @brief QETApp::aboutQET
|
|
|
|
* Open the dialog about qet.
|
|
|
|
*/
|
|
|
|
void QETApp::aboutQET()
|
|
|
|
{
|
2018-08-15 12:45:55 +00:00
|
|
|
AboutQET aq(qApp->activeWindow());
|
2017-07-27 20:26:13 +00:00
|
|
|
|
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
aq.setWindowFlags(Qt::Sheet);
|
2009-08-09 16:43:03 +00:00
|
|
|
#endif
|
2017-07-27 20:26:13 +00:00
|
|
|
aq.exec();
|
2009-06-19 19:31:48 +00:00
|
|
|
}
|
|
|
|
|
2007-09-21 18:59:43 +00:00
|
|
|
/**
|
|
|
|
@param window fenetre dont il faut trouver les barres d'outils et dock flottants
|
|
|
|
@return les barres d'outils et dock flottants de la fenetre
|
|
|
|
*/
|
|
|
|
QList<QWidget *> QETApp::floatingToolbarsAndDocksForMainWindow(QMainWindow *window) const {
|
|
|
|
QList<QWidget *> widgets;
|
2018-08-15 12:45:55 +00:00
|
|
|
foreach(QWidget *qw, qApp->topLevelWidgets()) {
|
2007-09-21 18:59:43 +00:00
|
|
|
if (!qw -> isWindow()) continue;
|
|
|
|
if (qobject_cast<QToolBar *>(qw) || qobject_cast<QDockWidget *>(qw)) {
|
|
|
|
if (qw -> parent() == window) widgets << qw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(widgets);
|
|
|
|
}
|
2007-09-22 13:27:14 +00:00
|
|
|
|
2008-07-19 17:34:13 +00:00
|
|
|
/**
|
|
|
|
Parse les arguments suivants :
|
|
|
|
* --common-elements-dir=
|
|
|
|
* --config-dir
|
|
|
|
* --help
|
|
|
|
* --version
|
|
|
|
* -v
|
|
|
|
* --license
|
|
|
|
Les autres arguments sont normalement des chemins de fichiers.
|
|
|
|
S'ils existent, ils sont juste memorises dans l'attribut arguments_files_.
|
|
|
|
Sinon, ils sont memorises dans l'attribut arguments_options_.
|
|
|
|
*/
|
|
|
|
void QETApp::parseArguments() {
|
|
|
|
// recupere les arguments
|
2018-08-15 12:45:55 +00:00
|
|
|
QList<QString> arguments_list(qApp->arguments());
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-19 17:34:13 +00:00
|
|
|
// enleve le premier argument : il s'agit du fichier binaire
|
|
|
|
arguments_list.takeFirst();
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-26 15:26:19 +00:00
|
|
|
// analyse les arguments
|
|
|
|
qet_arguments_ = QETArguments(arguments_list);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-19 17:34:13 +00:00
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
|
2008-07-26 15:26:19 +00:00
|
|
|
if (qet_arguments_.commonElementsDirSpecified()) {
|
|
|
|
overrideCommonElementsDir(qet_arguments_.commonElementsDir());
|
|
|
|
}
|
2008-07-19 17:34:13 +00:00
|
|
|
#endif
|
2012-01-08 17:04:34 +00:00
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CTBTD_OPTION
|
|
|
|
if (qet_arguments_.commonTitleBlockTemplatesDirSpecified()) {
|
|
|
|
overrideCommonTitleBlockTemplatesDir(qet_arguments_.commonTitleBlockTemplatesDir());
|
|
|
|
}
|
|
|
|
#endif
|
2008-07-19 17:34:13 +00:00
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CD_OPTION
|
2008-07-26 15:26:19 +00:00
|
|
|
if (qet_arguments_.configDirSpecified()) {
|
|
|
|
overrideConfigDir(qet_arguments_.configDir());
|
|
|
|
}
|
2008-07-19 17:34:13 +00:00
|
|
|
#endif
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-08-17 21:08:31 +00:00
|
|
|
if (qet_arguments_.langDirSpecified()) {
|
|
|
|
overrideLangDir(qet_arguments_.langDir());
|
|
|
|
}
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-26 15:26:19 +00:00
|
|
|
if (qet_arguments_.printLicenseRequested()) {
|
|
|
|
printLicense();
|
|
|
|
non_interactive_execution_ = true;
|
|
|
|
}
|
|
|
|
if (qet_arguments_.printHelpRequested()) {
|
|
|
|
printHelp();
|
|
|
|
non_interactive_execution_ = true;
|
|
|
|
}
|
|
|
|
if (qet_arguments_.printVersionRequested()) {
|
|
|
|
printVersion();
|
|
|
|
non_interactive_execution_ = true;
|
2008-07-19 17:34:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-02 16:53:42 +00:00
|
|
|
/**
|
|
|
|
Initialise le splash screen si et seulement si l'execution est interactive.
|
|
|
|
Autrement, l'attribut splash_screen_ vaut 0.
|
|
|
|
*/
|
|
|
|
void QETApp::initSplashScreen() {
|
|
|
|
if (non_interactive_execution_) return;
|
2018-05-24 18:08:06 +00:00
|
|
|
m_splash_screen = new QSplashScreen(QPixmap(":/ico/splash.png"));
|
|
|
|
m_splash_screen -> show();
|
2009-04-03 19:30:25 +00:00
|
|
|
setSplashScreenStep(tr("Chargement...", "splash screen caption"));
|
2008-08-02 16:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Change le texte du splash screen et prend en compte les evenements.
|
|
|
|
Si l'application s'execute de facon non interactive, cette methode ne fait
|
|
|
|
rien.
|
|
|
|
*/
|
|
|
|
void QETApp::setSplashScreenStep(const QString &message) {
|
2018-05-24 18:08:06 +00:00
|
|
|
if (!m_splash_screen) return;
|
2008-08-02 16:53:42 +00:00
|
|
|
if (!message.isEmpty()) {
|
2018-05-24 18:08:06 +00:00
|
|
|
m_splash_screen -> showMessage(message, Qt::AlignBottom | Qt::AlignLeft);
|
2008-08-02 16:53:42 +00:00
|
|
|
}
|
2018-08-15 12:45:55 +00:00
|
|
|
qApp->processEvents();
|
2008-08-02 16:53:42 +00:00
|
|
|
}
|
|
|
|
|
2008-07-19 17:34:13 +00:00
|
|
|
/**
|
|
|
|
Determine et applique le langage a utiliser pour l'application
|
|
|
|
*/
|
|
|
|
void QETApp::initLanguage() {
|
2014-01-21 19:23:44 +00:00
|
|
|
setLanguage(langFromSetting());
|
2008-07-19 17:34:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-16 15:11:13 +00:00
|
|
|
* @brief QETApp::initStyle
|
|
|
|
* Setup the gui style
|
|
|
|
*/
|
2008-07-19 17:34:13 +00:00
|
|
|
void QETApp::initStyle() {
|
2018-08-15 12:45:55 +00:00
|
|
|
initial_palette_ = qApp->palette();
|
2015-03-02 20:14:56 +00:00
|
|
|
|
2016-08-25 01:57:20 +00:00
|
|
|
//Apply or not the system style
|
2015-09-16 15:11:13 +00:00
|
|
|
QSettings settings;
|
|
|
|
useSystemPalette(settings.value("usesystemcolors", true).toBool());
|
2008-07-19 17:34:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Lit et prend en compte la configuration de l'application.
|
|
|
|
Cette methode creera, si necessaire :
|
|
|
|
* le dossier de configuration
|
|
|
|
* le dossier de la collection perso
|
2012-01-08 17:04:34 +00:00
|
|
|
* the directory for custom title blocks
|
2008-07-19 17:34:13 +00:00
|
|
|
*/
|
|
|
|
void QETApp::initConfiguration() {
|
|
|
|
// cree les dossiers de configuration si necessaire
|
|
|
|
QDir config_dir(QETApp::configDir());
|
|
|
|
if (!config_dir.exists()) config_dir.mkpath(QETApp::configDir());
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-19 17:34:13 +00:00
|
|
|
QDir custom_elements_dir(QETApp::customElementsDir());
|
|
|
|
if (!custom_elements_dir.exists()) custom_elements_dir.mkpath(QETApp::customElementsDir());
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2012-01-08 17:04:34 +00:00
|
|
|
QDir custom_tbt_dir(QETApp::customTitleBlockTemplatesDir());
|
|
|
|
if (!custom_tbt_dir.exists()) custom_tbt_dir.mkpath(QETApp::customTitleBlockTemplatesDir());
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-30 11:51:27 +00:00
|
|
|
// fichiers recents
|
2009-05-24 17:46:44 +00:00
|
|
|
// note : les icones doivent etre initialisees avant ces instructions (qui creent des menus en interne)
|
2018-05-24 18:08:06 +00:00
|
|
|
m_projects_recent_files = new RecentFiles("projects");
|
|
|
|
m_projects_recent_files -> setIconForFiles(QET::Icons::ProjectFile);
|
|
|
|
m_elements_recent_files = new RecentFiles("elements");
|
|
|
|
m_elements_recent_files -> setIconForFiles(QET::Icons::Element);
|
2008-07-19 17:34:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Construit l'icone dans le systray et son menu
|
|
|
|
*/
|
|
|
|
void QETApp::initSystemTray() {
|
2015-03-02 20:14:56 +00:00
|
|
|
setSplashScreenStep(tr("Chargement... icône du systray", "splash screen caption"));
|
2008-07-19 17:34:13 +00:00
|
|
|
// initialisation des menus de l'icone dans le systray
|
2009-04-03 19:30:25 +00:00
|
|
|
menu_systray = new QMenu(tr("QElectroTech", "systray menu title"));
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2009-05-01 14:41:33 +00:00
|
|
|
quitter_qet = new QAction(QET::Icons::ApplicationExit, tr("&Quitter"), this);
|
|
|
|
reduce_appli = new QAction(QET::Icons::Hide, tr("&Masquer"), this);
|
|
|
|
restore_appli = new QAction(QET::Icons::Restore, tr("&Restaurer"), this);
|
2015-03-02 20:14:56 +00:00
|
|
|
reduce_diagrams = new QAction(QET::Icons::Hide, tr("&Masquer tous les éditeurs de schéma"), this);
|
|
|
|
restore_diagrams = new QAction(QET::Icons::Restore, tr("&Restaurer tous les éditeurs de schéma"), this);
|
|
|
|
reduce_elements = new QAction(QET::Icons::Hide, tr("&Masquer tous les éditeurs d'élément"), this);
|
|
|
|
restore_elements = new QAction(QET::Icons::Restore, tr("&Restaurer tous les éditeurs d'élément"), this);
|
|
|
|
reduce_templates = new QAction(QET::Icons::Hide, tr("&Masquer tous les éditeurs de cartouche", "systray submenu entry"), this);
|
|
|
|
restore_templates = new QAction(QET::Icons::Restore, tr("&Restaurer tous les éditeurs de cartouche", "systray submenu entry"), this);
|
|
|
|
new_diagram = new QAction(QET::Icons::WindowNew, tr("&Nouvel éditeur de schéma"), this);
|
|
|
|
new_element = new QAction(QET::Icons::WindowNew, tr("&Nouvel éditeur d'élément"), this);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-19 17:34:13 +00:00
|
|
|
quitter_qet -> setStatusTip(tr("Ferme l'application QElectroTech"));
|
2015-03-02 20:14:56 +00:00
|
|
|
reduce_appli -> setToolTip(tr("Réduire QElectroTech dans le systray"));
|
2008-07-19 17:34:13 +00:00
|
|
|
restore_appli -> setToolTip(tr("Restaurer QElectroTech"));
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-19 17:34:13 +00:00
|
|
|
connect(quitter_qet, SIGNAL(triggered()), this, SLOT(quitQET()));
|
|
|
|
connect(reduce_appli, SIGNAL(triggered()), this, SLOT(reduceEveryEditor()));
|
|
|
|
connect(restore_appli, SIGNAL(triggered()), this, SLOT(restoreEveryEditor()));
|
|
|
|
connect(reduce_diagrams, SIGNAL(triggered()), this, SLOT(reduceDiagramEditors()));
|
|
|
|
connect(restore_diagrams, SIGNAL(triggered()), this, SLOT(restoreDiagramEditors()));
|
|
|
|
connect(reduce_elements, SIGNAL(triggered()), this, SLOT(reduceElementEditors()));
|
|
|
|
connect(restore_elements, SIGNAL(triggered()), this, SLOT(restoreElementEditors()));
|
2011-12-27 01:39:45 +00:00
|
|
|
connect(reduce_templates, SIGNAL(triggered()), this, SLOT(reduceTitleBlockTemplateEditors()));
|
|
|
|
connect(restore_templates,SIGNAL(triggered()), this, SLOT(restoreTitleBlockTemplateEditors()));
|
2008-07-19 17:34:13 +00:00
|
|
|
connect(new_diagram, SIGNAL(triggered()), this, SLOT(newDiagramEditor()));
|
|
|
|
connect(new_element, SIGNAL(triggered()), this, SLOT(newElementEditor()));
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2008-07-19 17:34:13 +00:00
|
|
|
// initialisation de l'icone du systray
|
2018-05-24 18:08:06 +00:00
|
|
|
m_qsti = new QSystemTrayIcon(QET::Icons::QETLogo, this);
|
|
|
|
m_qsti -> setToolTip(tr("QElectroTech", "systray icon tooltip"));
|
|
|
|
connect(m_qsti, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systray(QSystemTrayIcon::ActivationReason)));
|
|
|
|
m_qsti -> setContextMenu(menu_systray);
|
|
|
|
m_qsti -> show();
|
2008-07-19 17:34:13 +00:00
|
|
|
}
|
|
|
|
|
2011-12-27 01:39:45 +00:00
|
|
|
/**
|
|
|
|
Add a list of \a windows to \a menu.
|
|
|
|
This template function assumes it will be given a QList of pointers to
|
|
|
|
objects inheriting the QMainWindow class.
|
|
|
|
@param T the class inheriting QMainWindow
|
|
|
|
@param menu the menu windows will be added to
|
|
|
|
@param windows A list of top-level windows.
|
|
|
|
*/
|
|
|
|
template <class T> void QETApp::addWindowsListToMenu(QMenu *menu, const QList<T *> &windows) {
|
|
|
|
menu -> addSeparator();
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (QMainWindow *window, windows) {
|
2011-12-27 01:39:45 +00:00
|
|
|
QAction *current_menu = menu -> addAction(window -> windowTitle());
|
|
|
|
current_menu -> setCheckable(true);
|
|
|
|
current_menu -> setChecked(window -> isVisible());
|
|
|
|
connect(current_menu, SIGNAL(triggered()), &signal_map, SLOT(map()));
|
|
|
|
signal_map.setMapping(current_menu, window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-15 19:26:40 +00:00
|
|
|
/**
|
|
|
|
@param url The location of a collection item (title block template,
|
|
|
|
element, category, ...).
|
|
|
|
@return the id of the project mentionned in the URL, or -1 if none could be
|
|
|
|
found.
|
|
|
|
*/
|
|
|
|
int QETApp::projectIdFromString(const QString &url) {
|
|
|
|
QRegExp embedded("^project([0-9]+)\\+embed.*$", Qt::CaseInsensitive);
|
|
|
|
if (embedded.exactMatch(url)) {
|
|
|
|
bool conv_ok = false;
|
|
|
|
int project_id = embedded.capturedTexts().at(1).toInt(&conv_ok);
|
|
|
|
if (conv_ok) {
|
|
|
|
return(project_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param url The location of a collection item (title block template,
|
|
|
|
element, category, ...).
|
|
|
|
@return the project mentionned in the URL, or 0 if none could be
|
|
|
|
found.
|
|
|
|
*/
|
|
|
|
QETProject *QETApp::projectFromString(const QString &url) {
|
|
|
|
int project_id = projectIdFromString(url);
|
2017-08-05 02:06:59 +00:00
|
|
|
if (project_id == -1) return(nullptr);
|
2012-01-15 19:26:40 +00:00
|
|
|
return(project(project_id));
|
|
|
|
}
|
|
|
|
|
2007-09-22 13:27:14 +00:00
|
|
|
/// construit le menu de l'icone dans le systray
|
|
|
|
void QETApp::buildSystemTrayMenu() {
|
|
|
|
menu_systray -> clear();
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2007-09-22 13:27:14 +00:00
|
|
|
// recupere les editeurs
|
|
|
|
QList<QETDiagramEditor *> diagrams = diagramEditors();
|
|
|
|
QList<QETElementEditor *> elements = elementEditors();
|
2011-12-27 01:39:45 +00:00
|
|
|
QList<QETTitleBlockTemplateEditor *> tbtemplates = titleBlockTemplateEditors();
|
|
|
|
fetchWindowStats(diagrams, elements, tbtemplates);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2007-09-22 13:27:14 +00:00
|
|
|
// ajoute le bouton reduire / restaurer au menu
|
|
|
|
menu_systray -> addAction(every_editor_reduced ? restore_appli : reduce_appli);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2007-09-22 13:27:14 +00:00
|
|
|
// ajoute les editeurs de schemas dans un sous-menu
|
2015-03-02 20:14:56 +00:00
|
|
|
QMenu *diagrams_submenu = menu_systray -> addMenu(tr("Éditeurs de schémas"));
|
2007-09-22 13:27:14 +00:00
|
|
|
diagrams_submenu -> addAction(reduce_diagrams);
|
|
|
|
diagrams_submenu -> addAction(restore_diagrams);
|
|
|
|
diagrams_submenu -> addAction(new_diagram);
|
|
|
|
reduce_diagrams -> setEnabled(!diagrams.isEmpty() && !every_diagram_reduced);
|
|
|
|
restore_diagrams -> setEnabled(!diagrams.isEmpty() && !every_diagram_visible);
|
2011-12-27 01:39:45 +00:00
|
|
|
addWindowsListToMenu<QETDiagramEditor>(diagrams_submenu, diagrams);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2007-09-22 13:27:14 +00:00
|
|
|
// ajoute les editeurs d'elements au menu
|
2015-03-02 20:14:56 +00:00
|
|
|
QMenu *elements_submenu = menu_systray -> addMenu(tr("Éditeurs d'élément"));
|
2007-09-22 13:27:14 +00:00
|
|
|
elements_submenu -> addAction(reduce_elements);
|
|
|
|
elements_submenu -> addAction(restore_elements);
|
|
|
|
elements_submenu -> addAction(new_element);
|
|
|
|
reduce_elements -> setEnabled(!elements.isEmpty() && !every_element_reduced);
|
|
|
|
restore_elements -> setEnabled(!elements.isEmpty() && !every_element_visible);
|
|
|
|
elements_submenu -> addSeparator();
|
2011-12-27 01:39:45 +00:00
|
|
|
addWindowsListToMenu<QETElementEditor>(elements_submenu, elements);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2011-12-27 01:39:45 +00:00
|
|
|
// add title block template editors in a submenu
|
2015-03-02 20:14:56 +00:00
|
|
|
QMenu *tbtemplates_submenu = menu_systray -> addMenu(tr("Éditeurs de cartouche", "systray menu entry"));
|
2011-12-27 01:39:45 +00:00
|
|
|
tbtemplates_submenu -> addAction(reduce_templates);
|
|
|
|
tbtemplates_submenu -> addAction(restore_templates);
|
|
|
|
reduce_templates -> setEnabled(!tbtemplates.isEmpty() && !every_template_reduced);
|
|
|
|
restore_templates -> setEnabled(!tbtemplates.isEmpty() && !every_template_visible);
|
|
|
|
addWindowsListToMenu<QETTitleBlockTemplateEditor>(tbtemplates_submenu, tbtemplates);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2007-09-22 13:27:14 +00:00
|
|
|
// ajoute le bouton quitter au menu
|
|
|
|
menu_systray -> addSeparator();
|
|
|
|
menu_systray -> addAction(quitter_qet);
|
|
|
|
}
|
|
|
|
|
2018-05-24 18:08:06 +00:00
|
|
|
/**
|
|
|
|
* @brief QETApp::checkBackupFiles
|
|
|
|
* Check for backup files.
|
|
|
|
* If backup was found, open a dialog and ask user what to do.
|
|
|
|
*/
|
|
|
|
void QETApp::checkBackupFiles()
|
|
|
|
{
|
|
|
|
//Delete all backup files
|
|
|
|
QDir dir(configDir() + "backup");
|
|
|
|
if(dir.exists())
|
|
|
|
{
|
|
|
|
QStringList extension_filter("*.qet");
|
|
|
|
QStringList list = dir.entryList(extension_filter);
|
2018-06-01 18:33:08 +00:00
|
|
|
|
|
|
|
//Remove from the list, the backup file of registred project
|
|
|
|
for(QETProject *project : registeredProjects().values())
|
|
|
|
if(!project->filePath().isEmpty())
|
|
|
|
{
|
|
|
|
QFileInfo info(project->filePath());
|
|
|
|
list.removeOne(info.fileName());
|
|
|
|
}
|
|
|
|
|
2018-05-24 18:08:06 +00:00
|
|
|
if(list.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QString text;
|
|
|
|
if(list.size() == 1)
|
|
|
|
text.append(tr("<b>Le fichier de restauration suivant a été trouvé,<br>"
|
|
|
|
"Voulez-vous l'ouvrir ?</b><br>"));
|
|
|
|
else
|
|
|
|
text.append(tr("<b>Les fichiers de restauration suivant on été trouvé,<br>"
|
|
|
|
"Voulez-vous les ouvrir ?</b><br>"));
|
2018-07-19 14:14:31 +00:00
|
|
|
for(const QString& name : list)
|
2018-05-24 18:08:06 +00:00
|
|
|
text.append("<br>" + name);
|
|
|
|
|
|
|
|
if (QET::QetMessageBox::question(nullptr, tr("Fichier de restauration"), text, QMessageBox::Ok|QMessageBox::Cancel) == QMessageBox::Ok)
|
|
|
|
{
|
|
|
|
QStringList files_list;
|
2018-07-19 14:14:31 +00:00
|
|
|
for(const QString& str : list)
|
2018-05-24 18:08:06 +00:00
|
|
|
files_list << dir.path() + "/" + str;
|
|
|
|
|
|
|
|
QList<QETDiagramEditor *> diagrams_editors = diagramEditors();
|
|
|
|
|
|
|
|
//If there is opened editors, we find those who are visible
|
|
|
|
if (diagrams_editors.count())
|
|
|
|
{
|
|
|
|
QList<QETDiagramEditor *> visible_diagrams_editors;
|
|
|
|
for(QETDiagramEditor *de : diagrams_editors) {
|
|
|
|
if (de->isVisible())
|
|
|
|
visible_diagrams_editors << de;
|
|
|
|
}
|
|
|
|
|
|
|
|
//We take the first visible, or the first one
|
|
|
|
QETDiagramEditor *de_open;
|
|
|
|
if (visible_diagrams_editors.count()) {
|
|
|
|
de_open = visible_diagrams_editors.first();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
de_open = diagrams_editors.first();
|
|
|
|
de_open -> setVisible(true);
|
|
|
|
}
|
|
|
|
|
2018-07-19 14:14:31 +00:00
|
|
|
for(const QString& file : files_list) {
|
2018-05-24 18:08:06 +00:00
|
|
|
de_open -> openAndAddProject(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
new QETDiagramEditor(files_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Because the file was open from backup, we remove the file path of each project opened,
|
|
|
|
//for avoid user to save in the backup directory
|
|
|
|
for(QETDiagramEditor *editor : diagramEditors())
|
|
|
|
{
|
|
|
|
for(ProjectView *pv : editor->openedProjects())
|
|
|
|
{
|
|
|
|
if(files_list.contains(pv->project()->filePath()))
|
|
|
|
pv->project()->setFilePath(QString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-22 13:27:14 +00:00
|
|
|
/// Met a jour les booleens concernant l'etat des fenetres
|
2011-12-27 01:39:45 +00:00
|
|
|
void QETApp::fetchWindowStats(
|
|
|
|
const QList<QETDiagramEditor *> &diagrams,
|
|
|
|
const QList<QETElementEditor *> &elements,
|
|
|
|
const QList<QETTitleBlockTemplateEditor *> &tbtemplates
|
|
|
|
) {
|
2007-09-22 13:27:14 +00:00
|
|
|
// compte le nombre de schemas visibles
|
|
|
|
int visible_diagrams = 0;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QMainWindow *w, diagrams) if (w -> isVisible()) ++ visible_diagrams;
|
2007-09-22 13:27:14 +00:00
|
|
|
every_diagram_reduced = !visible_diagrams;
|
|
|
|
every_diagram_visible = visible_diagrams == diagrams.count();
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2007-09-22 13:27:14 +00:00
|
|
|
// compte le nombre de schemas visibles
|
|
|
|
int visible_elements = 0;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QMainWindow *w, elements) if (w -> isVisible()) ++ visible_elements;
|
2007-09-22 13:27:14 +00:00
|
|
|
every_element_reduced = !visible_elements;
|
|
|
|
every_element_visible = visible_elements == elements.count();
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2011-12-27 01:39:45 +00:00
|
|
|
// count visible template editors
|
|
|
|
int visible_templates = 0;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QMainWindow *window, tbtemplates) {
|
2011-12-27 01:39:45 +00:00
|
|
|
if (window -> isVisible()) ++ visible_templates;
|
|
|
|
}
|
|
|
|
every_template_reduced = !visible_templates;
|
|
|
|
every_template_visible = visible_templates == tbtemplates.count();
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2007-09-22 13:27:14 +00:00
|
|
|
// determine si tous les elements sont reduits
|
|
|
|
every_editor_reduced = every_element_reduced && every_diagram_reduced;
|
|
|
|
}
|
2007-10-10 17:50:26 +00:00
|
|
|
|
2008-07-17 19:25:57 +00:00
|
|
|
#ifdef Q_OS_DARWIN
|
2007-10-10 17:50:26 +00:00
|
|
|
/**
|
2008-07-17 19:25:57 +00:00
|
|
|
Gere les evenements, en particulier l'evenement FileOpen sous MacOs.
|
2007-10-10 17:50:26 +00:00
|
|
|
@param e Evenement a gerer
|
|
|
|
*/
|
|
|
|
bool QETApp::event(QEvent *e) {
|
|
|
|
// gere l'ouverture de fichiers (sous MacOs)
|
|
|
|
if (e -> type() == QEvent::FileOpen) {
|
|
|
|
// nom du fichier a ouvrir
|
|
|
|
QString filename = static_cast<QFileOpenEvent *>(e) -> file();
|
2008-07-17 19:25:57 +00:00
|
|
|
openFiles(QStringList() << filename);
|
2007-10-10 17:50:26 +00:00
|
|
|
return(true);
|
|
|
|
} else {
|
|
|
|
return(QApplication::event(e));
|
|
|
|
}
|
|
|
|
}
|
2008-07-17 19:25:57 +00:00
|
|
|
#endif
|
2007-10-28 01:32:57 +00:00
|
|
|
|
2007-11-18 00:22:19 +00:00
|
|
|
/**
|
|
|
|
Affiche l'aide et l'usage sur la sortie standard
|
|
|
|
*/
|
2007-10-28 01:32:57 +00:00
|
|
|
void QETApp::printHelp() {
|
|
|
|
QString help(
|
2018-08-15 12:45:55 +00:00
|
|
|
tr("Usage : ") + QFileInfo(qApp->applicationFilePath()).fileName() + tr(" [options] [fichier]...\n\n") +
|
2015-03-02 20:14:56 +00:00
|
|
|
tr("QElectroTech, une application de réalisation de schémas électriques.\n\n"
|
2007-10-28 01:32:57 +00:00
|
|
|
"Options disponibles : \n"
|
|
|
|
" --help Afficher l'aide sur les options\n"
|
|
|
|
" -v, --version Afficher la version\n"
|
|
|
|
" --license Afficher la licence\n")
|
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
|
|
|
|
+ tr(" --common-elements-dir=DIR Definir le dossier de la collection d'elements\n")
|
2007-11-18 00:22:19 +00:00
|
|
|
#endif
|
2012-01-08 17:04:34 +00:00
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CTBTD_OPTION
|
|
|
|
+ tr(" --common-tbt-dir=DIR Definir le dossier de la collection de modeles de cartouches\n")
|
|
|
|
#endif
|
2007-11-18 00:22:19 +00:00
|
|
|
#ifdef QET_ALLOW_OVERRIDE_CD_OPTION
|
|
|
|
+ tr(" --config-dir=DIR Definir le dossier de configuration\n")
|
2007-10-28 01:32:57 +00:00
|
|
|
#endif
|
2008-08-17 21:08:31 +00:00
|
|
|
+ tr(" --lang-dir=DIR Definir le dossier contenant les fichiers de langue\n")
|
2007-10-28 01:32:57 +00:00
|
|
|
);
|
|
|
|
std::cout << qPrintable(help) << std::endl;
|
|
|
|
}
|
|
|
|
|
2007-11-18 00:22:19 +00:00
|
|
|
/**
|
|
|
|
Affiche la version sur la sortie standard
|
|
|
|
*/
|
2007-10-28 01:32:57 +00:00
|
|
|
void QETApp::printVersion() {
|
2009-04-03 19:30:25 +00:00
|
|
|
std::cout << qPrintable(QET::displayedVersion) << std::endl;
|
2007-10-28 01:32:57 +00:00
|
|
|
}
|
|
|
|
|
2007-11-18 00:22:19 +00:00
|
|
|
/**
|
|
|
|
Affiche la licence sur la sortie standard
|
|
|
|
*/
|
2007-10-28 01:32:57 +00:00
|
|
|
void QETApp::printLicense() {
|
|
|
|
std::cout << qPrintable(QET::license()) << std::endl;
|
|
|
|
}
|
2007-10-30 14:00:11 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
/**
|
|
|
|
@return la liste des projets avec leurs ids associes
|
|
|
|
*/
|
|
|
|
QMap<uint, QETProject *> QETApp::registeredProjects() {
|
|
|
|
return(registered_projects_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param project Projet a enregistrer aupres de l'application
|
|
|
|
@return true si le projet a pu etre enregistre, false sinon
|
|
|
|
L'echec de l'enregistrement d'un projet signifie generalement qu'il est deja enregistre.
|
|
|
|
*/
|
|
|
|
bool QETApp::registerProject(QETProject *project) {
|
|
|
|
// le projet doit sembler valide
|
|
|
|
if (!project) return(false);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// si le projet est deja enregistre, renvoie false
|
|
|
|
if (projectId(project) != -1) return(false);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// enregistre le projet
|
|
|
|
registered_projects_.insert(next_project_id ++, project);
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Annule l'enregistrement du projet project
|
|
|
|
@param project Projet dont il faut annuler l'enregistrement
|
|
|
|
@return true si l'annulation a reussi, false sinon
|
|
|
|
L'echec de cette methode signifie generalement que le projet n'etait pas enregistre.
|
|
|
|
*/
|
|
|
|
bool QETApp::unregisterProject(QETProject *project) {
|
|
|
|
int project_id = projectId(project);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// si le projet n'est pas enregistre, renvoie false
|
|
|
|
if (project_id == -1) return(false);
|
2015-09-10 16:29:39 +00:00
|
|
|
|
2009-04-03 19:30:25 +00:00
|
|
|
// annule l'enregistrement du projet
|
|
|
|
return(registered_projects_.remove(project_id) == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param id Id du projet voulu
|
|
|
|
@return le projet correspond a l'id passe en parametre
|
|
|
|
*/
|
|
|
|
QETProject *QETApp::project(const uint &id) {
|
|
|
|
if (registered_projects_.contains(id)) {
|
|
|
|
return(registered_projects_[id]);
|
|
|
|
} else {
|
2017-08-05 02:06:59 +00:00
|
|
|
return(nullptr);
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param project Projet dont on souhaite recuperer l'id
|
|
|
|
@return l'id du projet en parametre si celui-ci est enregistre, -1 sinon
|
|
|
|
*/
|
|
|
|
int QETApp::projectId(const QETProject *project) {
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(int id, registered_projects_.keys()) {
|
2009-04-03 19:30:25 +00:00
|
|
|
if (registered_projects_[id] == project) {
|
|
|
|
return(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(-1);
|
|
|
|
}
|