Fix Qt 6 deprecated Qt::SystemLocaleShortDate

The format options
Qt::SystemLocaleDate, Qt::SystemLocaleShortDate
and Qt::SystemLocaleLongDate
shall be removed in Qt 6.
	Their use should be replaced with
QLocale::system().toString(date, QLocale::ShortFormat)
or
QLocale::system().toString(date, QLocale::LongFormat).
This commit is contained in:
Simon De Backer
2020-09-21 20:23:20 +02:00
parent f21cdb4040
commit c7ffae7918
3 changed files with 82 additions and 64 deletions

View File

@@ -17,6 +17,8 @@
*/
#include <QPainter>
#include <utility>
#include <QLocale>
#include "titleblocktemplate.h"
#include "titleblocktemplaterenderer.h"
#include "bordertitleblock.h"
@@ -934,9 +936,12 @@ void BorderTitleBlock::updateDiagramContextForTitleBlock(
}
// ... overridden by the historical and/or dynamically generated fields
QLocale var;
var.dateFormat(QLocale::ShortFormat);
context.addValue("author", btb_author_);
context.addValue("date", btb_date_.toString(
Qt::SystemLocaleShortDate));
context.addValue(
"date",
QLocale::system().toString(btb_date_, QLocale::ShortFormat));
context.addValue("title", btb_title_);
context.addValue("filename", btb_filename_);
context.addValue("plant", btb_plant_);

View File

@@ -24,6 +24,7 @@
#include "diagramposition.h"
#include <QSqlError>
#include <QLocale>
#if defined(Q_OS_LINUX) || defined(Q_OS_WINDOWS)
#include <QSqlDriver>
@@ -161,7 +162,11 @@ void projectDataBase::addDiagram(Diagram *diagram)
for (auto key : QETApp::diagramInfoKeys())
{
if (key == "date") {
m_insert_diagram_info_query.bindValue(":date", QDate::fromString(infos.value("date").toString(), Qt::SystemLocaleShortDate));
m_insert_diagram_info_query.bindValue(
":date",
QLocale::system().toString(
infos.value("date").toDate(),
QLocale::ShortFormat));
} else {
auto value = infos.value(key);
auto bind = key.prepend(":");
@@ -419,7 +424,11 @@ void projectDataBase::populateDiagramInfoTable()
for (auto key : QETApp::diagramInfoKeys())
{
if (key == "date") {
m_insert_diagram_info_query.bindValue(":date", QDate::fromString(infos.value("date").toString(), Qt::SystemLocaleShortDate));
m_insert_diagram_info_query.bindValue(
":date",
QLocale::system().toString(
infos.value("date").toDate(),
QLocale::ShortFormat));
} else {
auto value = infos.value(key);
auto bind = key.prepend(":");

View File

@@ -934,7 +934,11 @@ QETResult QETProject::write()
return(error_message);
//title block variables should be updated after file save dialog is confirmed, before file is saved.
m_project_properties.addValue("saveddate", QDate::currentDate().toString(Qt::SystemLocaleShortDate));
m_project_properties.addValue(
"saveddate",
QDate::currentDate().toString(
QLocale::system().toString(
QLocale::ShortFormat)));
m_project_properties.addValue("savedtime", QDateTime::currentDateTime().toString("HH:mm"));
m_project_properties.addValue("savedfilename", QFileInfo(filePath()).baseName());
m_project_properties.addValue("savedfilepath", filePath());