1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-06 16:05:13 -04:00

Remove use of deprecated QRegExp.

This commit is contained in:
srcejon
2024-06-10 14:01:57 +01:00
parent 4f822b4daf
commit 41716632d4
18 changed files with 256 additions and 210 deletions
+40 -33
View File
@@ -17,7 +17,6 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QRegExp>
#include <QRegularExpression>
#include <QStringList>
#include <QDateTime>
@@ -407,34 +406,37 @@ bool APRSPacket::parseDataExension(QString& info, int& idx)
QString s = info.right(remainingLength);
// Course and speed
QRegExp courseSpeed("^([0-9]{3})\\/([0-9]{3})");
if (courseSpeed.indexIn(s) >= 0)
QRegularExpression courseSpeed("^([0-9]{3})\\/([0-9]{3})");
QRegularExpressionMatch match;
match = courseSpeed.match(s);
if (match.hasMatch())
{
m_course = courseSpeed.capturedTexts()[1].toInt();
m_speed = courseSpeed.capturedTexts()[2].toInt();
m_course = match.capturedTexts()[1].toInt();
m_speed = match.capturedTexts()[2].toInt();
m_hasCourseAndSpeed = true;
idx += 7;
return true;
}
// Station radio details
QRegExp phg("^PHG([0-9])([0-9])([0-9])([0-9])");
if (phg.indexIn(s) >= 0)
QRegularExpression phg("^PHG([0-9])([0-9])([0-9])([0-9])");
match = phg.match(s);
if (match.hasMatch())
{
// Transmitter power
int powerCode = phg.capturedTexts()[1].toInt();
int powerCode = match.capturedTexts()[1].toInt();
int powerMap[] = {0, 1, 4, 9, 16, 25, 36, 49, 64, 81};
m_powerWatts = powerMap[powerCode];
// Antenna height
int heightCode = phg.capturedTexts()[2].toInt();
int heightCode = match.capturedTexts()[2].toInt();
m_antennaHeightFt = heightMap[heightCode];
// Antenna gain
m_antennaGainDB = phg.capturedTexts()[3].toInt();
m_antennaGainDB = match.capturedTexts()[3].toInt();
// Antenna directivity
int directivityCode = phg.capturedTexts()[4].toInt();
int directivityCode = match.capturedTexts()[4].toInt();
m_antennaDirectivity = directivityMap[directivityCode];
m_hasStationDetails = true;
@@ -444,31 +446,33 @@ bool APRSPacket::parseDataExension(QString& info, int& idx)
}
// Radio range
QRegExp rng("^RNG([0-9]{4})");
if (rng.indexIn(s) >= 0)
QRegularExpression rng("^RNG([0-9]{4})");
match = rng.match(s);
if (match.hasMatch())
{
m_radioRangeMiles = rng.capturedTexts()[1].toInt();
m_radioRangeMiles = match.capturedTexts()[1].toInt();
m_hasRadioRange = true;
idx += 7;
return true;
}
// Omni-DF strength
QRegExp dfs("^DFS([0-9])([0-9])([0-9])([0-9])");
if (dfs.indexIn(s) >= 0)
QRegularExpression dfs("^DFS([0-9])([0-9])([0-9])([0-9])");
match = dfs.match(s);
if (match.hasMatch())
{
// Strength S-points
m_dfStrength = dfs.capturedTexts()[1].toInt();
m_dfStrength = match.capturedTexts()[1].toInt();
// Antenna height
int heightCode = dfs.capturedTexts()[2].toInt();
int heightCode = match.capturedTexts()[2].toInt();
m_dfHeightFt = heightMap[heightCode];
// Antenna gain
m_dfGainDB = dfs.capturedTexts()[3].toInt();
m_dfGainDB = match.capturedTexts()[3].toInt();
// Antenna directivity
int directivityCode = dfs.capturedTexts()[4].toInt();
int directivityCode = match.capturedTexts()[4].toInt();
m_dfAntennaDirectivity = directivityMap[directivityCode];
m_hasDf = true;
@@ -487,14 +491,14 @@ bool APRSPacket::parseComment(QString& info, int& idx)
m_comment = info.right(commentLength);
// Comment can contain altitude anywhere in it. Of the form /A=001234 in feet
QRegExp re("\\/A=([0-9]{6})");
int pos = re.indexIn(m_comment);
if (pos >= 0)
QRegularExpression re("\\/A=([0-9]{6})");
QRegularExpressionMatch match = re.match(m_comment);
if (match.hasMatch())
{
m_altitudeFt = re.capturedTexts()[1].toInt();
m_altitudeFt = match.capturedTexts()[1].toInt();
m_hasAltitude = true;
// Strip it out of comment if at start of string
if (pos == 0)
if (match.capturedStart(0) == 0)
m_comment = m_comment.mid(9);
}
}
@@ -755,18 +759,20 @@ bool APRSPacket::parseStatus(QString& info, int& idx)
{
QString remaining = info.mid(idx);
QRegExp timestampRE("^([0-9]{6})z"); // DHM timestamp
QRegExp maidenheadRE("^([A-Z]{2}[0-9]{2}[A-Z]{0,2})[/\\\\]."); // Maidenhead grid locator and symbol
QRegularExpression timestampRE("^([0-9]{6})z"); // DHM timestamp
QRegularExpression maidenheadRE("^([A-Z]{2}[0-9]{2}[A-Z]{0,2})[/\\\\]."); // Maidenhead grid locator and symbol
QRegularExpressionMatch matchTimestamp = timestampRE.match(remaining);
QRegularExpressionMatch matchMaidenhead = maidenheadRE.match(remaining);
if (timestampRE.indexIn(remaining) >= 0)
if (matchTimestamp.hasMatch())
{
parseTime(info, idx);
m_status = info.mid(idx);
idx += m_status.length();
}
else if (maidenheadRE.indexIn(remaining) >= 0)
else if (matchMaidenhead.hasMatch())
{
m_maidenhead = maidenheadRE.capturedTexts()[1];
m_maidenhead = matchMaidenhead.capturedTexts()[1];
idx += m_maidenhead.length();
m_symbolTable = info[idx++].toLatin1();
m_symbolCode = info[idx++].toLatin1();
@@ -959,10 +965,11 @@ bool APRSPacket::parseMessage(QString& info, int& idx)
else
{
// Check for message number
QRegExp noRE("\\{([0-9]{1,5})$");
if (noRE.indexIn(m_message) >= 0)
QRegularExpression noRE("\\{([0-9]{1,5})$");
QRegularExpressionMatch match = noRE.match(m_message);
if (match.hasMatch())
{
m_messageNo = noRE.capturedTexts()[1];
m_messageNo = match.capturedTexts()[1];
m_message = m_message.left(m_message.length() - m_messageNo.length() - 1);
}
}
-35
View File
@@ -20,7 +20,6 @@
#include <cmath>
#include <QRegExp>
#include <QDateTime>
#include <QDebug>
@@ -701,40 +700,6 @@ double Astronomy::refractionPAL(double alt, double pressure, double temperature,
return z-Units::radiansToDegrees(zr);
}
double Astronomy::raToDecimal(const QString& value)
{
QRegExp decimal("^([0-9]+(\\.[0-9]+)?)");
QRegExp hms("^([0-9]+)[ h]([0-9]+)[ m]([0-9]+(\\.[0-9]+)?)s?");
if (decimal.exactMatch(value))
return decimal.capturedTexts()[0].toDouble();
else if (hms.exactMatch(value))
{
return Units::hoursMinutesSecondsToDecimal(
hms.capturedTexts()[1].toDouble(),
hms.capturedTexts()[2].toDouble(),
hms.capturedTexts()[3].toDouble());
}
return 0.0;
}
double Astronomy::decToDecimal(const QString& value)
{
QRegExp decimal("^(-?[0-9]+(\\.[0-9]+)?)");
QRegExp dms(QString("^(-?[0-9]+)[ %1d]([0-9]+)[ 'm]([0-9]+(\\.[0-9]+)?)[\"s]?").arg(QChar(0xb0)));
if (decimal.exactMatch(value))
return decimal.capturedTexts()[0].toDouble();
else if (dms.exactMatch(value))
{
return Units::degreesMinutesSecondsToDecimal(
dms.capturedTexts()[1].toDouble(),
dms.capturedTexts()[2].toDouble(),
dms.capturedTexts()[3].toDouble());
}
return 0.0;
}
double Astronomy::lstAndRAToLongitude(double lst, double raHours)
{
double longitude = lst - (raHours * 15.0); // Convert hours to degrees
-3
View File
@@ -64,9 +64,6 @@ public:
static double refractionSaemundsson(double alt, double pressure, double temperature);
static double refractionPAL(double alt, double pressure, double temperature, double humidity, double frequency, double latitude, double heightAboveSeaLevel, double temperatureLapseRate);
static double raToDecimal(const QString& value);
static double decToDecimal(const QString& value);
static double lstAndRAToLongitude(double lst, double raHours);
static void equatorialToGalactic(double ra, double dec, double& l, double& b);
+44 -28
View File
@@ -20,7 +20,7 @@
#include <cmath>
#include <QtGlobal>
#include <QRegExp>
#include <QRegularExpression>
#include <QDebug>
#include <QResource>
@@ -49,59 +49,73 @@ FITS::FITS(QString resourceName) :
int hLen = std::min((qint64)m_headerSize * 3, m_fileSize); // Could possibly be bigger
QByteArray headerBytes = m_data.left(hLen);
QString header = QString::fromLatin1(headerBytes);
QRegExp widthRE("NAXIS1 *= *([0-9]+)");
QRegExp heightRE("NAXIS2 *= *([0-9]+)");
QRegExp bitsPerPixelRE("BITPIX *= *(-?[0-9]+)");
QRegExp bzeroRE("BZERO *= *([0-9]+)");
QRegExp bscaleRE("BSCALE *= *(-?[0-9]+(.[0-9]+)?)");
QRegExp buintRE("BUNIT *= *\\'([A-Z ]+)\\'");
QRegExp cdelt1RE("CDELT1 *= *(-?[0-9]+(.[0-9]+)?)");
QRegExp cdelt2RE("CDELT2 *= *(-?[0-9]+(.[0-9]+)?)");
QRegExp endRE("END {77}");
QRegularExpression widthRE("NAXIS1 *= *([0-9]+)");
QRegularExpression heightRE("NAXIS2 *= *([0-9]+)");
QRegularExpression bitsPerPixelRE("BITPIX *= *(-?[0-9]+)");
QRegularExpression bzeroRE("BZERO *= *([0-9]+)");
QRegularExpression bscaleRE("BSCALE *= *(-?[0-9]+(.[0-9]+)?)");
QRegularExpression buintRE("BUNIT *= *\\'([A-Z ]+)\\'");
QRegularExpression cdelt1RE("CDELT1 *= *(-?[0-9]+(.[0-9]+)?)");
QRegularExpression cdelt2RE("CDELT2 *= *(-?[0-9]+(.[0-9]+)?)");
QRegularExpression endRE("END {77}");
QRegularExpressionMatch match;
if (widthRE.indexIn(header) != -1)
m_width = widthRE.capturedTexts()[1].toInt();
match = widthRE.match(header);
if (match.hasMatch())
m_width = match.capturedTexts()[1].toInt();
else
{
qWarning() << "FITS: NAXIS1 missing";
return;
}
if (heightRE.indexIn(header) != -1)
m_height = heightRE.capturedTexts()[1].toInt();
match = heightRE.match(header);
if (match.hasMatch())
m_height = match.capturedTexts()[1].toInt();
else
{
qWarning() << "FITS: NAXIS2 missing";
return;
}
if (bitsPerPixelRE.indexIn(header) != -1)
m_bitsPerPixel = bitsPerPixelRE.capturedTexts()[1].toInt();
match = bitsPerPixelRE.match(header);
if (match.hasMatch())
m_bitsPerPixel = match.capturedTexts()[1].toInt();
else
{
qWarning() << "FITS: BITPIX missing";
return;
}
m_bytesPerPixel = abs(m_bitsPerPixel)/8;
if (bzeroRE.indexIn(header) != -1)
m_bzero = bzeroRE.capturedTexts()[1].toInt();
match = bzeroRE.match(header);
if (match.hasMatch())
m_bzero = match.capturedTexts()[1].toInt();
else
m_bzero = 0;
if (bscaleRE.indexIn(header) != -1)
m_bscale = bscaleRE.capturedTexts()[1].toDouble();
match = bscaleRE.match(header);
if (match.hasMatch())
m_bscale = match.capturedTexts()[1].toDouble();
else
m_bscale = 1.0;
if (cdelt1RE.indexIn(header) != -1)
m_cdelta1 = cdelt1RE.capturedTexts()[1].toDouble();
match = cdelt1RE.match(header);
if (match.hasMatch())
m_cdelta1 = match.capturedTexts()[1].toDouble();
else
m_cdelta1 = 0.0;
if (cdelt2RE.indexIn(header) != -1)
m_cdelta2 = cdelt2RE.capturedTexts()[1].toDouble();
match = cdelt2RE.match(header);
if (match.hasMatch())
m_cdelta2 = match.capturedTexts()[1].toDouble();
else
m_cdelta2 = 0.0;
if (buintRE.indexIn(header) != -1)
match = buintRE.match(header);
if (match.hasMatch())
{
m_buint = buintRE.capturedTexts()[1].trimmed();
m_buint = match.capturedTexts()[1].trimmed();
if (m_buint.contains("MILLI"))
m_uintScale = 0.001f;
else
@@ -109,8 +123,10 @@ FITS::FITS(QString resourceName) :
}
else
m_uintScale = 1.0f;
int endIdx = endRE.indexIn(header);
if (endIdx == -1)
match = endRE.match(header);
int endIdx = match.capturedStart(0);
if (!match.hasMatch())
{
qWarning() << "FITS: END missing";
return;
+3 -3
View File
@@ -19,7 +19,7 @@
#include <cmath>
#include <QRegExp>
#include <QRegularExpression>
#include "maidenhead.h"
@@ -83,6 +83,6 @@ bool Maidenhead::isMaidenhead(const QString& maidenhead)
int length = maidenhead.length();
if ((length != 4) && (length != 6) && (length != 8))
return false;
QRegExp re("[A-Ra-r][A-Ra-r][0-9][0-9]([A-Xa-x][A-Xa-x]([0-9][0-9])?)?");
return re.exactMatch(maidenhead);
QRegularExpression re(QRegularExpression::anchoredPattern("[A-Ra-r][A-Ra-r][0-9][0-9]([A-Xa-x][A-Xa-x]([0-9][0-9])?)?"));
return re.match(maidenhead).hasMatch();
}
+111 -60
View File
@@ -24,7 +24,7 @@
#include <cmath>
#include <QString>
#include <QStringList>
#include <QRegExp>
#include <QRegularExpression>
#include <QDebug>
#include "export.h"
@@ -158,35 +158,35 @@ public:
// Also supports decimal degrees
static bool degreeMinuteAndSecondsToDecimalDegrees(const QString& string, float& degrees)
{
QRegExp decimal("(-?[0-9]+(\\.[0-9]+)?)");
if (decimal.exactMatch(string))
QRegularExpression decimal(QRegularExpression::anchoredPattern("(-?[0-9]+(\\.[0-9]+)?)"));
QRegularExpressionMatch match;
match = decimal.match(string);
if (match.hasMatch())
{
degrees = decimal.capturedTexts()[1].toFloat();
degrees = match.capturedTexts()[1].toFloat();
return true;
}
QRegExp dms(QString("(-)?([0-9]+)[%1d](([0-9]+)['m](([0-9]+(\\.[0-9]+)?)[\"s])?)?").arg(QChar(0xb0)));
if (dms.exactMatch(string))
QRegularExpression dms(QRegularExpression::anchoredPattern(QString("(-)?([0-9]+)[%1d](([0-9]+)['m](([0-9]+(\\.[0-9]+)?)[\"s])?)?").arg(QChar(0xb0))));
match = dms.match(string);
if (match.hasMatch())
{
float d = 0.0f;
bool neg = false;
for (int i = 0; i < dms.captureCount(); i++) {
qDebug() << dms.capturedTexts()[i];
}
if (dms.captureCount() >= 1) {
neg = dms.capturedTexts()[1] == "-";
neg = match.capturedTexts()[1] == "-";
}
if (dms.captureCount() >= 3) {
d = dms.capturedTexts()[2].toFloat();
d = match.capturedTexts()[2].toFloat();
}
float m = 0.0f;
if (dms.captureCount() >= 5) {
m = dms.capturedTexts()[4].toFloat();
m = match.capturedTexts()[4].toFloat();
}
float s = 0.0f;
if (dms.captureCount() >= 7) {
s = dms.capturedTexts()[6].toFloat();
s = match.capturedTexts()[6].toFloat();
}
qDebug() << neg << d << m << s;
degrees = d + m/60.0 + s/(60.0*60.0);
if (neg) {
degrees = -degrees;
@@ -271,24 +271,29 @@ public:
// We support both decimal and DMS formats
static bool stringToLatitudeAndLongitude(const QString& string, float& latitude, float& longitude)
{
QRegExp decimal("(-?[0-9]+(\\.[0-9]+)?) *,? *(-?[0-9]+(\\.[0-9]+)?)");
if (decimal.exactMatch(string))
QRegularExpressionMatch match;
QRegularExpression decimal(QRegularExpression::anchoredPattern("(-?[0-9]+(\\.[0-9]+)?) *,? *(-?[0-9]+(\\.[0-9]+)?)"));
match = decimal.match(string);
if (match.hasMatch())
{
latitude = decimal.capturedTexts()[1].toFloat();
longitude = decimal.capturedTexts()[3].toFloat();
latitude = match.capturedTexts()[1].toFloat();
longitude = match.capturedTexts()[3].toFloat();
return true;
}
QRegExp dms(QString("([0-9]+)[%1d]([0-9]+)['m]([0-9]+(\\.[0-9]+)?)[\"s]([NS]) *,? *([0-9]+)[%1d]([0-9]+)['m]([0-9]+(\\.[0-9]+)?)[\"s]([EW])").arg(QChar(0xb0)));
if (dms.exactMatch(string))
QRegularExpression dms(QRegularExpression::anchoredPattern(QString("([0-9]+)[%1d]([0-9]+)['m]([0-9]+(\\.[0-9]+)?)[\"s]([NS]) *,? *([0-9]+)[%1d]([0-9]+)['m]([0-9]+(\\.[0-9]+)?)[\"s]([EW])").arg(QChar(0xb0))));
match = dms.match(string);
if (match.hasMatch())
{
float latD = dms.capturedTexts()[1].toFloat();
float latM = dms.capturedTexts()[2].toFloat();
float latS = dms.capturedTexts()[3].toFloat();
bool north = dms.capturedTexts()[5] == "N";
float lonD = dms.capturedTexts()[6].toFloat();
float lonM = dms.capturedTexts()[7].toFloat();
float lonS = dms.capturedTexts()[8].toFloat();
bool east = dms.capturedTexts()[10] == "E";
float latD = match.capturedTexts()[1].toFloat();
float latM = match.capturedTexts()[2].toFloat();
float latS = match.capturedTexts()[3].toFloat();
bool north = match.capturedTexts()[5] == "N";
float lonD = match.capturedTexts()[6].toFloat();
float lonM = match.capturedTexts()[7].toFloat();
float lonS = match.capturedTexts()[8].toFloat();
bool east = match.capturedTexts()[10] == "E";
latitude = latD + latM/60.0 + latS/(60.0*60.0);
if (!north)
latitude = -latitude;
@@ -297,17 +302,19 @@ public:
longitude = -longitude;
return true;
}
QRegExp dms2(QString("([0-9]+)([NS])([0-9]{2})([0-9]{2}) *,?([0-9]+)([EW])([0-9]{2})([0-9]{2})"));
if (dms2.exactMatch(string))
QRegularExpression dms2(QRegularExpression::anchoredPattern(QString("([0-9]+)([NS])([0-9]{2})([0-9]{2}) *,?([0-9]+)([EW])([0-9]{2})([0-9]{2})")));
match = dms2.match(string);
if (match.hasMatch())
{
float latD = dms2.capturedTexts()[1].toFloat();
bool north = dms2.capturedTexts()[2] == "N";
float latM = dms2.capturedTexts()[3].toFloat();
float latS = dms2.capturedTexts()[4].toFloat();
float lonD = dms2.capturedTexts()[5].toFloat();
bool east = dms2.capturedTexts()[6] == "E";
float lonM = dms2.capturedTexts()[7].toFloat();
float lonS = dms2.capturedTexts()[8].toFloat();
float latD = match.capturedTexts()[1].toFloat();
bool north = match.capturedTexts()[2] == "N";
float latM = match.capturedTexts()[3].toFloat();
float latS = match.capturedTexts()[4].toFloat();
float lonD = match.capturedTexts()[5].toFloat();
bool east = match.capturedTexts()[6] == "E";
float lonM = match.capturedTexts()[7].toFloat();
float lonS = match.capturedTexts()[8].toFloat();
latitude = latD + latM/60.0 + latS/(60.0*60.0);
if (!north)
latitude = -latitude;
@@ -316,18 +323,20 @@ public:
longitude = -longitude;
return true;
}
// 512255.5900N 0024400.6105W as used on aviation charts
QRegExp dms3(QString("(\\d{2})(\\d{2})((\\d{2})(\\.\\d+)?)([NS]) *,?(\\d{3})(\\d{2})((\\d{2})(\\.\\d+)?)([EW])"));
if (dms3.exactMatch(string))
QRegularExpression dms3(QRegularExpression::anchoredPattern(QString("(\\d{2})(\\d{2})((\\d{2})(\\.\\d+)?)([NS]) *,?(\\d{3})(\\d{2})((\\d{2})(\\.\\d+)?)([EW])")));
match = dms3.match(string);
if (match.hasMatch())
{
float latD = dms3.capturedTexts()[1].toFloat();
float latM = dms3.capturedTexts()[2].toFloat();
float latS = dms3.capturedTexts()[3].toFloat();
bool north = dms3.capturedTexts()[6] == "N";
float lonD = dms3.capturedTexts()[7].toFloat();
float lonM = dms3.capturedTexts()[8].toFloat();
float lonS = dms3.capturedTexts()[9].toFloat();
bool east = dms3.capturedTexts()[12] == "E";
float latD = match.capturedTexts()[1].toFloat();
float latM = match.capturedTexts()[2].toFloat();
float latS = match.capturedTexts()[3].toFloat();
bool north = match.capturedTexts()[6] == "N";
float lonD = match.capturedTexts()[7].toFloat();
float lonM = match.capturedTexts()[8].toFloat();
float lonS = match.capturedTexts()[9].toFloat();
bool east = match.capturedTexts()[12] == "E";
latitude = latD + latM/60.0 + latS/(60.0*60.0);
if (!north)
latitude = -latitude;
@@ -348,17 +357,19 @@ public:
// 107.1324 -34.233
static bool stringToRADec(const QString& string, float& ra, float& dec)
{
QRegExp dms("([0-9]+)[ :h]([0-9]+)[ :m]([0-9]+(\\.[0-9]+)?)s? *,? *([+-]?[0-9]+)[ :d]([0-9]+)[ :m]([0-9]+(\\.[0-9]+)?)s?");
if (dms.exactMatch(string))
QRegularExpressionMatch match;
QRegularExpression dms(QRegularExpression::anchoredPattern("([0-9]+)[ :h]([0-9]+)[ :m]([0-9]+(\\.[0-9]+)?)s? *,? *([+-]?[0-9]+)[ :d]([0-9]+)[ :m]([0-9]+(\\.[0-9]+)?)s?"));
match = dms.match(string);
if (match.hasMatch())
{
int raHours = dms.capturedTexts()[1].toInt();
int raMins = dms.capturedTexts()[2].toInt();
float raSecs = dms.capturedTexts()[3].toFloat();
int raHours = match.capturedTexts()[1].toInt();
int raMins = match.capturedTexts()[2].toInt();
float raSecs = match.capturedTexts()[3].toFloat();
ra = raHours + raMins / 60.0f + raSecs / (60.0f * 60.0f);
qDebug() << ra << raHours << raMins << raSecs;
int decDegs = dms.capturedTexts()[5].toInt();
int decMins = dms.capturedTexts()[6].toInt();
float decSecs = dms.capturedTexts()[7].toFloat();
int decDegs = match.capturedTexts()[5].toInt();
int decMins = match.capturedTexts()[6].toInt();
float decSecs = match.capturedTexts()[7].toFloat();
bool neg = decDegs < 0;
dec = abs(decDegs) + decMins / 60.0f + decSecs / (60.0f * 60.0f);
if (neg) {
@@ -366,16 +377,56 @@ public:
}
return true;
}
QRegExp decimal("([0-9]+(\\.[0-9]+)?) *,? *([+-]?[0-9]+(\\.[0-9]+)?)");
if (decimal.exactMatch(string))
QRegularExpression decimal(QRegularExpression::anchoredPattern("([0-9]+(\\.[0-9]+)?) *,? *([+-]?[0-9]+(\\.[0-9]+)?)"));
match = decimal.match(string);
if (match.hasMatch())
{
ra = decimal.capturedTexts()[1].toFloat();
dec = decimal.capturedTexts()[3].toFloat();
ra = match.capturedTexts()[1].toFloat();
dec = match.capturedTexts()[3].toFloat();
return true;
}
return false;
}
static double raToDecimal(const QString& value)
{
QRegularExpression decimal(QRegularExpression::anchoredPattern("^([0-9]+(\\.[0-9]+)?)"));
QRegularExpression hms(QRegularExpression::anchoredPattern("^([0-9]+)[ h]([0-9]+)[ m]([0-9]+(\\.[0-9]+)?)s?"));
QRegularExpressionMatch decimalMatch = decimal.match(value);
QRegularExpressionMatch hmsMatch = hms.match(value);
if (decimalMatch.hasMatch())
return decimalMatch.capturedTexts()[0].toDouble();
else if (hmsMatch.hasMatch())
{
return Units::hoursMinutesSecondsToDecimal(
hmsMatch.capturedTexts()[1].toDouble(),
hmsMatch.capturedTexts()[2].toDouble(),
hmsMatch.capturedTexts()[3].toDouble());
}
return 0.0;
}
static double decToDecimal(const QString& value)
{
QRegularExpression decimal(QRegularExpression::anchoredPattern("^(-?[0-9]+(\\.[0-9]+)?)"));
QRegularExpression dms(QRegularExpression::anchoredPattern(QString("^(-?[0-9]+)[ %1d]([0-9]+)[ 'm]([0-9]+(\\.[0-9]+)?)[\"s]?").arg(QChar(0xb0))));
QRegularExpressionMatch decimalMatch = decimal.match(value);
QRegularExpressionMatch dmsMatch = dms.match(value);
if (decimalMatch.hasMatch())
return decimalMatch.capturedTexts()[0].toDouble();
else if (dmsMatch.hasMatch())
{
return Units::degreesMinutesSecondsToDecimal(
dmsMatch.capturedTexts()[1].toDouble(),
dmsMatch.capturedTexts()[2].toDouble(),
dmsMatch.capturedTexts()[3].toDouble());
}
return 0.0;
}
static float solarFluxUnitsToJansky(float sfu)
{
return sfu * 10000.0f;