BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
GUI::Util::String Namespace Reference

Functions

QStringList fromStdStrings (const std::vector< std::string > &container)
 
QString readTextFile (const QString &fileName)
 
QString suggestName (const QStringList &existingNames, const QString &name)
 Returns a name suggestion based on the given name. More...
 

Function Documentation

◆ fromStdStrings()

QStringList GUI::Util::String::fromStdStrings ( const std::vector< std::string > &  container)

Definition at line 18 of file String.cpp.

19 {
20  QStringList result;
21  for (const std::string& str : container)
22  result.append(QString::fromStdString(str));
23  return result;
24 }

Referenced by MinimizerItemCatalog::algorithmDescriptions(), and MinimizerItemCatalog::algorithmNames().

◆ readTextFile()

QString GUI::Util::String::readTextFile ( const QString &  fileName)

◆ suggestName()

QString GUI::Util::String::suggestName ( const QStringList &  existingNames,
const QString &  name 
)

Returns a name suggestion based on the given name.

Tries to add a reasonable numbering in brackets if necessary (e.g. "GISAS" -> "GISAS (2)")

Definition at line 26 of file String.cpp.

27 {
28  int newNumber = -1;
29  QRegExp regexp(R"(\‍((\d+)\))");
30 
31  QString baseName = name;
32  if (regexp.indexIn(baseName) >= 0) {
33  newNumber = regexp.cap(1).toInt();
34  baseName.replace(regexp.cap(0), "");
35  baseName = baseName.trimmed();
36  }
37 
38  for (const auto& name : existingNames) {
39  if (name == baseName)
40  newNumber = std::max(newNumber, 2);
41  else if (regexp.indexIn(name) >= 0)
42  newNumber = std::max(newNumber, regexp.cap(1).toInt() + 1);
43  }
44 
45  if (newNumber == -1)
46  return baseName;
47 
48  return QString("%1 (%2)").arg(baseName).arg(newNumber);
49 }
QString const & name(EShape k)
Definition: particles.cpp:20
QString baseName(const QString &fileName)
Returns base name of file.
Definition: Path.cpp:133

References GUI::Util::Path::baseName(), and GUI::RealSpace::Particles::name().

Referenced by SampleListModel::createSample(), and InstrumentCollection::suggestInstrumentName().

Here is the call graph for this function: