1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
|
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/IO/ImportDialogs.cpp
//! @brief Implements class ImportDialog and its children.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/View/IO/ImportDialogs.h"
#include "Base/Util/Assert.h"
#include <QButtonGroup>
#include <QCheckBox>
#include <QComboBox>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QRadioButton>
#include <QSpinBox>
#include <QVBoxLayout>
#include <QtGui>
ImportSettings1D Import1dDialog::Msettings("q_z (1/nm)", "#", "", 1, 2);
ImportSettings2D Import2dDialog::Msettings("q_y (1/nm)", "q_z (1/nm)");
ImportDialog::ImportDialog(QWidget* parent)
: QDialog(parent)
{
setWindowTitle("Specify input format");
setWindowFlags(Qt::Dialog);
}
Import1dDialog::Import1dDialog(QWidget* parent)
: ImportDialog(parent)
{
auto* vbox = new QVBoxLayout;
setLayout(vbox);
auto* gridLayout = new QGridLayout;
vbox->addLayout(gridLayout);
auto* have_sR = new QCheckBox;
gridLayout->addWidget(have_sR, 2, 0);
have_sR->setCheckState(Msettings.col_sR == 0 ? Qt::Unchecked : Qt::Checked);
// connect statement is below, as it needs access to other widgets
gridLayout->addWidget(new QLabel("Read Q"), 0, 1);
gridLayout->addWidget(new QLabel("Read R"), 1, 1);
gridLayout->addWidget(new QLabel("Read σR"), 2, 1);
gridLayout->addWidget(new QLabel("from column"), 0, 2);
gridLayout->addWidget(new QLabel("from column"), 1, 2);
auto* from_sR = new QLabel("from column"); // this one can be made invisible
gridLayout->addWidget(from_sR, 2, 2);
from_sR->setVisible(Msettings.col_sR != 0);
auto* sb_Q = new QSpinBox;
gridLayout->addWidget(sb_Q, 0, 3);
sb_Q->setMinimum(1);
sb_Q->setValue(Msettings.col_Q);
connect(sb_Q, &QSpinBox::valueChanged, [&p = Msettings](int i) { p.col_Q = i; });
auto* sb_R = new QSpinBox;
gridLayout->addWidget(sb_R, 1, 3);
sb_R->setMinimum(1);
sb_R->setValue(Msettings.col_R);
connect(sb_R, &QSpinBox::valueChanged, [&p = Msettings](int i) { p.col_R = i; });
auto* sb_sR = new QSpinBox;
gridLayout->addWidget(sb_sR, 2, 3);
sb_sR->setVisible(Msettings.col_sR != 0);
sb_sR->setMinimum(1);
sb_sR->setValue(Msettings.col_sR);
connect(sb_sR, &QSpinBox::valueChanged, [&p = Msettings](int i) { p.col_sR = i; });
connect(have_sR, &QCheckBox::stateChanged, [&p = Msettings, from_sR, sb_sR](int i) {
from_sR->setVisible(i != 0);
sb_sR->setVisible(i != 0);
if (i == 0)
Msettings.col_sR = 0;
else
sb_sR->setValue(p.col_R + 1);
});
auto* w21 = new QWidget;
vbox->addWidget(w21);
auto* form211 = new QFormLayout;
w21->setLayout(form211);
auto* linesToSkipEdit = new QLineEdit;
form211->addRow("Ignore line numbers:", linesToSkipEdit);
if (Msettings.linesToSkip.empty())
linesToSkipEdit->setPlaceholderText("Example: 1-5, 12");
else
linesToSkipEdit->setText(QString::fromStdString(Msettings.linesToSkip));
connect(linesToSkipEdit, &QLineEdit::textEdited,
[&p = Msettings](const QString& text) { p.linesToSkip = text.toStdString(); });
auto* headerPrefixEdit = new QLineEdit;
form211->addRow("Ignore lines starting with:", headerPrefixEdit);
if (Msettings.headerPrefix.empty())
headerPrefixEdit->setPlaceholderText("#,//");
else
headerPrefixEdit->setText(QString::fromStdString(Msettings.headerPrefix));
connect(headerPrefixEdit, &QLineEdit::textEdited,
[&p = Msettings](const QString& text) { p.headerPrefix = text.toStdString(); });
const std::vector<std::string> qCoords{"q_z (1/nm)", "q_z (1/angstrom)", "alpha (rad)",
"alpha (deg)", "2alpha (rad)", "2alpha (deg)"};
auto* qUnitCombo = new QComboBox;
form211->addRow("Abscissa given as:", qUnitCombo);
qUnitCombo->addItem("q (1/nm)");
qUnitCombo->addItem("q (1/Å)");
qUnitCombo->addItem("α (rad)");
qUnitCombo->addItem("α (deg)");
qUnitCombo->addItem("2α (rad)");
qUnitCombo->addItem("2α (deg)");
ASSERT(qUnitCombo->count() == (int)qCoords.size());
for (int i = 0; i < qUnitCombo->count(); ++i)
if (Msettings.xCoord == qCoords[i]) {
qUnitCombo->setCurrentIndex(i);
break;
}
connect(qUnitCombo, &QComboBox::currentIndexChanged,
[&p = Msettings, qCoords](int i) { p.xCoord = qCoords[i]; });
auto* sortCheckbox = new QCheckBox;
sortCheckbox->setChecked(Msettings.sort);
form211->addRow("Sort by Q", sortCheckbox);
connect(sortCheckbox, &QCheckBox::toggled,
[&p = Msettings](bool checked) { p.sort = checked; });
auto* negativeCheckbox = new QCheckBox;
negativeCheckbox->setChecked(Msettings.rm_negative);
form211->addRow("Discard negative Q", negativeCheckbox);
connect(negativeCheckbox, &QCheckBox::toggled,
[&p = Msettings](bool checked) { p.rm_negative = checked; });
auto* duplicateCheckbox = new QCheckBox;
duplicateCheckbox->setChecked(Msettings.rm_duplications);
form211->addRow("Discard Q duplications", duplicateCheckbox);
connect(duplicateCheckbox, &QCheckBox::toggled,
[&p = Msettings](bool checked) { p.rm_duplications = checked; });
auto* buttonline = new QHBoxLayout;
vbox->addLayout(buttonline);
auto* okButton = new QPushButton("OK");
buttonline->addWidget(okButton);
okButton->setDefault(true);
connect(okButton, &QPushButton::clicked, this, &Import1dDialog::accept);
}
Import2dDialog::Import2dDialog(QWidget* parent)
: ImportDialog(parent)
{
auto* vbox = new QVBoxLayout;
setLayout(vbox);
auto* gridLayout = new QGridLayout;
vbox->addLayout(gridLayout);
auto* has_axes = new QCheckBox("Table contains axes");
has_axes->setChecked(Msettings.has_axes);
gridLayout->addWidget(has_axes, 0, 0);
// connect statement is below, as it needs access to other widgets
auto* swap_axes = new QCheckBox("Swap axes");
swap_axes->setChecked(Msettings.swap_axes);
gridLayout->addWidget(swap_axes, 1, 0);
// row
auto* row_label = new QLabel("Row:");
gridLayout->addWidget(row_label, 2, 0);
auto* row_first = new QRadioButton("first");
row_first->setChecked(Msettings.first_row);
gridLayout->addWidget(row_first, 2, 1);
connect(row_first, &QRadioButton::toggled, [](bool b) { Msettings.first_row = b; });
auto* row_last = new QRadioButton("last");
row_last->setChecked(!Msettings.first_row);
gridLayout->addWidget(row_last, 2, 2);
connect(row_last, &QRadioButton::toggled, [](bool b) { Msettings.first_row = !b; });
auto* row_group = new QButtonGroup;
row_group->addButton(row_first);
row_group->addButton(row_last);
// column
auto* col_label = new QLabel("Column:");
gridLayout->addWidget(col_label, 3, 0);
auto* col_first = new QRadioButton("first");
col_first->setChecked(Msettings.first_col);
gridLayout->addWidget(col_first, 3, 1);
connect(col_first, &QRadioButton::toggled, [](bool b) { Msettings.first_col = b; });
auto* col_last = new QRadioButton("last");
col_last->setChecked(!Msettings.first_col);
gridLayout->addWidget(col_last, 3, 2);
connect(col_last, &QRadioButton::toggled, [](bool b) { Msettings.first_col = !b; });
auto* col_group = new QButtonGroup;
col_group->addButton(col_first);
col_group->addButton(col_last);
// Q units
auto* form_l = new QFormLayout;
vbox->addLayout(form_l);
auto* unit_label = new QLabel("Axes are given in units of:");
const std::vector<std::string> xCoords{"q_y (1/nm)", "q_y (1/angstrom)", "phi_i (rad)",
"phi_i (deg)"};
const std::vector<std::string> yCoords{"q_z (1/nm)", "q_z (1/angstrom)", "alpha_i (rad)",
"alpha_i (deg)"};
ASSERT(xCoords.size() == yCoords.size());
auto* qUnitCombo = new QComboBox;
form_l->addRow(unit_label, qUnitCombo);
qUnitCombo->addItem("1/nm");
qUnitCombo->addItem("1/Å");
qUnitCombo->addItem("deg");
qUnitCombo->addItem("rad");
ASSERT(qUnitCombo->count() == (int)xCoords.size());
for (int i = 0; i < qUnitCombo->count(); ++i)
if (Msettings.xCoord == xCoords[i]) {
qUnitCombo->setCurrentIndex(i);
break;
}
connect(qUnitCombo, &QComboBox::currentIndexChanged, [=](int i) {
Msettings.xCoord = xCoords[i];
Msettings.yCoord = yCoords[i];
// upd labels via toggling
swap_axes->toggled(Msettings.swap_axes);
});
connect(swap_axes, &QCheckBox::toggled, [=](bool b) {
Msettings.swap_axes = b;
QString xName = QString::fromStdString(Msettings.xCoord.name());
QString yName = QString::fromStdString(Msettings.yCoord.name());
if (b) {
row_label->setText("Row (" + yName + "):");
col_label->setText("Column (" + xName + "):");
} else {
row_label->setText("Row (" + xName + "):");
col_label->setText("Column (" + yName + ")");
}
});
swap_axes->toggled(Msettings.swap_axes);
connect(has_axes, &QCheckBox::toggled, [=](bool b) {
Msettings.has_axes = b;
swap_axes->setEnabled(b);
row_label->setEnabled(b);
row_first->setEnabled(b);
row_last->setEnabled(b);
col_label->setEnabled(b);
col_first->setEnabled(b);
col_last->setEnabled(b);
unit_label->setEnabled(b);
qUnitCombo->setEnabled(b);
});
has_axes->toggled(Msettings.has_axes);
auto* buttonline = new QHBoxLayout;
vbox->addLayout(buttonline);
auto* okButton = new QPushButton("OK");
buttonline->addWidget(okButton);
okButton->setDefault(true);
connect(okButton, &QPushButton::clicked, this, &Import2dDialog::accept);
}
|