BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
gui2::DataLoaderDialog Class Reference

Main dialog for the data loader. More...

Inheritance diagram for gui2::DataLoaderDialog:
[legend]
Collaboration diagram for gui2::DataLoaderDialog:
[legend]

Public Member Functions

 DataLoaderDialog (QWidget *parent=nullptr)
 
 ~DataLoaderDialog ()
 
QStringList fileNames () const
 
std::vector< GraphImportDatagraphImportData () const
 Returns the result of whole parsing. More...
 
void invokeFileSelectorDialog ()
 Invokes file selector dialog. More...
 
void setTargetCanvas (const std::vector< std::string > &canvas_names, int current_index)
 Set list of target canvas to define entr where to import. More...
 
int targetCanvasIndex () const
 Returns index of target canvas for graph import. More...
 

Protected Member Functions

void accept () override
 
void keyPressEvent (QKeyEvent *event) override
 Make dialog intact to enter-key to handle it by LoadSelectorPanel. More...
 

Private Slots

void onLoadFilesRequest ()
 Loads ASCII data from all files in a list. More...
 
void onParseAllRequest ()
 Parse all string data and generate graph data. More...
 
void onShowFilePreviewRequest ()
 Show content of selected file in text/table views. More...
 

Private Member Functions

void initConnections ()
 Init interconnections of all widgets. More...
 
void readSettings ()
 Reads dialog settings. More...
 
void writeSettings ()
 Writes dialog settings. More...
 

Private Attributes

std::unique_ptr< DataHandlerm_dataHandler
 
std::vector< GraphImportDatam_graphImportData
 
LoaderPreviewPanelm_previewPanel {nullptr}
 
LoaderSelectorPanelm_selectorPanel {nullptr}
 
QSplitter * m_splitter {nullptr}
 
DataLoaderToolBarm_toolBar {nullptr}
 

Detailed Description

Main dialog for the data loader.

Definition at line 35 of file dataloaderdialog.h.

Constructor & Destructor Documentation

◆ DataLoaderDialog()

gui2::DataLoaderDialog::DataLoaderDialog ( QWidget *  parent = nullptr)

Definition at line 87 of file dataloaderdialog.cpp.

88  : QDialog(parent)
89  , m_toolBar(new DataLoaderToolBar)
90  , m_selectorPanel(new LoaderSelectorPanel)
91  , m_previewPanel(new LoaderPreviewPanel)
92  , m_splitter(new QSplitter)
93  , m_dataHandler(std::make_unique<DataHandler>())
94 {
95  m_splitter->setChildrenCollapsible(false);
96  m_splitter->addWidget(m_selectorPanel);
97  m_splitter->addWidget(m_previewPanel);
98 
99  auto button_box = new QDialogButtonBox;
100  auto button = button_box->addButton("Import data", QDialogButtonBox::AcceptRole);
101  button->setAutoDefault(false);
102  button->setDefault(false);
103 
104  button = button_box->addButton("Cancel", QDialogButtonBox::RejectRole);
105  button->setAutoDefault(false);
106  button->setDefault(false);
107 
108  connect(button_box, &QDialogButtonBox::accepted, this, &DataLoaderDialog::accept);
109  connect(button_box, &QDialogButtonBox::rejected, this, &DataLoaderDialog::reject);
110 
111  auto layout = new QVBoxLayout(this);
112  layout->addWidget(m_toolBar);
113  layout->addWidget(m_splitter);
114  layout->addWidget(button_box);
115 
116  initConnections();
117  setWindowTitle("Data import dialog");
118 
119  readSettings();
120 }
LoaderSelectorPanel * m_selectorPanel
void readSettings()
Reads dialog settings.
LoaderPreviewPanel * m_previewPanel
DataLoaderToolBar * m_toolBar
std::unique_ptr< DataHandler > m_dataHandler
void initConnections()
Init interconnections of all widgets.

References accept(), initConnections(), m_previewPanel, m_selectorPanel, m_splitter, m_toolBar, and readSettings().

Here is the call graph for this function:

◆ ~DataLoaderDialog()

gui2::DataLoaderDialog::~DataLoaderDialog ( )

Definition at line 122 of file dataloaderdialog.cpp.

123 {
124  writeSettings();
125 }
void writeSettings()
Writes dialog settings.

References writeSettings().

Here is the call graph for this function:

Member Function Documentation

◆ accept()

void gui2::DataLoaderDialog::accept ( )
overrideprotected

Definition at line 170 of file dataloaderdialog.cpp.

171 {
172  invoke_and_catch([this]() { onParseAllRequest(); });
173 
174  QDialog::accept();
175  close();
176 }
void onParseAllRequest()
Parse all string data and generate graph data.

References onParseAllRequest().

Referenced by DataLoaderDialog().

Here is the call graph for this function:

◆ fileNames()

QStringList gui2::DataLoaderDialog::fileNames ( ) const

Definition at line 156 of file dataloaderdialog.cpp.

157 {
158  return m_selectorPanel->fileNames();
159 }

References gui2::LoaderSelectorPanel::fileNames(), and m_selectorPanel.

Referenced by gui2::ImportDataEditor::invokeImportDialog().

Here is the call graph for this function:

◆ graphImportData()

std::vector< GraphImportData > gui2::DataLoaderDialog::graphImportData ( ) const

Returns the result of whole parsing.

Definition at line 129 of file dataloaderdialog.cpp.

130 {
131  return m_graphImportData;
132 }
std::vector< GraphImportData > m_graphImportData

References m_graphImportData.

Referenced by gui2::ImportDataEditor::invokeImportDialog().

◆ initConnections()

void gui2::DataLoaderDialog::initConnections ( )
private

Init interconnections of all widgets.

Definition at line 265 of file dataloaderdialog.cpp.

266 {
267  // connect toolbar and LoaderSelectorPanel
272 
273  // updates raw data container when file list changed
276 
277  // update text/table view when file selection changed
280 
281  // update text/table view when parser properties changed
284 }
void onLoadFilesRequest()
Loads ASCII data from all files in a list.
void onShowFilePreviewRequest()
Show content of selected file in text/table views.
void fileNamesChanged(const QStringList &file_names)
void fileSelectionChanged(const QStringList &file_names)

References gui2::DataLoaderToolBar::addFilesRequest(), gui2::LoaderSelectorPanel::fileNamesChanged(), gui2::LoaderSelectorPanel::fileSelectionChanged(), m_selectorPanel, m_toolBar, gui2::LoaderSelectorPanel::onAddFilesRequest(), onLoadFilesRequest(), gui2::LoaderSelectorPanel::onRemoveFileRequest(), onShowFilePreviewRequest(), gui2::LoaderSelectorPanel::parserPropertyChanged(), and gui2::DataLoaderToolBar::removeFilesRequest().

Referenced by DataLoaderDialog().

Here is the call graph for this function:

◆ invokeFileSelectorDialog()

void gui2::DataLoaderDialog::invokeFileSelectorDialog ( )

Invokes file selector dialog.

Definition at line 151 of file dataloaderdialog.cpp.

152 {
154 }

References m_selectorPanel, and gui2::LoaderSelectorPanel::onAddFilesRequest().

Referenced by gui2::ImportDataEditor::invokeImportDialog().

Here is the call graph for this function:

◆ keyPressEvent()

void gui2::DataLoaderDialog::keyPressEvent ( QKeyEvent *  event)
overrideprotected

Make dialog intact to enter-key to handle it by LoadSelectorPanel.

Definition at line 163 of file dataloaderdialog.cpp.

164 {
165  if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)
166  return;
167  QDialog::keyPressEvent(event);
168 }

◆ onLoadFilesRequest

void gui2::DataLoaderDialog::onLoadFilesRequest ( )
privateslot

Loads ASCII data from all files in a list.

Definition at line 180 of file dataloaderdialog.cpp.

181 {
182  auto update_raw_data = [this]() {
183  m_dataHandler->updateRawData(
185  };
186  invoke_and_catch(update_raw_data);
187 }
MVVM_VIEW_EXPORT std::vector< std::string > fromStringList(const QStringList &string_list)
Converts vector of strings to QStringList.

References gui2::LoaderSelectorPanel::fileNames(), ModelView::Utils::fromStringList(), m_dataHandler, and m_selectorPanel.

Referenced by initConnections().

Here is the call graph for this function:

◆ onParseAllRequest

void gui2::DataLoaderDialog::onParseAllRequest ( )
privateslot

Parse all string data and generate graph data.

Definition at line 210 of file dataloaderdialog.cpp.

211 {
212  m_graphImportData.clear();
213 
214  auto parser = m_selectorPanel->createParser();
215  for (const auto& name : m_selectorPanel->fileNames()) {
216  auto data_to_parse = m_dataHandler->textData(name.toStdString());
217 
218  parser->process(data_to_parse);
219  auto parsed_text = parser->parsedData();
220 
221  auto columns = m_previewPanel->columnInfo();
222  for (auto [axis_info, intensity_info] : Utils::CreateGraphInfoPairs(columns)) {
223  auto data = Utils::CreateData(parsed_text, axis_info, intensity_info);
224  data.graph_description = createImportDescription(name, axis_info, intensity_info);
225  m_graphImportData.emplace_back(data);
226  }
227  }
228 }
std::vector< ColumnInfo > columnInfo() const
std::unique_ptr< ParserInterface > createParser() const
QString const & name(EShape k)
Definition: particles.cpp:21
DAREFLCORE_EXPORT std::vector< std::pair< ColumnInfo, ColumnInfo > > CreateGraphInfoPairs(const std::vector< ColumnInfo > &column_info)
Pack ColumnInfo into pairs representing {AxisType, IntensityType}.
DAREFLCORE_EXPORT GraphImportData CreateData(const std::vector< std::vector< std::string >> &text_data, const ColumnInfo &axis, const ColumnInfo &intensity)
Creates structure from text data.

References gui2::LoaderPreviewPanel::columnInfo(), gui2::Utils::CreateData(), gui2::Utils::CreateGraphInfoPairs(), gui2::LoaderSelectorPanel::createParser(), gui2::LoaderSelectorPanel::fileNames(), m_dataHandler, m_graphImportData, m_previewPanel, m_selectorPanel, and RealSpace::Particles::name().

Referenced by accept().

Here is the call graph for this function:

◆ onShowFilePreviewRequest

void gui2::DataLoaderDialog::onShowFilePreviewRequest ( )
privateslot

Show content of selected file in text/table views.

Definition at line 191 of file dataloaderdialog.cpp.

192 {
193  auto selected_files = m_selectorPanel->selectedFileNames();
194  if (selected_files.empty()) {
196  return;
197  }
198 
199  auto data_to_parse = m_dataHandler->textData(selected_files.back().toStdString());
200 
201  // creating parser using current settings
202  auto parser = m_selectorPanel->createParser();
203  parser->process(data_to_parse);
204 
205  m_previewPanel->showData(parser.get());
206 }
void showData(const ParserInterface *parser)
Sets raw text to the TextView.
QStringList selectedFileNames() const

References gui2::LoaderPreviewPanel::clearPanel(), gui2::LoaderSelectorPanel::createParser(), m_dataHandler, m_previewPanel, m_selectorPanel, gui2::LoaderSelectorPanel::selectedFileNames(), and gui2::LoaderPreviewPanel::showData().

Referenced by initConnections().

Here is the call graph for this function:

◆ readSettings()

void gui2::DataLoaderDialog::readSettings ( )
private

Reads dialog settings.

Definition at line 232 of file dataloaderdialog.cpp.

233 {
234  QSettings settings;
235 
236  if (settings.contains(dialogsize_setting_name()))
237  resize(settings.value(dialogsize_setting_name(), QSize(800, 600)).toSize());
238 
239  if (settings.contains(splittersize_setting_name())) {
240  QStringList splitter_sizes = QStringList() << "400"
241  << "400";
242  splitter_sizes = settings.value(splittersize_setting_name(), splitter_sizes).toStringList();
243  QList<int> sizes;
244  for (auto num : splitter_sizes)
245  sizes.push_back(num.toInt());
246  m_splitter->setSizes(sizes);
247  }
248 }

References m_splitter.

Referenced by DataLoaderDialog().

◆ setTargetCanvas()

void gui2::DataLoaderDialog::setTargetCanvas ( const std::vector< std::string > &  canvas_names,
int  current_index 
)

Set list of target canvas to define entr where to import.

Definition at line 136 of file dataloaderdialog.cpp.

138 {
139  m_selectorPanel->setTargetCanvas(ModelView::Utils::toStringList(canvas_names), current_index);
140 }
void setTargetCanvas(const QStringList &canvas_names, int current_index)
MVVM_VIEW_EXPORT QStringList toStringList(const std::vector< std::string > &vec)
Converts vector of strings to QStringList.

References m_selectorPanel, gui2::LoaderSelectorPanel::setTargetCanvas(), and ModelView::Utils::toStringList().

Referenced by gui2::ImportDataEditor::invokeImportDialog().

Here is the call graph for this function:

◆ targetCanvasIndex()

int gui2::DataLoaderDialog::targetCanvasIndex ( ) const

Returns index of target canvas for graph import.

Definition at line 144 of file dataloaderdialog.cpp.

145 {
147 }

References m_selectorPanel, and gui2::LoaderSelectorPanel::targetCanvasIndex().

Referenced by gui2::ImportDataEditor::invokeImportDialog().

Here is the call graph for this function:

◆ writeSettings()

void gui2::DataLoaderDialog::writeSettings ( )
private

Writes dialog settings.

Definition at line 252 of file dataloaderdialog.cpp.

253 {
254  QSettings settings;
255  settings.setValue(dialogsize_setting_name(), size());
256 
257  QStringList splitter_sizes;
258  for (auto x : m_splitter->sizes())
259  splitter_sizes.push_back(QString::number(x));
260  settings.setValue(splittersize_setting_name(), splitter_sizes);
261 }

References m_splitter.

Referenced by ~DataLoaderDialog().

Member Data Documentation

◆ m_dataHandler

std::unique_ptr<DataHandler> gui2::DataLoaderDialog::m_dataHandler
private

◆ m_graphImportData

std::vector<GraphImportData> gui2::DataLoaderDialog::m_graphImportData
private

Definition at line 72 of file dataloaderdialog.h.

Referenced by graphImportData(), and onParseAllRequest().

◆ m_previewPanel

LoaderPreviewPanel* gui2::DataLoaderDialog::m_previewPanel {nullptr}
private

◆ m_selectorPanel

◆ m_splitter

QSplitter* gui2::DataLoaderDialog::m_splitter {nullptr}
private

Definition at line 69 of file dataloaderdialog.h.

Referenced by DataLoaderDialog(), readSettings(), and writeSettings().

◆ m_toolBar

DataLoaderToolBar* gui2::DataLoaderDialog::m_toolBar {nullptr}
private

Definition at line 66 of file dataloaderdialog.h.

Referenced by DataLoaderDialog(), and initConnections().


The documentation for this class was generated from the following files: