summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkarsh Simha <akarsh@kde.org>2016-08-30 08:28:02 (GMT)
committerAkarsh Simha <akarsh@kde.org>2016-08-30 08:31:48 (GMT)
commita79f4667b59a25a3f35f2b3da3e210d7de545f47 (patch)
treee6ae2324c3059083cbc690014a724e1fce6b627f
parent042cf321fb0834c9c66ca6fae3dc94212a490260 (diff)
deps-- to Qt 5.1: use a lambda wrapper to replace a Qt5.5 method
QString::indexOf( ... ) calls that were removed seem to require Qt 5.5. In order to encourage functional building of KStars on older Ubuntu versions, we avoid using this call, and instead use a C++ lambda to wrap around. If the call becomes deprecated, we can easily modify the wrapper to use the new syntax. Also: move helper method AddDeepSkyObject::countNonOverlappingMatches into a lambda. CCMAIL: kstars-devel@kde.org
-rw-r--r--kstars/tools/adddeepskyobject.cpp47
-rw-r--r--kstars/tools/adddeepskyobject.h2
2 files changed, 28 insertions, 21 deletions
diff --git a/kstars/tools/adddeepskyobject.cpp b/kstars/tools/adddeepskyobject.cpp
index b81ef31..cedb54c 100644
--- a/kstars/tools/adddeepskyobject.cpp
+++ b/kstars/tools/adddeepskyobject.cpp
@@ -90,22 +90,45 @@ void AddDeepSkyObject::fillFromText( const QString &text ) {
float minorAxis = NaN::f;
float positionAngle = 0;
QString name;
+
+ // Note: The following method is a proxy to support older versions of Qt.
+ // In Qt 5.5 and above, the QString::indexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) method obviates the need for the following.
+ auto indexOf = []( const QString &s, const QRegularExpression &regExp, int from, QRegularExpressionMatch *m ) -> int {
+ *m = regExp.match( s, from );
+ return m->capturedStart( 0 );
+ };
+
+ auto countNonOverlappingMatches = [ indexOf ]( const QString &string, const QRegularExpression &regExp, QStringList *list = 0 ) -> int {
+ int count = 0;
+ int matchIndex = -1;
+ int lastMatchLength = 1;
+ QRegularExpressionMatch rmatch;
+ while ( ( matchIndex = indexOf( string, regExp, matchIndex + lastMatchLength, &rmatch ) ) >= 0 ) {
+ ++count;
+ lastMatchLength = rmatch.captured( 0 ).length();
+ if ( list )
+ list->append( rmatch.captured( 0 ) );
+ }
+ return count;
+ };
+
QRegularExpressionMatch rmatch;
- if ( countNonOverlappingMatches( text, matchCoords ) == 2 ) {
+ int nonOverlappingMatchCount;
+ if ( ( nonOverlappingMatchCount = countNonOverlappingMatches( text, matchCoords ) ) == 2 ) {
coordText = text;
}
- else if ( countNonOverlappingMatches( text, matchCoords ) > 2 ) {
+ else if ( nonOverlappingMatchCount > 2 ) {
qDebug() << "Found more than 2 coordinate matches. Trying to match J2000 line.";
- if ( text.indexOf( matchJ2000Line, 0, &rmatch ) >= 0 ) {
+ if ( indexOf( text, matchJ2000Line, 0, &rmatch ) >= 0 ) {
coordText = rmatch.captured( 1 ) + rmatch.captured( 2 );
qDebug() << "Found a J2000 line match: " << coordText;
}
}
if ( !coordText.isEmpty() ) {
- int coord1 = coordText.indexOf( matchCoords, 0, &rmatch );
+ int coord1 = indexOf( coordText, matchCoords, 0, &rmatch );
Q_ASSERT( coord1 >= 0 );
RA = dms( rmatch.captured( 1 ) + ' ' + rmatch.captured( 2 ) + ' ' + rmatch.captured( 3 ), false );
- int coord2 = coordText.indexOf( matchCoords, coord1 + rmatch.captured( 0 ).length(), &rmatch );
+ int coord2 = indexOf( coordText, matchCoords, coord1 + rmatch.captured( 0 ).length(), &rmatch );
Q_ASSERT( coord2 >= 0 );
Dec = dms( rmatch.captured( 1 ) + ' ' + rmatch.captured( 2 ) + ' ' + rmatch.captured( 3 ), true );
qDebug() << "Extracted coordinates: " << RA.toHMSString() << " " << Dec.toDMSString();
@@ -287,17 +310,3 @@ void AddDeepSkyObject::slotFillFromText() {
if ( ok )
fillFromText( text );
}
-
-int AddDeepSkyObject::countNonOverlappingMatches( const QString &string, const QRegularExpression &regExp, QStringList *list ) {
- int count = 0;
- int matchIndex = -1;
- int lastMatchLength = 1;
- QRegularExpressionMatch rmatch;
- while ( ( matchIndex = string.indexOf( regExp, matchIndex + lastMatchLength, &rmatch ) ) >= 0 ) {
- ++count;
- lastMatchLength = rmatch.captured( 0 ).length();
- if ( list )
- list->append( rmatch.captured( 0 ) );
- }
- return count;
-}
diff --git a/kstars/tools/adddeepskyobject.h b/kstars/tools/adddeepskyobject.h
index fa0ceec..df68c8e 100644
--- a/kstars/tools/adddeepskyobject.h
+++ b/kstars/tools/adddeepskyobject.h
@@ -71,8 +71,6 @@ class AddDeepSkyObject : public QDialog, public Ui::AddDeepSkyObject {
private:
- int countNonOverlappingMatches( const QString &string, const QRegularExpression &regExp, QStringList *list = 0 );
-
SyncedCatalogComponent *m_catalog;
Ui::AddDeepSkyObject *ui;
};