NebulaMgr.cpp   NebulaMgr.cpp 
skipping to change at line 653 skipping to change at line 653
{ {
if (QString("C%1").arg(n->C_nb) == objw || QString(" C %1").arg(n->C_nb) == objw) if (QString("C%1").arg(n->C_nb) == objw || QString(" C %1").arg(n->C_nb) == objw)
return qSharedPointerCast<StelObject>(n); return qSharedPointerCast<StelObject>(n);
} }
} }
return NULL; return NULL;
} }
//! Find and return the list of at most maxNbItem objects auto-completing t he passed object I18n name //! Find and return the list of at most maxNbItem objects auto-completing t he passed object I18n name
QStringList NebulaMgr::listMatchingObjectsI18n(const QString& objPrefix, in t maxNbItem) const QStringList NebulaMgr::listMatchingObjectsI18n(const QString& objPrefix, in t maxNbItem, bool useStartOfWords) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) return result; if (maxNbItem==0) return result;
QString dson; QString objw = objPrefix.toUpper();
// Search by Messier objects number (possible formats are "M31" or " M 31") // Search by Messier objects number (possible formats are "M31" or " M 31")
if (objPrefix.size()>=1 && objPrefix[0]=='M') if (objw.size()>=1 && objw[0]=='M')
{ {
foreach (const NebulaP& n, nebArray) foreach (const NebulaP& n, nebArray)
{ {
if (n->M_nb==0) continue; if (n->M_nb==0) continue;
dson = QString("M%1").arg(n->M_nb); QString constw = QString("M%1").arg(n->M_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) QString constws = constw.mid(0, objw.size());
if (constws==objw)
{ {
result << dson; result << constws;
continue; // Prevent adding both forms for name continue; // Prevent adding both forms for name
} }
dson = QString("M %1").arg(n->M_nb); constw = QString("M %1").arg(n->M_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) constws = constw.mid(0, objw.size());
result << dson; if (constws==objw)
result << constw;
} }
} }
// Search by IC objects number (possible formats are "IC466" or "IC 466") // Search by IC objects number (possible formats are "IC466" or "IC 466")
if (objPrefix.size()>=1 && objPrefix[0]=='I') if (objw.size()>=1 && objw[0]=='I')
{ {
foreach (const NebulaP& n, nebArray) foreach (const NebulaP& n, nebArray)
{ {
if (n->IC_nb==0) continue; if (n->IC_nb==0) continue;
dson = QString("IC%1").arg(n->IC_nb); QString constw = QString("IC%1").arg(n->IC_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) QString constws = constw.mid(0, objw.size());
if (constws==objw)
{ {
result << dson; result << constws;
continue; // Prevent adding both forms for name continue; // Prevent adding both forms for name
} }
dson = QString("IC %1").arg(n->IC_nb); constw = QString("IC %1").arg(n->IC_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) constws = constw.mid(0, objw.size());
result << dson; if (constws==objw)
result << constw;
} }
} }
// Search by NGC numbers (possible formats are "NGC31" or "NGC 31") // Search by NGC numbers (possible formats are "NGC31" or "NGC 31")
foreach (const NebulaP& n, nebArray) foreach (const NebulaP& n, nebArray)
{ {
if (n->NGC_nb==0) continue; if (n->NGC_nb==0) continue;
dson = QString("NGC%1").arg(n->NGC_nb); QString constw = QString("NGC%1").arg(n->NGC_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) QString constws = constw.mid(0, objw.size());
if (constws==objw)
{ {
result << dson; result << constws;
continue; continue;
} }
dson = QString("NGC %1").arg(n->NGC_nb); constw = QString("NGC %1").arg(n->NGC_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) constws = constw.mid(0, objw.size());
result << dson; if (constws==objw)
result << constw;
} }
// Search by caldwell objects number (possible formats are "C31" or "C 31") // Search by caldwell objects number (possible formats are "C31" or "C 31")
if (objPrefix.size()>=1 && objPrefix[0]=='C') if (objw.size()>=1 && objw[0]=='C')
{ {
foreach (const NebulaP& n, nebArray) foreach (const NebulaP& n, nebArray)
{ {
if (n->C_nb==0) continue; if (n->C_nb==0) continue;
dson = QString("C%1").arg(n->C_nb); QString constw = QString("C%1").arg(n->C_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) QString constws = constw.mid(0, objw.size());
if (constws==objw)
{ {
result << dson; result << constws;
continue; // Prevent adding both forms for name continue; // Prevent adding both forms for name
} }
dson = QString("C %1").arg(n->C_nb); constw = QString("C %1").arg(n->C_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) constws = constw.mid(0, objw.size());
result << dson; if (constws==objw)
result << constw;
} }
} }
QString dson;
bool find;
// Search by common names // Search by common names
foreach (const NebulaP& n, nebArray) foreach (const NebulaP& n, nebArray)
{ {
dson = n->nameI18; dson = n->nameI18;
if (dson.contains(objPrefix, Qt::CaseInsensitive)) find = false;
if (useStartOfWords)
{
if (dson.mid(0, objw.size()).toUpper()==objw)
find = true;
}
else
{
if (dson.contains(objPrefix, Qt::CaseInsensitive))
find = true;
}
if (find)
result << dson; result << dson;
} }
result.sort(); result.sort();
if (maxNbItem > 0) if (maxNbItem > 0)
{ {
if (result.size()>maxNbItem) result.erase(result.begin()+max NbItem, result.end()); if (result.size()>maxNbItem) result.erase(result.begin()+max NbItem, result.end());
} }
return result; return result;
} }
//! Find and return the list of at most maxNbItem objects auto-completing t he passed object English name //! Find and return the list of at most maxNbItem objects auto-completing t he passed object English name
QStringList NebulaMgr::listMatchingObjects(const QString& objPrefix, int ma xNbItem) const QStringList NebulaMgr::listMatchingObjects(const QString& objPrefix, int ma xNbItem, bool useStartOfWords) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) return result; if (maxNbItem==0) return result;
QString dson; QString objw = objPrefix.toUpper();
// Search by Messier objects number (possible formats are "M31" or " M 31") // Search by Messier objects number (possible formats are "M31" or " M 31")
if (objPrefix.size()>=1 && objPrefix[0]=='M') if (objw.size()>=1 && objw[0]=='M')
{ {
foreach (const NebulaP& n, nebArray) foreach (const NebulaP& n, nebArray)
{ {
if (n->M_nb==0) continue; if (n->M_nb==0) continue;
dson = QString("M%1").arg(n->M_nb); QString constw = QString("M%1").arg(n->M_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) QString constws = constw.mid(0, objw.size());
if (constws==objw)
{ {
result << dson; result << constws;
continue; // Prevent adding both forms for name continue; // Prevent adding both forms for name
} }
dson = QString("M %1").arg(n->M_nb); constw = QString("M %1").arg(n->M_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) constws = constw.mid(0, objw.size());
result << dson; if (constws==objw)
result << constw;
} }
} }
// Search by IC objects number (possible formats are "IC466" or "IC 466") // Search by IC objects number (possible formats are "IC466" or "IC 466")
if (objPrefix.size()>=1 && objPrefix[0]=='I') if (objw.size()>=1 && objw[0]=='I')
{ {
foreach (const NebulaP& n, nebArray) foreach (const NebulaP& n, nebArray)
{ {
if (n->IC_nb==0) continue; if (n->IC_nb==0) continue;
dson = QString("IC%1").arg(n->IC_nb); QString constw = QString("IC%1").arg(n->IC_nb);
if (dson.contains(objPrefix,Qt::CaseInsensitive)) QString constws = constw.mid(0, objw.size());
if (constws==objw)
{ {
result << dson; result << constws;
continue; // Prevent adding both forms for name continue; // Prevent adding both forms for name
} }
dson = QString("IC %1").arg(n->IC_nb); constw = QString("IC %1").arg(n->IC_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) constws = constw.mid(0, objw.size());
result << dson; if (constws==objw)
result << constw;
} }
} }
// Search by NGC numbers (possible formats are "NGC31" or "NGC 31") // Search by NGC numbers (possible formats are "NGC31" or "NGC 31")
foreach (const NebulaP& n, nebArray) foreach (const NebulaP& n, nebArray)
{ {
if (n->NGC_nb==0) continue; if (n->NGC_nb==0) continue;
dson = QString("NGC%1").arg(n->NGC_nb); QString constw = QString("NGC%1").arg(n->NGC_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) QString constws = constw.mid(0, objw.size());
if (constws==objw)
{ {
result << dson; result << constws;
continue; continue;
} }
dson = QString("NGC %1").arg(n->NGC_nb); constw = QString("NGC %1").arg(n->NGC_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) constws = constw.mid(0, objw.size());
result << dson; if (constws==objw)
result << constw;
} }
// Search by caldwell objects number (possible formats are "C31" or "C 31") // Search by caldwell objects number (possible formats are "C31" or "C 31")
if (objPrefix.size()>=1 && objPrefix[0]=='C') if (objw.size()>=1 && objw[0]=='C')
{ {
foreach (const NebulaP& n, nebArray) foreach (const NebulaP& n, nebArray)
{ {
if (n->C_nb==0) continue; if (n->C_nb==0) continue;
dson = QString("C%1").arg(n->C_nb); QString constw = QString("C%1").arg(n->C_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) QString constws = constw.mid(0, objw.size());
if (constws==objw)
{ {
result << dson; result << constws;
continue; // Prevent adding both forms for name continue; // Prevent adding both forms for name
} }
dson = QString("C %1").arg(n->C_nb); constw = QString("C %1").arg(n->C_nb);
if (dson.contains(objPrefix, Qt::CaseInsensitive)) constws = constw.mid(0, objw.size());
result << dson; if (constws==objw)
result << constw;
} }
} }
QString dson;
bool find;
// Search by common names // Search by common names
foreach (const NebulaP& n, nebArray) foreach (const NebulaP& n, nebArray)
{ {
dson = n->englishName; dson = n->englishName;
if (dson.contains(objPrefix, Qt::CaseInsensitive)) find = false;
if (useStartOfWords)
{
if (dson.mid(0, objw.size()).toUpper()==objw)
find = true;
}
else
{
if (dson.contains(objPrefix, Qt::CaseInsensitive))
find = true;
}
if (find)
result << dson; result << dson;
} }
result.sort(); result.sort();
if (maxNbItem > 0) if (maxNbItem > 0)
{ {
if (result.size()>maxNbItem) result.erase(result.begin()+max NbItem, result.end()); if (result.size()>maxNbItem) result.erase(result.begin()+max NbItem, result.end());
} }
return result; return result;
 End of changes. 38 change blocks. 
60 lines changed or deleted 104 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/