From 03f18c3dc5dc428c7943fce9b13091a42c7f40df Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Tue, 5 Nov 2024 22:54:53 +0100 Subject: [PATCH] Make kraft compile against Qt6 - all tests pass --- src/addressselectorwidget.cpp | 4 +- src/alldocsview.cpp | 4 +- src/defaultprovider.cpp | 2 +- src/docassistant.cpp | 5 +- src/docdigestdetailview.cpp | 2 +- src/flostempldialog.cpp | 2 +- src/format.cpp | 7 +- src/grantleetemplate.cpp | 23 +-- src/grantleetemplate.h | 6 +- src/importfilter.cpp | 373 +++++++++++++++++----------------- src/kataloglistview.cpp | 14 +- src/kraftdb.cpp | 26 +-- src/kraftdoc.cpp | 29 ++- src/kraftview.cpp | 4 +- src/myidentity.cpp | 4 - src/pdfconverter.cpp | 1 - src/positionviewwidget.cpp | 2 +- src/reportitem.cpp | 4 +- src/setupassistant.cpp | 2 +- src/textselection.cpp | 2 +- src/xmldocindex.cpp | 2 +- tests/t_attributes.cpp | 2 +- tests/t_defaultprovider.cpp | 4 +- tests/t_doctype.cpp | 2 +- tests/t_format.cpp | 2 +- tests/t_jsonindexfile.cpp | 2 +- tests/t_kraftattrib.cpp | 2 +- tests/t_kraftdoc.cpp | 2 +- tests/t_metaparser.cpp | 2 +- tests/t_numbercycle.cpp | 2 +- tests/t_stringutil.cpp | 2 +- tests/t_unitman.cpp | 2 +- tests/t_xmlsaver.cpp | 2 +- 33 files changed, 267 insertions(+), 277 deletions(-) diff --git a/src/addressselectorwidget.cpp b/src/addressselectorwidget.cpp index d6a1b392..868e17a1 100644 --- a/src/addressselectorwidget.cpp +++ b/src/addressselectorwidget.cpp @@ -204,7 +204,7 @@ bool AddressSortProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) if( contact.isEmpty() ) { return true; } else { - const QString p = filterRegExp().pattern(); + const QString p = filterRegularExpression().pattern(); return contactMatchesFilter(contact, p ); } @@ -232,7 +232,7 @@ KraftContactViewer::KraftContactViewer(QWidget *parent) #endif { QVBoxLayout *lay = new QVBoxLayout; - lay->setMargin(0); + lay->setContentsMargins(0,0,0,0); setLayout(lay); #ifdef HAVE_AKONADI #if AKONADICONTACT_VERSION >= QT_VERSION_CHECK(5, 24, 0) diff --git a/src/alldocsview.cpp b/src/alldocsview.cpp index 722af9eb..c8637ab3 100644 --- a/src/alldocsview.cpp +++ b/src/alldocsview.cpp @@ -51,7 +51,7 @@ AllDocsView::AllDocsView( QWidget *parent ) QVBoxLayout *box = new QVBoxLayout; setLayout( box ); - box->setMargin( 0 ); + box->setContentsMargins(0,0,0,0); box->setSpacing( 0 ); _searchLine = new QLineEdit(this); @@ -140,7 +140,7 @@ QWidget* AllDocsView::initializeTreeWidget() //Add treewidgets to the toolbox: All docs view QVBoxLayout *vb1 = new QVBoxLayout; - vb1->setMargin(0); + vb1->setContentsMargins(0,0,0,0); _stack = new QStackedWidget(this); _stack->addWidget(_tableView); _stack->addWidget(_dateView); diff --git a/src/defaultprovider.cpp b/src/defaultprovider.cpp index e4fe44ba..893c5fb0 100644 --- a/src/defaultprovider.cpp +++ b/src/defaultprovider.cpp @@ -363,7 +363,7 @@ QString DefaultProvider::createV2BaseDir(const QString& base) } if (v2base.isEmpty()) { - v2base = QStandardPaths::writableLocation(QStandardPaths::DataLocation); + v2base = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); v2base.append("/v2"); currV2Dir.setPath(v2base); diff --git a/src/docassistant.cpp b/src/docassistant.cpp index f7c0426e..3bb9b425 100644 --- a/src/docassistant.cpp +++ b/src/docassistant.cpp @@ -33,7 +33,6 @@ #include "headertemplateprovider.h" #include "footertemplateprovider.h" #include "catalogtemplateprovider.h" -#include "addresstemplateprovider.h" DocAssistant::DocAssistant( QWidget *parent ): QSplitter( parent ), mFullPreview( true ), @@ -43,7 +42,7 @@ DocAssistant::DocAssistant( QWidget *parent ): QWidget *topWidget = new QWidget; QVBoxLayout *topVBox = new QVBoxLayout; - topVBox->setMargin(0); + topVBox->setContentsMargins(0,0,0,0); topWidget->setLayout( topVBox ); QHBoxLayout *buttonLayout = new QHBoxLayout; @@ -68,7 +67,7 @@ DocAssistant::DocAssistant( QWidget *parent ): mTemplatePane = new QWidget; QVBoxLayout *bottomVBox = new QVBoxLayout; - bottomVBox->setMargin(0); + bottomVBox->setContentsMargins(0,0,0,0); mTemplatePane->setLayout( bottomVBox ); addWidget( mTemplatePane ); diff --git a/src/docdigestdetailview.cpp b/src/docdigestdetailview.cpp index 365b9e07..ebcabc67 100644 --- a/src/docdigestdetailview.cpp +++ b/src/docdigestdetailview.cpp @@ -86,7 +86,7 @@ DocDigestDetailView::DocDigestDetailView(QWidget *parent) : _leftDetails->setWordWrap(true); // --- The middle HTML based view - hbox->setMargin(0); + hbox->setContentsMargins(0,0,0,0); setLayout( hbox ); mHtmlCanvas = new DocDigestHtmlView( this ); mHtmlCanvas->setFrameStyle(0); diff --git a/src/flostempldialog.cpp b/src/flostempldialog.cpp index cb541056..8ba2adbc 100644 --- a/src/flostempldialog.cpp +++ b/src/flostempldialog.cpp @@ -829,7 +829,7 @@ void FlosTemplDialog::slSetNewText() longest = p; } QFontMetrics fm(m_textDispFix->font()); - int w = 10+fm.width(longest); + int w = 10+fm.boundingRect(longest).width(); if( m_textDispTime) { m_textDispTime->setText(t); diff --git a/src/format.cpp b/src/format.cpp index 5949e46c..ca05dc80 100644 --- a/src/format.cpp +++ b/src/format.cpp @@ -40,14 +40,17 @@ QString localeDoubleToString(double val, const QLocale& loc) QString toDateString( const QDate& date, const QString& format ) { + QLocale locale; if (format == Format::DateFormatIso) { return date.toString(Qt::ISODate); } if (format == DateFormatShort || format.isEmpty()) { - return date.toString(Qt::DefaultLocaleShortDate); + const QString shortDateFormat = locale.dateFormat(QLocale::ShortFormat); + return date.toString(shortDateFormat); } if (format == DateFormatLong) { - return date.toString(Qt::DefaultLocaleLongDate); + const QString longDateFormat = locale.dateFormat(QLocale::LongFormat); + return date.toString(longDateFormat); } if (format == DateFormatRFC) { return date.toString(Qt::RFC2822Date); diff --git a/src/grantleetemplate.cpp b/src/grantleetemplate.cpp index 65982f15..ad9d5f32 100644 --- a/src/grantleetemplate.cpp +++ b/src/grantleetemplate.cpp @@ -21,12 +21,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include // make this class a QObject to parent the created QObjects in addToMappingHash() // to it. That way, the allocated objects are automatically freed by the Qt mechanism @@ -69,25 +68,25 @@ void GrantleeFileTemplate::addToObjMapping(const QString& key, QObject *obj) QString GrantleeFileTemplate::render(bool &ok) const { - QScopedPointer engine(new Grantlee::Engine()); + QScopedPointer engine(new KTextTemplate::Engine()); QFileInfo fi(_tmplFileName); ok = true; // assume all goes well. - auto loader = QSharedPointer::create(); + auto loader = QSharedPointer::create(); loader->setTemplateDirs( {fi.absolutePath()} ); engine->addTemplateLoader( loader ); QString output; auto t = engine->loadByName(fi.fileName()); - if (t->error() != Grantlee::Error::NoError) { + if (t->error() != KTextTemplate::Error::NoError) { ok = false; output = t->errorString(); - qDebug() << "Grantlee template load failed:" << output; + qDebug() << "TextTemplate template load failed:" << output; } if (ok) { - Grantlee::Context c; + KTextTemplate::Context c; QHash::const_iterator i = _objs.constBegin(); while (i != _objs.constEnd()) { @@ -98,11 +97,11 @@ QString GrantleeFileTemplate::render(bool &ok) const } output = t->render(&c); - if (t->error() != Grantlee::Error::NoError) { + if (t->error() != KTextTemplate::Error::NoError) { ok = false; // Rendering error. output = t->errorString(); - qDebug() << "Grantlee template err:" << output; + qDebug() << "TextTemplate template err:" << output; } } diff --git a/src/grantleetemplate.h b/src/grantleetemplate.h index b8fcc7d2..33333c8c 100644 --- a/src/grantleetemplate.h +++ b/src/grantleetemplate.h @@ -17,9 +17,9 @@ #ifndef GRANTLEETEMPLATE_H #define GRANTLEETEMPLATE_H -#include -#include -#include +#include +#include +#include class GrantleeFileTemplate : public QObject { diff --git a/src/importfilter.cpp b/src/importfilter.cpp index d27368d9..7ada9419 100644 --- a/src/importfilter.cpp +++ b/src/importfilter.cpp @@ -32,259 +32,258 @@ ImportFilter::ImportFilter() - : mStrict( true ) + : mStrict( true ) { } bool ImportFilter::readDefinition( const QString& name ) { - QString defFile = name; - if ( ! name.startsWith( "/" ) ) { - QString defFileName = QString( name ).toLower(); - QString findFile = kdeStdDirPath() + defFileName; - - // qDebug () << "KDE StdDir Path: " << findFile; - defFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, findFile); - if ( defFile.isEmpty() ) { - mError = i18n( "Unable to find filter called %1", name ); - return false; + QString defFile = name; + if ( ! name.startsWith( "/" ) ) { + QString defFileName = QString( name ).toLower(); + QString findFile = kdeStdDirPath() + defFileName; + + // qDebug () << "KDE StdDir Path: " << findFile; + defFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, findFile); + if ( defFile.isEmpty() ) { + mError = i18n( "Unable to find filter called %1", name ); + return false; + } } - } - // qDebug () << "Reading definition file " << defFile; - QFile f( defFile ); - if ( !f.open( QIODevice::ReadOnly ) ) { - mError = i18n( "Could not open the definition file!" ); - return false; - } + // qDebug () << "Reading definition file " << defFile; + QFile f( defFile ); + if ( !f.open( QIODevice::ReadOnly ) ) { + mError = i18n( "Could not open the definition file!" ); + return false; + } - QTextStream t( &f ); + QTextStream t( &f ); - while ( !t.atEnd() ) { - mDefinition << t.readLine(); - } - f.close(); - return true; + while ( !t.atEnd() ) { + mDefinition << t.readLine(); + } + f.close(); + return true; } bool ImportFilter::parse() { - return true; + return true; } bool ImportFilter::recode( const QString& file, const QString& outfile ) { - if ( mEncoding.isEmpty() ) return true; + if ( mEncoding.isEmpty() ) return true; - QString cmd = DefaultProvider::self()->iconvTool(); + QString cmd = DefaultProvider::self()->iconvTool(); - if ( QFile::exists( cmd ) ) { - QStringList args = QStringList() - << "-f" << mEncoding << "-t" << "utf-8" << "-o" << outfile << file; - int result = QProcess::execute( cmd, args ); - Q_UNUSED(result); - // qDebug () << "Recode finished with exit code " << result; - return true; - } else { - // qDebug () << "Recode-tool does not exist!"; - } - return false; + if ( QFile::exists( cmd ) ) { + QStringList args = QStringList() + << "-f" << mEncoding << "-t" << "utf-8" << "-o" << outfile << file; + int result = QProcess::execute( cmd, args ); + Q_UNUSED(result); + // qDebug () << "Recode finished with exit code " << result; + return true; + } else { + // qDebug () << "Recode-tool does not exist!"; + } + return false; } // ########################################################################### DocPositionImportFilter::DocPositionImportFilter() - :ImportFilter( ) + :ImportFilter( ) { } QString DocPositionImportFilter::kdeStdDirPath() const { - QString re = QString::fromLatin1( "kraft/importfilter/positions/" ); - return re; + QString re = QString::fromLatin1( "kraft/importfilter/positions/" ); + return re; } #define FILTER_TAG( x, y ) x bool DocPositionImportFilter::parseDefinition() { - bool ret = true; - for ( QStringList::Iterator it = mDefinition.begin(); it != mDefinition.end(); ++it ) { - QString l = ( *it ).trimmed(); - - if ( l.isEmpty() || l.startsWith( "#" ) ) { - // continue - whitespace.... - } else if ( l.startsWith( FILTER_TAG( "amount:", "amount of the item" ), Qt::CaseInsensitive ) ) { - mAmount = ( l.right( l.length()-7 ) ).trimmed(); - } else if ( l.startsWith( FILTER_TAG( "text:", "The item text" ), Qt::CaseInsensitive ) ) { - mText = ( l.right( l.length()-5 ) ).trimmed(); - mText.replace( "
", QChar( 0x0A ) ); - } else if ( l.startsWith( FILTER_TAG( "unit:", "The item unit" ), Qt::CaseInsensitive ) ) { - mUnit = ( l.right( l.length()-5 ) ).trimmed(); - } else if ( l.startsWith( FILTER_TAG( "unit_price:", "unit price" ), Qt::CaseInsensitive ) ) { - mUnitPrice = ( l.right( l.length()-11 ) ).trimmed(); - } else if ( l.startsWith( FILTER_TAG( "name:", "The name of the filter" ), Qt::CaseInsensitive ) ) { - mName = ( l.right( l.length()-5 ) ).trimmed(); - } else if ( l.startsWith( FILTER_TAG( "description:", "The filter description" ), Qt::CaseInsensitive ) ) { - mDescription = ( l.right( l.length()-12 ) ).trimmed(); - } else if ( l.startsWith( FILTER_TAG("encoding:", "The encoding of the source file" ), Qt::CaseInsensitive ) ) { - mEncoding = ( l.right( l.length()-9 ) ).trimmed(); - } else if ( l.startsWith( FILTER_TAG( "separator:", "The separator used in the source file" ), Qt::CaseInsensitive ) ) { - // qDebug () << "Separator found: " << l.right( l.length()-10 ); - mSeparator = ( l.right( l.length()-10 ) ).trimmed(); - } else if ( l.startsWith( FILTER_TAG( "tags:", "Comma separated list of tags for one item" ), Qt::CaseInsensitive ) ) { - mTags = ( l.right( l.length()-5 ) ).trimmed(); - } else { - // qDebug () << "WRN: Unknown filter tag found: " << l; - if ( mError.isEmpty() ) mError = i18n( "Unknown tags: " ); - mError.append( l ); - ret = false; + bool ret = true; + for ( QStringList::Iterator it = mDefinition.begin(); it != mDefinition.end(); ++it ) { + QString l = ( *it ).trimmed(); + + if ( l.isEmpty() || l.startsWith( "#" ) ) { + // continue - whitespace.... + } else if ( l.startsWith( FILTER_TAG( "amount:", "amount of the item" ), Qt::CaseInsensitive ) ) { + mAmount = ( l.right( l.length()-7 ) ).trimmed(); + } else if ( l.startsWith( FILTER_TAG( "text:", "The item text" ), Qt::CaseInsensitive ) ) { + mText = ( l.right( l.length()-5 ) ).trimmed(); + mText.replace( "
", QChar( 0x0A ) ); + } else if ( l.startsWith( FILTER_TAG( "unit:", "The item unit" ), Qt::CaseInsensitive ) ) { + mUnit = ( l.right( l.length()-5 ) ).trimmed(); + } else if ( l.startsWith( FILTER_TAG( "unit_price:", "unit price" ), Qt::CaseInsensitive ) ) { + mUnitPrice = ( l.right( l.length()-11 ) ).trimmed(); + } else if ( l.startsWith( FILTER_TAG( "name:", "The name of the filter" ), Qt::CaseInsensitive ) ) { + mName = ( l.right( l.length()-5 ) ).trimmed(); + } else if ( l.startsWith( FILTER_TAG( "description:", "The filter description" ), Qt::CaseInsensitive ) ) { + mDescription = ( l.right( l.length()-12 ) ).trimmed(); + } else if ( l.startsWith( FILTER_TAG("encoding:", "The encoding of the source file" ), Qt::CaseInsensitive ) ) { + mEncoding = ( l.right( l.length()-9 ) ).trimmed(); + } else if ( l.startsWith( FILTER_TAG( "separator:", "The separator used in the source file" ), Qt::CaseInsensitive ) ) { + // qDebug () << "Separator found: " << l.right( l.length()-10 ); + mSeparator = ( l.right( l.length()-10 ) ).trimmed(); + } else if ( l.startsWith( FILTER_TAG( "tags:", "Comma separated list of tags for one item" ), Qt::CaseInsensitive ) ) { + mTags = ( l.right( l.length()-5 ) ).trimmed(); + } else { + // qDebug () << "WRN: Unknown filter tag found: " << l; + if ( mError.isEmpty() ) mError = i18n( "Unknown tags: " ); + mError.append( l ); + ret = false; + } } - } - if ( mSeparator.isEmpty() ) { - mSeparator = QString::fromLatin1( ";" ); - } + if ( mSeparator.isEmpty() ) { + mSeparator = QString::fromLatin1( ";" ); + } - return ret; + return ret; } void DocPositionImportFilter::debugDefinition() { - // qDebug () << "Amount: " << mAmount; - // qDebug () << "Unit: " << mUnit; - // qDebug () << "UnitPrice: " << mUnitPrice; - // qDebug () << "Text: " << mText; - // qDebug () << "Separator: <" << mSeparator << ">"; + // qDebug () << "Amount: " << mAmount; + // qDebug () << "Unit: " << mUnit; + // qDebug () << "UnitPrice: " << mUnitPrice; + // qDebug () << "Text: " << mText; + // qDebug () << "Separator: <" << mSeparator << ">"; } DocPositionList DocPositionImportFilter::import( const QUrl &inFile ) { - DocPositionList list; - bool copied = false; + DocPositionList list; + bool copied = false; - if( !inFile.isLocalFile() ) return list; + if( !inFile.isLocalFile() ) return list; - QString file( inFile.toLocalFile() ); + QString file( inFile.toLocalFile() ); - // in case we have to recode, the source file needs to be copied. - bool ok = true; - if ( !mEncoding.isEmpty() ) { - file += ".tmp"; - copied = true; - // qDebug () << "Encoding file to " << file; + // in case we have to recode, the source file needs to be copied. + bool ok = true; + if ( !mEncoding.isEmpty() ) { + file += ".tmp"; + copied = true; + // qDebug () << "Encoding file to " << file; - ok = recode( inFile.toLocalFile(), file ); - if ( !ok ) { - // qDebug () << "Recoding failed!"; - mError = i18n( "Could not recode input file!" ); + ok = recode( inFile.toLocalFile(), file ); + if ( !ok ) { + // qDebug () << "Recoding failed!"; + mError = i18n( "Could not recode input file!" ); + } } - } - - QFile f( file ); - if ( ! f.exists() ) { - // qDebug () << "File " << file << " could not be found!"; - mError = i18n( "Unable to open temp file " ) + file; - ok = false; - } + QFile f( file ); - if ( ok ) { - if ( !f.open( QIODevice::ReadOnly ) ) { - mError = i18n( "Could not open the import source file!" ); - ok = false; + if ( ! f.exists() ) { + // qDebug () << "File " << file << " could not be found!"; + mError = i18n( "Unable to open temp file " ) + file; + ok = false; } - } - if ( ok ) { - QTextStream t( &f ); - while ( !t.atEnd() ) { - cnt++; - QString l = t.readLine().trimmed(); - // qDebug () << "Importing line " << l; - if ( !( l.isEmpty() || l.startsWith( "#" ) ) ) { - bool ok; - DocPosition dp = importDocPosition( l, ok ); - if ( ok ) - list.append( new DocPosition( dp ) ); - } + if ( ok ) { + if ( !f.open( QIODevice::ReadOnly ) ) { + mError = i18n( "Could not open the import source file!" ); + ok = false; + } } - f.close(); - } - if ( copied ) { - QFile::remove( file ); - } - return list; + if ( ok ) { + QTextStream t( &f ); + + while ( !t.atEnd() ) { + QString l = t.readLine().trimmed(); + // qDebug () << "Importing line " << l; + if ( !( l.isEmpty() || l.startsWith( "#" ) ) ) { + bool ok; + DocPosition dp = importDocPosition( l, ok ); + if ( ok ) + list.append( new DocPosition( dp ) ); + } + } + f.close(); + } + if ( copied ) { + QFile::remove( file ); + } + return list; } // creates a DocPosition from one line of the imported file DocPosition DocPositionImportFilter::importDocPosition( const QString& l, bool& ok ) { - QStringList parts = l.split( mSeparator, Qt::KeepEmptyParts ); - // qDebug () << "Importing raw line " << l; - - QString h; - ok = true; - - DocPosition pos; - - // the text (mandatory) - QString t = replaceCOL( parts, mText ); - - pos.setText( t ); - QString unit = replaceCOL( parts, mUnit ); - - int unitId = UnitManager::self()->getUnitIDSingular( unit ); - if ( unitId > -1 ) { - pos.setUnit( UnitManager::self()->getUnit( unitId ) ); - } else { - pos.setUnit(Einheit( unit )); - } - - // Amount. - h = replaceCOL( parts, mAmount ); - bool convOk = true; - double a = h.toDouble( &convOk ); - if ( convOk ) { - pos.setAmount( a ); - } else { - // qDebug () << "WRN: Unable to convert amount to double: " << h; - if ( mStrict ) ok = false; - } - - // Unit Price - h = replaceCOL( parts, mUnitPrice ); - a = h.toDouble( &convOk ); - if ( convOk ) { - pos.setUnitPrice( Geld( a ) ); - } else { - // qDebug () << "WRN: Unable to convert unit price to double: " << h; - if ( mStrict ) ok = false; - } - - if ( !mTags.isEmpty() ) { - QStringList tags = mTags.split(QRegularExpression( "\\s*,\\s*" )); - - for (const QString& t : tags) { - pos.addTag(t); - } - } - - return pos; + QStringList parts = l.split( mSeparator, Qt::KeepEmptyParts ); + // qDebug () << "Importing raw line " << l; + + QString h; + ok = true; + + DocPosition pos; + + // the text (mandatory) + QString t = replaceCOL( parts, mText ); + + pos.setText( t ); + QString unit = replaceCOL( parts, mUnit ); + + int unitId = UnitManager::self()->getUnitIDSingular( unit ); + if ( unitId > -1 ) { + pos.setUnit( UnitManager::self()->getUnit( unitId ) ); + } else { + pos.setUnit(Einheit( unit )); + } + + // Amount. + h = replaceCOL( parts, mAmount ); + bool convOk = true; + double a = h.toDouble( &convOk ); + if ( convOk ) { + pos.setAmount( a ); + } else { + // qDebug () << "WRN: Unable to convert amount to double: " << h; + if ( mStrict ) ok = false; + } + + // Unit Price + h = replaceCOL( parts, mUnitPrice ); + a = h.toDouble( &convOk ); + if ( convOk ) { + pos.setUnitPrice( Geld( a ) ); + } else { + // qDebug () << "WRN: Unable to convert unit price to double: " << h; + if ( mStrict ) ok = false; + } + + if ( !mTags.isEmpty() ) { + QStringList tags = mTags.split(QRegularExpression( "\\s*,\\s*" )); + + for (const QString& t : tags) { + pos.addTag(t); + } + } + + return pos; } QString DocPositionImportFilter::replaceCOL( const QStringList& cols, const QString& in ) { - QString re( in ); - for ( int i = 0; i < cols.size(); i++ ) { - QString replacer = QString( "COL(%1)" ).arg( i+1 ); - QString col = cols[i].trimmed(); - - re.replace( replacer, col, Qt::CaseInsensitive ); - } - // qDebug() << "replaced line: " << re; - return re; + QString re( in ); + for ( int i = 0; i < cols.size(); i++ ) { + QString replacer = QString( "COL(%1)" ).arg( i+1 ); + QString col = cols[i].trimmed(); + + re.replace( replacer, col, Qt::CaseInsensitive ); + } + // qDebug() << "replaced line: " << re; + return re; } diff --git a/src/kataloglistview.cpp b/src/kataloglistview.cpp index 10bb1f91..8b7c6d67 100644 --- a/src/kataloglistview.cpp +++ b/src/kataloglistview.cpp @@ -21,15 +21,11 @@ #include -#include "kraftglobals.h" #include "katalog.h" #include "katalogman.h" #include "kataloglistview.h" #include "defaultprovider.h" #include "materialcalcpart.h" -#include "stockmaterial.h" -#include "templkatalog.h" -#include "timecalcpart.h" #include "dbids.h" #include "catalogchapter.h" #include "addeditchapterdialog.h" @@ -136,8 +132,8 @@ void KatalogListView::setupChapters() QList strayCats; - foreach( CatalogChapter chapter, chapters ) { - QTreeWidgetItem *item = tryAddingCatalogChapter( chapter ); + for( const CatalogChapter& chapter: chapters ) { + QTreeWidgetItem *item = tryAddingCatalogChapter(chapter); if( ! item ) { strayCats.append( chapter ); } else { @@ -150,7 +146,7 @@ void KatalogListView::setupChapters() QList newStrayCats; oldStrayCatCount = strayCats.count(); // loop as long as the overall number of straycats goes down in every round - foreach( CatalogChapter chapter, strayCats ) { + for( const CatalogChapter& chapter: strayCats ) { QTreeWidgetItem *katItem = tryAddingCatalogChapter( chapter ); if( katItem ) { // qDebug () << "Successfully added catalog chapter from strayCats"; @@ -217,7 +213,7 @@ CatalogTemplateList KatalogListView::selectedTemplates() if( ! mCheckboxes || templates.isEmpty() ) { QList items = selectedItems(); - foreach( QTreeWidgetItem* item, items ) { + for( QTreeWidgetItem* item: items ) { if( isChapter(item) && !isRoot(item) ) { // for chapters, the children are lined up. int kidCnt = item->childCount(); @@ -417,7 +413,7 @@ void KatalogListView::dropEvent( QDropEvent *event ) QModelIndex dropParentIndex; int col = -1; int row = -1; - QModelIndex dropIndx = indexAt( event->pos() ); + QModelIndex dropIndx = indexAt( event->position().toPoint()); QTreeWidgetItem *droppedOnItem = itemFromIndex( dropIndx ); if( ! droppedOnItem ) { event->ignore(); diff --git a/src/kraftdb.cpp b/src/kraftdb.cpp index 6d1775d2..94cadbb0 100644 --- a/src/kraftdb.cpp +++ b/src/kraftdb.cpp @@ -210,7 +210,9 @@ int KraftDB::checkConnect( const QString& host, const QString& dbName, } int re = 0; - m_db.setConnectOptions("MYSQL_OPT_RECONNECT=1"); + if (!isSqlite()) { + m_db.setConnectOptions("MYSQL_OPT_RECONNECT=1"); + } m_db.open(); if ( m_db.isOpenError() ) { qDebug () << "ERR opening the db: " << m_db.lastError().text() << @@ -331,14 +333,13 @@ SqlCommandList KraftDB::parseCommandFile( const QString& file ) qDebug () << "FATAL: Could not open " << sqlFile; } else { QTextStream ts( &f ); - ts.setCodec("UTF-8"); QString allSql = ts.readAll(); //Not sure of this one! QStringList sqlList = allSql.split(";"); - QRegExp reg( "\\s*(#|--)\\s*message:? ?(.*)\\s*\\n" ); - QRegExp failreg( "\\s*(#|--)\\s*mayfail\\s*\\n" ); - reg.setMinimal( true ); + QRegularExpression reg( "\\s*(#|--)\\s*message:? ?(.*)\\s*\\n" ); + QRegularExpression failreg( "\\s*(#|--)\\s*mayfail\\s*\\n" ); + // reg.setMinimal( true ); FIXME Qt6 port QListIterator it(sqlList); @@ -346,19 +347,19 @@ SqlCommandList KraftDB::parseCommandFile( const QString& file ) QString msg, command; QString sqlFragment = it.next().trimmed(); - - int pos = reg.indexIn( sqlFragment.toLower(), 0 ); + QRegularExpressionMatch match; + int pos = sqlFragment.toLower().indexOf(reg, 0, &match); if ( pos > -1 ) { - msg = reg.cap( 2 ); + msg = match.captured(2); // qDebug() << "SQL-Commands-Parser: Msg: >" << msg << "<"; } - bool mayfail = false; - pos = failreg.indexIn( sqlFragment.toLower(), 0 ); + bool mayfail{false}; + pos = sqlFragment.toLower().indexOf(failreg, 0, &match); if( pos > -1 ) { mayfail = true; } - bool clean = false; + bool clean{false}; while( ! clean ) { if( sqlFragment.startsWith("#") || sqlFragment.startsWith("--") ) { // remove the comment line. @@ -424,7 +425,6 @@ QList KraftDB::parseMetaFile( int currentVersion ) qWarning() << "FATAL: Could not open " << xmlFile; } else { QTextStream ts( &f ); - ts.setCodec("UTF-8"); parser.parse( &f ); } } else { @@ -463,7 +463,7 @@ int KraftDB::processSqlCommands( const SqlCommandList& commands ) } } - foreach( SqlCommand cmd, commands ) { + for( SqlCommand cmd: commands ) { if( !cmd.message().isEmpty() ) { Q_EMIT statusMessage( cmd.message() ); } diff --git a/src/kraftdoc.cpp b/src/kraftdoc.cpp index 069ba274..0f24712f 100644 --- a/src/kraftdoc.cpp +++ b/src/kraftdoc.cpp @@ -739,16 +739,16 @@ void KraftDoc::slotNewIdent(const QString& ident) } } -#if 0 - // vat tags pos = 0; - while ((pos = rxVat.indexIn(myStr, pos)) != -1) { - const QString lookupTag = rxVat.cap(1); + while ((pos = myStr.indexOf(rxVat, pos, &match))> -1) { + const QString lookupTag = match.captured(1); if (vatSums.contains(lookupTag)) { - myStr.replace(pos, rxVat.matchedLength(), vatSums[lookupTag].toLocaleString()); + myStr.replace(pos, match.captured().length(), vatSums[lookupTag].toLocaleString()); } + } + // generate a list of all tags in any position for (DocPositionBase *pb : dposList) { DocPosition *p = static_cast(pb); @@ -765,41 +765,40 @@ void KraftDoc::slotNewIdent(const QString& ident) } pos = 0; - while ((pos = rxAmount.indexIn(myStr, pos)) != -1) { - const QString lookupTag = rxAmount.cap(1); + while ((pos = myStr.indexOf(rxAmount, pos, &match))> -1) { + const QString lookupTag = match.captured(1); int amount{0}; if (seenTags.contains(lookupTag)) { amount = seenTags[lookupTag]; } - myStr.replace(pos, rxAmount.matchedLength(), QString::number(amount)); + myStr.replace(pos, match.captured().length(), QString::number(amount)); } pos = 0; - while ((pos = rxAddDate.indexIn(myStr, pos)) != -1) { - const QString addDaysStr = rxAddDate.cap(1); + while ((pos = myStr.indexOf(rxAddDate, pos, &match))> -1) { + const QString addDaysStr = match.captured(1); qint64 addDays = addDaysStr.toInt(); QDate newDate = date.addDays(addDays); const QString newDateStr = Format::toDateString(newDate, dateFormat.isEmpty() ? KraftSettings::self()->dateFormat() : dateFormat); - myStr.replace(pos, rxAddDate.matchedLength(), newDateStr); + myStr.replace(pos, match.captured().length(), newDateStr); } // IF_ANY_HAS_TAG(tag) ..... END_HAS_TAG // check the IF_HAS_TAG(tag) ... END_HAS_TAG macro pos = 0; - while ((pos = rxIf.indexIn(myStr, pos)) != -1) { - const QString lookupTag = rxIf.cap(1); + while ((pos = myStr.indexOf(rxIf, pos, &match))> -1) { + const QString lookupTag = match.captured(1); int endpos = myStr.lastIndexOf(rxEndif); if (endpos == -1) endpos = myStr.length(); if (seenTags.contains(lookupTag)) { myStr.remove(endpos, 12 /* length of END_HAS_TAG */); - myStr.remove(pos, rxIf.matchedLength()); + myStr.remove(pos, match.captured().length()); } else { // the tag was not seen, so this needs to be deleted. int len = endpos-pos+12; myStr.remove(pos, len); } } -#endif return myStr; } diff --git a/src/kraftview.cpp b/src/kraftview.cpp index ea3d7e59..af23ff24 100644 --- a/src/kraftview.cpp +++ b/src/kraftview.cpp @@ -746,7 +746,7 @@ void KraftView::slotMovePositionUp( int pos ) return; } - mPositionWidgetList.swap( pos, pos-1 ); + mPositionWidgetList.swapItemsAt( pos, pos-1 ); w1 = mPositionWidgetList.at( pos-1 ); w2 = mPositionWidgetList.at( pos ); // Porting ATTENTION: check assignment of w1, w1 @@ -783,7 +783,7 @@ void KraftView::slotMovePositionDown( int pos ) return; } - mPositionWidgetList.swap( pos, pos+1); + mPositionWidgetList.swapItemsAt( pos, pos+1); w1 = mPositionWidgetList.at( pos+1 ); w2 = mPositionWidgetList.at( pos ); // Porting ATTENTION: check assignment of w1, w1 diff --git a/src/myidentity.cpp b/src/myidentity.cpp index 66bf06a5..cd97525e 100644 --- a/src/myidentity.cpp +++ b/src/myidentity.cpp @@ -56,15 +56,11 @@ KContacts::Addressee MyIdentity::UIToAddressee(Ui::manualOwnIdentity ui) resUrl.setUrl(QUrl(ui.leWebsite->text())); add.setUrl(resUrl); -#if KContacts_VERSION >= QT_VERSION_CHECK(5, 88, 0) KContacts::Email email; email.setEmail(ui.leEmail->text()); email.setPreferred(true); email.setType(KContacts::Email::TypeFlag::Work); add.addEmail(email); -#else - add.insertEmail(ui.leEmail->text(), true /* prefered */ ); -#endif return add; } diff --git a/src/pdfconverter.cpp b/src/pdfconverter.cpp index 9a0be318..5c063f1f 100644 --- a/src/pdfconverter.cpp +++ b/src/pdfconverter.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include #include diff --git a/src/positionviewwidget.cpp b/src/positionviewwidget.cpp index 870bb79b..099fcf54 100644 --- a/src/positionviewwidget.cpp +++ b/src/positionviewwidget.cpp @@ -162,7 +162,7 @@ PositionViewWidget::PositionViewWidget() this->setAutoFillBackground(true); this->setBaseSize(this->width(), 100); - this->layout()->setMargin( 6 ); + this->layout()->setContentsMargins(6, 6, 6, 6); } void PositionViewWidget::setDocPosition( DocPositionBase *dp) diff --git a/src/reportitem.cpp b/src/reportitem.cpp index 4d9c05ea..8742c4d9 100644 --- a/src/reportitem.cpp +++ b/src/reportitem.cpp @@ -49,14 +49,14 @@ ReportItem::ReportItem(DocPositionBase *dpb) re = QStringLiteral("2"); } - _unit = dp->unit().einheit(_amount > 1 ? 2 : 1); + _unit = dp->unit().einheit(dp->amount() > 1 ? 2 : 1); _taxMarker = re; _uuid = dp->uuid(); } QString ReportItem::htmlText() { - const QStringList li = _text.toHtmlEscaped().split( "\n", QString::KeepEmptyParts ); + const QStringList li = _text.toHtmlEscaped().split( "\n", Qt::KeepEmptyParts ); QString re = li.join("
"); return re; diff --git a/src/setupassistant.cpp b/src/setupassistant.cpp index 3cd9c7e6..fcb2d1f6 100644 --- a/src/setupassistant.cpp +++ b/src/setupassistant.cpp @@ -617,7 +617,7 @@ void SetupAssistant::startDatabaseUpdate() mUpgradeDbPage, SLOT( slotCountFillProgress( bool ) ) ); bool errors = false; - + int doneOverallCmds{0}; currentVer = KraftDB::self()->currentSchemaVersion(); for( SqlCommandList cmdList : commandLists ) { currentVer++; diff --git a/src/textselection.cpp b/src/textselection.cpp index a6745d02..bdb4e310 100644 --- a/src/textselection.cpp +++ b/src/textselection.cpp @@ -47,7 +47,7 @@ TextSelection::TextSelection( QWidget *parent, KraftDoc::Part part ) /* a view for the entry text repository */ QVBoxLayout *vbox = new QVBoxLayout; - vbox->setMargin(0); + vbox->setContentsMargins(0, 0, 0, 0); mTextNameView = new QListView; vbox->addWidget(mTextNameView); diff --git a/src/xmldocindex.cpp b/src/xmldocindex.cpp index 71d1f963..25449042 100644 --- a/src/xmldocindex.cpp +++ b/src/xmldocindex.cpp @@ -27,7 +27,7 @@ QMap XmlDocIndex::_identMap = QMap(); QMap XmlDocIndex::_uuidMap = QMap(); -QMultiMap XmlDocIndex::_dateMap = QMap(); +QMultiMap XmlDocIndex::_dateMap = QMultiMap(); QFuture XmlDocIndex::_future; XmlDocIndex::XmlDocIndex() diff --git a/tests/t_attributes.cpp b/tests/t_attributes.cpp index ae6a773d..abc70ec7 100644 --- a/tests/t_attributes.cpp +++ b/tests/t_attributes.cpp @@ -35,7 +35,7 @@ void init_test_db() class T_Attributes : public QObject { Q_OBJECT -private slots: +private Q_SLOTS: void initTestCase() { init_test_db(); diff --git a/tests/t_defaultprovider.cpp b/tests/t_defaultprovider.cpp index ba347ede..7d8f7f30 100644 --- a/tests/t_defaultprovider.cpp +++ b/tests/t_defaultprovider.cpp @@ -20,7 +20,7 @@ void createTestFile( const QString& testFile, const QString& content = QString() QVERIFY (file.open(QIODevice::WriteOnly)); { QTextStream stream(&file); - stream << c << endl; + stream << c << Qt::endl; } } @@ -32,7 +32,7 @@ class T_Defaultprovider: public QObject { private: QString _systemDir; -private slots: +private Q_SLOTS: void initTestCase() { const QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); diff --git a/tests/t_doctype.cpp b/tests/t_doctype.cpp index 4c993177..22314734 100644 --- a/tests/t_doctype.cpp +++ b/tests/t_doctype.cpp @@ -36,7 +36,7 @@ void init_test_db() class T_DocType : public QObject { Q_OBJECT -private slots: +private Q_SLOTS: void initTestCase() { init_test_db(); diff --git a/tests/t_format.cpp b/tests/t_format.cpp index 0894ed9c..e275e20d 100644 --- a/tests/t_format.cpp +++ b/tests/t_format.cpp @@ -5,7 +5,7 @@ class T_Format : public QObject { Q_OBJECT -private slots: +private Q_SLOTS: void initTestCase() { diff --git a/tests/t_jsonindexfile.cpp b/tests/t_jsonindexfile.cpp index c994ac55..d5f1f785 100644 --- a/tests/t_jsonindexfile.cpp +++ b/tests/t_jsonindexfile.cpp @@ -44,7 +44,7 @@ namespace { class T_JsonIndexFile: public QObject { Q_OBJECT -private slots: +private Q_SLOTS: void initTestCase() { QVERIFY(_dir.isValid()); diff --git a/tests/t_kraftattrib.cpp b/tests/t_kraftattrib.cpp index a128cd3e..12d88b08 100644 --- a/tests/t_kraftattrib.cpp +++ b/tests/t_kraftattrib.cpp @@ -9,7 +9,7 @@ class T_KraftAttrib: public QObject { Q_OBJECT -private slots: +private Q_SLOTS: // copies the example xml document to a temporary path that simulates the // storage tree of kraft. diff --git a/tests/t_kraftdoc.cpp b/tests/t_kraftdoc.cpp index ce6e0aa3..7c6dc2df 100644 --- a/tests/t_kraftdoc.cpp +++ b/tests/t_kraftdoc.cpp @@ -77,7 +77,7 @@ DocPositionList buildPosList() { class T_KraftDoc: public QObject { Q_OBJECT -private slots: +private Q_SLOTS: void initTestCase() { QLocale::setDefault(QLocale::German); diff --git a/tests/t_metaparser.cpp b/tests/t_metaparser.cpp index d4b4f410..b85f61fb 100644 --- a/tests/t_metaparser.cpp +++ b/tests/t_metaparser.cpp @@ -5,7 +5,7 @@ class T_MetaParser : public QObject { Q_OBJECT -private slots: +private Q_SLOTS: void initTestCase() { diff --git a/tests/t_numbercycle.cpp b/tests/t_numbercycle.cpp index 235b78e8..6f9a0368 100644 --- a/tests/t_numbercycle.cpp +++ b/tests/t_numbercycle.cpp @@ -46,7 +46,7 @@ bool directFileChange(const QString& thefile, int from, int to) { class T_NumberCycle: public QObject { Q_OBJECT -private slots: +private Q_SLOTS: void initTestCase() { _baseDir = DefaultProvider::self()->createV2BaseDir(_dir.path()); diff --git a/tests/t_stringutil.cpp b/tests/t_stringutil.cpp index 5ca047e5..590daa9f 100644 --- a/tests/t_stringutil.cpp +++ b/tests/t_stringutil.cpp @@ -5,7 +5,7 @@ class T_KraftString : public QObject { Q_OBJECT -private slots: +private Q_SLOTS: void simple1() { QString tmpl{"Foo %nn baz"}; QMap rep; diff --git a/tests/t_unitman.cpp b/tests/t_unitman.cpp index 4c505709..0039d636 100644 --- a/tests/t_unitman.cpp +++ b/tests/t_unitman.cpp @@ -41,7 +41,7 @@ void init_test_db() class T_UnitMan : public QObject { Q_OBJECT -private slots: +private Q_SLOTS: void initTestCase() { init_test_db(); diff --git a/tests/t_xmlsaver.cpp b/tests/t_xmlsaver.cpp index 8044eadd..74602502 100644 --- a/tests/t_xmlsaver.cpp +++ b/tests/t_xmlsaver.cpp @@ -39,7 +39,7 @@ void init_test_db() class T_XmlSaver: public QObject { Q_OBJECT -private slots: +private Q_SLOTS: // copies the example xml document to a temporary path that simulates the // storage tree of kraft.