Improve and simplify the use of versions

This commit is contained in:
joshua 2023-01-19 20:18:21 +01:00
parent ad4e263198
commit a0970b37b9
12 changed files with 175 additions and 55 deletions

View File

@ -22,9 +22,11 @@
#include "diagramposition.h" #include "diagramposition.h"
#include "math.h" #include "math.h"
#include "qetapp.h" #include "qetapp.h"
#include "qetversion.h"
#include "titleblocktemplate.h" #include "titleblocktemplate.h"
#include "titleblocktemplaterenderer.h" #include "titleblocktemplaterenderer.h"
#include <QLocale> #include <QLocale>
#include <QPainter> #include <QPainter>
#include <utility> #include <utility>
@ -317,7 +319,7 @@ void BorderTitleBlock::importTitleBlock(const TitleBlockProperties &ip) {
setPlant(ip.plant); setPlant(ip.plant);
setLocMach(ip.locmach); setLocMach(ip.locmach);
setIndicerev(ip.indexrev); setIndicerev(ip.indexrev);
setVersion(QET::displayedVersion); setVersion(QetVersion::displayedVersion());
setFolio(ip.folio); setFolio(ip.folio);
setAutoPageNum(ip.auto_page_num); setAutoPageNum(ip.auto_page_num);
if (m_edge != ip.display_at) if (m_edge != ip.display_at)

View File

@ -35,6 +35,7 @@
#include "graphicspart/parttext.h" #include "graphicspart/parttext.h"
#include "ui/qetelementeditor.h" #include "ui/qetelementeditor.h"
#include "ui/elementpropertieseditorwidget.h" #include "ui/elementpropertieseditorwidget.h"
#include "../qetversion.h"
#include <QKeyEvent> #include <QKeyEvent>
#include <algorithm> #include <algorithm>
@ -448,7 +449,7 @@ const QDomDocument ElementScene::toXml(bool all_parts)
root.setAttribute("hotspot_y", QString("%1").arg( root.setAttribute("hotspot_y", QString("%1").arg(
-(qRound(size.y() - (ymargin/2))))); -(qRound(size.y() - (ymargin/2)))));
root.setAttribute("version", QET::version); QetVersion::toXmlAttribute(root);
root.setAttribute("link_type", m_element_data.typeToString(m_element_data.m_type)); root.setAttribute("link_type", m_element_data.typeToString(m_element_data.m_type));
//Uuid used to compare two elements //Uuid used to compare two elements

View File

@ -19,8 +19,8 @@
#include "../ElementsCollection/elementslocation.h" #include "../ElementsCollection/elementslocation.h"
#include "../editor/graphicspart/partline.h" #include "../editor/graphicspart/partline.h"
#include "../qet.h"
#include "../qetapp.h" #include "../qetapp.h"
#include "../qetversion.h"
#include <QAbstractTextDocumentLayout> #include <QAbstractTextDocumentLayout>
#include <QDomElement> #include <QDomElement>
@ -154,19 +154,16 @@ bool ElementPictureFactory::build(const ElementsLocation &location,
QDomElement dom = location.xml(); QDomElement dom = location.xml();
//Check if the current version can read the xml description //Check if the current version can read the xml description
if (dom.hasAttribute("version")) const auto elmt_version = QetVersion::fromXmlAttribute(dom);
{ if (!elmt_version.isNull()
QVersionNumber qet_version = QVersionNumber::fromString(QET::version); && QetVersion::currentVersion() < elmt_version)
QVersionNumber element_version = QVersionNumber::fromString(dom.attribute("version")); {
if (qet_version < element_version) std::cerr << qPrintable(
{ QObject::tr("Avertissement : l'élément "
std::cerr << qPrintable( " a été enregistré avec une version"
QObject::tr("Avertissement : l'élément " " ultérieure de QElectroTech.")
" a été enregistré avec une version" ) << std::endl;
" ultérieure de QElectroTech.") }
) << std::endl;
}
}
//This attributes must be present and valid //This attributes must be present and valid
int w, h, hot_x, hot_y; int w, h, hot_x, hot_y;

View File

@ -16,6 +16,9 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "machine_info.h" #include "machine_info.h"
#include "qetversion.h"
#include <QScreen> #include <QScreen>
#include <QProcess> #include <QProcess>
#include <QApplication> #include <QApplication>
@ -28,7 +31,6 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <windows.h> #include <windows.h>
#endif #endif
#include "qet.h"
MachineInfo *MachineInfo::m_instance = nullptr; MachineInfo *MachineInfo::m_instance = nullptr;
/** /**
@ -121,7 +123,7 @@ void MachineInfo::send_info_to_debug()
#endif #endif
#endif #endif
qInfo() << "GitRevision " + QString(GIT_COMMIT_SHA); qInfo() << "GitRevision " + QString(GIT_COMMIT_SHA);
qInfo()<< "QElectroTech V " + QET::displayedVersion; qInfo()<< "QElectroTech V " + QetVersion::displayedVersion();
qInfo()<< QObject::tr("Compilation : ") + pc.built.version; qInfo()<< QObject::tr("Compilation : ") + pc.built.version;
qInfo()<< "Built with Qt " + pc.built.QT qInfo()<< "Built with Qt " + pc.built.QT
+ " - " + pc.built.arch + " - " + pc.built.arch

View File

@ -20,6 +20,8 @@
#include "../diagram.h" #include "../diagram.h"
#include "../qeticons.h" #include "../qeticons.h"
#include "../qetproject.h" #include "../qetproject.h"
#include "../qetversion.h"
#include "ui_projectprintwindow.h" #include "ui_projectprintwindow.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
@ -84,7 +86,7 @@ void ProjectPrintWindow::launchDialog(QETProject *project, QPrinter::OutputForma
if (!file_name.endsWith(".pdf")) { if (!file_name.endsWith(".pdf")) {
file_name.append(".pdf"); file_name.append(".pdf");
} }
printer_->setCreator(QString("QElectroTech %1").arg(QET::displayedVersion)); printer_->setCreator(QString("QElectroTech %1").arg(QetVersion::displayedVersion()));
printer_->setOutputFileName(file_name); printer_->setOutputFileName(file_name);
printer_->setOutputFormat(QPrinter::PdfFormat); printer_->setOutputFormat(QPrinter::PdfFormat);
} }

View File

@ -28,10 +28,6 @@ class QActionGroup;
anywhere else within the QElectroTech application. anywhere else within the QElectroTech application.
*/ */
namespace QET { namespace QET {
/// QElectroTech version (as string, used to mark projects and elements XML documents)
const QString version = "0.100";
/// QElectroTech displayed version
const QString displayedVersion = "0.100-DEV";
QString license(); QString license();
//Describe the current state of a graphic item //Describe the current state of a graphic item

View File

@ -37,6 +37,7 @@
#include "ui/configpage/generalconfigurationpage.h" #include "ui/configpage/generalconfigurationpage.h"
#include "machine_info.h" #include "machine_info.h"
#include "TerminalStrip/ui/terminalstripeditorwindow.h" #include "TerminalStrip/ui/terminalstripeditorwindow.h"
#include "qetversion.h"
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
@ -2314,7 +2315,7 @@ void QETApp::printHelp()
*/ */
void QETApp::printVersion() void QETApp::printVersion()
{ {
std::cout << qPrintable(QET::displayedVersion) << std::endl; std::cout << qPrintable(QetVersion::displayedVersion()) << std::endl;
} }
/** /**

View File

@ -34,6 +34,7 @@
#include "elementtextitemgroup.h" #include "elementtextitemgroup.h"
#include "iostream" #include "iostream"
#include "../qetxml.h" #include "../qetxml.h"
#include "../qetversion.h"
#include <QDomElement> #include <QDomElement>
#include <utility> #include <utility>
@ -426,20 +427,17 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
return(false); return(false);
} }
//Check if the current version can read the xml description //Check if the current version can read the xml description
if (xml_def_elmt.hasAttribute(QStringLiteral("version"))) const auto elmt_version = QetVersion::fromXmlAttribute(xml_def_elmt);
{ if (!elmt_version.isNull()
QVersionNumber qet_version = QVersionNumber::fromString(QET::version); && QetVersion::currentVersion() < elmt_version)
QVersionNumber element_version = QVersionNumber::fromString(xml_def_elmt.attribute(QStringLiteral("version"))); {
if (qet_version < element_version) std::cerr << qPrintable(
{ QObject::tr("Avertissement : l'élément "
std::cerr << qPrintable( " a été enregistré avec une version"
QObject::tr("Avertissement : l'élément " " ultérieure de QElectroTech.")
" a été enregistré avec une version" ) << std::endl;
" ultérieure de QElectroTech.") }
) << std::endl;
}
}
//This attribute must be present and valid //This attribute must be present and valid
int w = 0, h = 0, hot_x = 0, hot_y = 0; int w = 0, h = 0, hot_x = 0, hot_y = 0;

View File

@ -33,6 +33,7 @@
#include "ui/importelementdialog.h" #include "ui/importelementdialog.h"
#include "TerminalStrip/terminalstrip.h" #include "TerminalStrip/terminalstrip.h"
#include "qetxml.h" #include "qetxml.h"
#include "qetversion.h"
#include <QHash> #include <QHash>
#include <QStandardPaths> #include <QStandardPaths>
@ -907,7 +908,7 @@ QDomDocument QETProject::toXml()
// racine du projet // racine du projet
QDomDocument xml_doc; QDomDocument xml_doc;
QDomElement project_root = xml_doc.createElement("project"); QDomElement project_root = xml_doc.createElement("project");
project_root.setAttribute("version", QET::version); QetVersion::toXmlAttribute(project_root);
if (project_title_.isEmpty()) if (project_title_.isEmpty())
{ {
// if project_title_is Empty add title from m_file_path // if project_title_is Empty add title from m_file_path
@ -1337,18 +1338,11 @@ void QETProject::readProjectXml(QDomDocument &xml_project)
if (root_elmt.tagName() == QLatin1String("project")) if (root_elmt.tagName() == QLatin1String("project"))
{ {
//Normal opening mode //Normal opening mode
if (root_elmt.hasAttribute(QStringLiteral("version"))) m_project_qet_version = QetVersion::fromXmlAttribute(root_elmt);
if (!m_project_qet_version.isNull())
{ {
bool conv_ok; if (QetVersion::currentVersion() < m_project_qet_version)
QVersionNumber qet_version = QVersionNumber::fromString(QET::version);
m_project_qet_version = QVersionNumber::fromString(root_elmt.attribute(QStringLiteral("version")));
#if TODO_LIST
#pragma message("@TODO use of version convert")
#endif
if (qet_version < m_project_qet_version)
{ {
int ret = QET::QetMessageBox::warning( int ret = QET::QetMessageBox::warning(
nullptr, nullptr,
tr("Avertissement", tr("Avertissement",
@ -1357,7 +1351,7 @@ void QETProject::readProjectXml(QDomDocument &xml_project)
"\n qui est ultérieure à votre version !" "\n qui est ultérieure à votre version !"
" \n" " \n"
"Vous utilisez actuellement QElectroTech en version %2") "Vous utilisez actuellement QElectroTech en version %2")
.arg(root_elmt.attribute(QStringLiteral("version")), QET::version + .arg(root_elmt.attribute(QStringLiteral("version")), QetVersion::currentVersion().toString() +
tr(".\n Il est alors possible que l'ouverture de tout ou partie de ce " tr(".\n Il est alors possible que l'ouverture de tout ou partie de ce "
"document échoue.\n" "document échoue.\n"
"Que désirez vous faire ?"), "Que désirez vous faire ?"),
@ -1374,16 +1368,14 @@ void QETProject::readProjectXml(QDomDocument &xml_project)
//Since QElectrotech 0.9 the compatibility with project made with //Since QElectrotech 0.9 the compatibility with project made with
//Qet 0.6 or lower is break; //Qet 0.6 or lower is break;
//keep float here for very old version if (m_project_qet_version <= QetVersion::versionZeroDotSix())
qreal r_project_qet_version = root_elmt.attribute(QStringLiteral("version")).toDouble(&conv_ok);
if (conv_ok && m_project_qet_version < QVersionNumber(0, 100) && r_project_qet_version <= 0.6)
{ {
auto ret = QET::QetMessageBox::warning( auto ret = QET::QetMessageBox::warning(
nullptr, nullptr,
tr("Avertissement ", "message box title"), tr("Avertissement ", "message box title"),
tr("Le projet que vous tentez d'ouvrir est partiellement " tr("Le projet que vous tentez d'ouvrir est partiellement "
"compatible avec votre version %1 de QElectroTech.\n") "compatible avec votre version %1 de QElectroTech.\n")
.arg(QET::version) + .arg(QetVersion::currentVersion().toString()) +
tr("Afin de le rendre totalement compatible veuillez ouvrir ce même projet " tr("Afin de le rendre totalement compatible veuillez ouvrir ce même projet "
"avec la version 0.8, ou 0.80 de QElectroTech et sauvegarder le projet " "avec la version 0.8, ou 0.80 de QElectroTech et sauvegarder le projet "
"et l'ouvrir à nouveau avec cette version.\n" "et l'ouvrir à nouveau avec cette version.\n"

85
sources/qetversion.cpp Normal file
View File

@ -0,0 +1,85 @@
/*
Copyright 2006-2023 The QElectroTech Team
This file is part of QElectroTech.
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.
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.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qetversion.h"
namespace QetVersion
{
QetVersion::VersionType VERSION_TYPE = QetVersion::dev;
QVersionNumber currentVersion()
{
return QVersionNumber{ 0, 100, 0 };
}
QString displayedVersion()
{
auto str = currentVersion().toString();
switch (VERSION_TYPE) {
case dev:
str.append(QStringLiteral("-dev"));
break;
case alpha1:
str.append(QStringLiteral("-alpha 1 "));
break;
case alpha2:
str.append(QStringLiteral("-alpha 2 "));
break;
case alpha3:
str.append(QStringLiteral("-alpha 3 "));
break;
default:
break;
}
return str;
}
/**
* @brief toXmlAttribute
* Write @a version as an attribute of @a xml
* @param xml
* @param version
*/
void toXmlAttribute(QDomElement &xml)
{
xml.setAttribute(QStringLiteral("version"), currentVersion().toString());
}
/**
* @brief fromXmlAttribute
* Read and return a QVersionNumber
* stored as attribute of @a xml
* @param xml
* @return the version stored in @a xml.
* Note that the returned version can be null
*/
QVersionNumber fromXmlAttribute(const QDomElement &xml)
{
if (xml.hasAttribute(QStringLiteral("version"))) {
return QVersionNumber::fromString(xml.attribute(QStringLiteral("version")));
} else {
return QVersionNumber{};
}
}
QVersionNumber versionZeroDotSix()
{
return QVersionNumber{ 0, 60 };
}
}

43
sources/qetversion.h Normal file
View File

@ -0,0 +1,43 @@
/*
Copyright 2006-2023 The QElectroTech Team
This file is part of QElectroTech.
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.
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.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef QETVERSION_H
#define QETVERSION_H
#include <QVersionNumber>
#include <QDomElement>
namespace QetVersion
{
enum VersionType {
dev = 0,
alpha1 = 1,
alpha2 = 2,
alpha3 = 3,
stable = 4
};
QVersionNumber currentVersion();
QString displayedVersion();
QVersionNumber versionZeroDotSix();
void toXmlAttribute(QDomElement &xml);
QVersionNumber fromXmlAttribute(const QDomElement &xml);
}
#endif // QETVERSION_H

View File

@ -21,6 +21,7 @@
#include "../qet.h" #include "../qet.h"
#include "../qetapp.h" #include "../qetapp.h"
#include "ui_aboutqetdialog.h" #include "ui_aboutqetdialog.h"
#include "../qetversion.h"
#include <QDate> #include <QDate>
@ -165,7 +166,7 @@ void AboutQETDialog::setContributors()
void AboutQETDialog::setVersion() void AboutQETDialog::setVersion()
{ {
QString str = "<span style=\"font-weight:bold;font-size:16pt;\">QElectroTech V " QString str = "<span style=\"font-weight:bold;font-size:16pt;\">QElectroTech V "
+ QET::displayedVersion + QetVersion::displayedVersion()
+ "</span>"; + "</span>";
ui->m_version_label->setText(str + MachineInfo::instance()->compilation_info()); ui->m_version_label->setText(str + MachineInfo::instance()->compilation_info());
} }