Skip to content

Commit

Permalink
Added a text wrapper for long origins of nomenclature names
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-w committed Oct 17, 2023
1 parent ef795f4 commit ec9e41d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/core/StelUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,33 @@ QString hoursToHmsStr(const float hours, const bool lowprecision)
return hoursToHmsStr(static_cast<double>(hours), lowprecision);
}

//! The method to splitting the text by substrings by some limit of string length
QString wrapText(const QString& s, const int limit)
{
QString result = "";
if (s.length()<=limit)
result = s;
else
{
QString prepare = "";
QStringList data = s.split(" ");
for (int i = 0; i<data.size(); i++)
{
prepare.append(QString(" %1").arg(data.at(i)));
if (prepare.length() >= limit)
{
result.append(QString("<br />%1").arg(data.at(i)));
prepare = "";
}
else
result.append(QString(" %1").arg(data.at(i)));
}
}

return result;
}


/* /////////////////// DELTA T VARIANTS
// For the standard epochs for many formulae, we use
// J2000.0=2000-jan-1.5=2451545.0,
Expand Down
3 changes: 3 additions & 0 deletions src/core/StelUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,9 @@ namespace StelUtils
//! Convert days (float) to a time string
QString daysFloatToDHMS(float days);

//! The method to splitting the text by substrings by some limit of string length
QString wrapText(const QString& s, const int limit = 52);

//! Get Delta-T estimation for a given date.
//! This is just an "empty" correction function, returning 0.
double getDeltaTwithoutCorrection(const double jDay);
Expand Down
2 changes: 1 addition & 1 deletion src/core/modules/NomenclatureItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ QString NomenclatureItem::getInfoString(const StelCore* core, const InfoStringGr
oss << QString("%1: %2°<br/>").arg(q_("Solar altitude"), QString::number(getSolarAltitude(core), 'f', 1));

if (!origin.isEmpty())
oss << QString("%1: %2<br/>").arg(q_("Origin of name"), qc_(origin, "origin"));
oss << StelUtils::wrapText(QString("%1: %2<br/>").arg(q_("Origin of name"), qc_(origin, "origin")));

// DEBUG output. This should help defining valid criteria for selection priority.
// oss << QString("Planet angular size (semidiameter!): %1''<br/>").arg(QString::number(planet->getAngularSize(core)*3600.));
Expand Down

0 comments on commit ec9e41d

Please sign in to comment.