QXRD  0.11.16
qxrdcalibrantdspacings.cpp
Go to the documentation of this file.
2 
3 void QxrdCalibrantDSpacings::setSettingsValue(QSettings *settings, QString name)
4 {
5  settings->beginWriteArray(name, count());
6 
7  for (int i=0; i<count(); i++) {
8  settings->setArrayIndex(i);
9  const QxrdCalibrantDSpacing &pt = at(i);
10  settings->setValue("index", pt.index());
11  settings->setValue("h", pt.h());
12  settings->setValue("k", pt.k());
13  settings->setValue("l", pt.l());
14  settings->setValue("d", pt.d());
15  settings->setValue("tth", pt.tth());
16  }
17 
18  settings->endArray();
19 }
20 
21 void QxrdCalibrantDSpacings::customSaver(const QVariant &val, QSettings *settings, QString name)
22 {
24 
25  vec.setSettingsValue(settings, name);
26 }
27 
29 {
30  QString res="[";
31 
32  for (int i=0; i<count(); i++) {
33  if (i != 0) {
34  res += ", \n";
35  }
36 
37  res += at(i).toString();
38  }
39 
40  res += "]";
41 
42  return res;
43 }
44 
46 {
47  qRegisterMetaType< QxrdCalibrantDSpacings >("QxrdCalibrantDSpacingVector");
48 
49  qRegisterMetaTypeStreamOperators< QxrdCalibrantDSpacings >("QxrdCalibrantDSpacingVector");
50 
52 }
53 
54 void QxrdCalibrantDSpacings::insertUnique(int index, int h, int k, int l, double d, double tth)
55 {
56  int n = count();
57 
58  for (int i=0; i<n; i++) {
59  QxrdCalibrantDSpacing s = value(i);
60 
61  if (d == s.d()) {
62  s.n() = s.n()+1;
63 
64  replace(i, s);
65 
66  return;
67  }
68  }
69 
70  append(QxrdCalibrantDSpacing(index,h,k,l,1,d,tth));
71 }
72 
74 {
75  QxrdCalibrantDSpacings a = *this;
76  QxrdCalibrantDSpacings b = vec;
77 
78  clear();
79 
80  while (a.count() > 0 || b.count() > 0) {
81  if (a.count() > 0 && b.count() > 0) {
82  if (a.first().d() > b.first().d()) {
83  append(a.takeFirst());
84  } else {
85  append(b.takeFirst());
86  }
87  } else if (a.count() > 0) {
88  append(a.takeFirst());
89  } else if (b.count() > 0) {
90  append(b.takeFirst());
91  }
92  }
93 }
94 
96 {
97  double res = qQNaN();
98 
99  if (n >= 0 && n < count()) {
100  res = value(n).d();
101  }
102 
103  return res;
104 }
105 
107 {
108  double res = qQNaN();
109 
110  if (n >= 0 && n < count()) {
111  res = value(n).tth();
112  }
113 
114  return res;
115 }
void setSettingsValue(QSettings *settings, QString name)
void insertUnique(int index, int h, int k, int l, double d, double tth)
static void registerCustomSaver(QString typeName, CustomSettingsSaver *saver)
static void customSaver(const QVariant &val, QSettings *settings, QString name)
void merge(const QxrdCalibrantDSpacings &vec)