19 #include <QFileDialog>
20 #include <QItemSelectionModel>
22 #include <QMessageBox>
24 #include <QStringListModel>
25 #include <QVBoxLayout>
30 const QString current_workdir_key =
"currentworkdir";
32 const QString workdir_setting_name()
40 : QWidget(parent), m_listView(new QListView), m_listModel(new QStringListModel(this))
44 auto layout =
new QVBoxLayout(
this);
45 layout->setContentsMargins(0, 0, 0, 0);
49 m_listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
51 m_listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
53 connect(
m_listView->selectionModel(), &QItemSelectionModel::selectionChanged,
this,
66 QFileDialog dialog(
this,
"Select one or more files to load",
m_currentWorkdir);
67 dialog.setFileMode(QFileDialog::ExistingFiles);
68 dialog.setNameFilter(
"Text (*.txt *.csv *.dat);; Other (*.*)");
69 dialog.setOption(QFileDialog::DontUseNativeDialog);
70 QStringList file_names = dialog.exec() ? dialog.selectedFiles() : QStringList();
74 if (file_names.empty())
85 auto selected =
m_listView->selectionModel()->selectedIndexes();
86 while (!selected.empty()) {
88 selected =
m_listView->selectionModel()->selectedIndexes();
108 for (
auto index :
m_listView->selectionModel()->selectedIndexes())
109 result.append(
m_listModel->data(index).toString());
120 if (settings.contains(workdir_setting_name()))
137 for (
const auto& file_name : file_names) {
140 msgBox.setText(file_name +
"\nmay be a binary file. Open it anyway?");
141 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
142 int ret = msgBox.exec();
143 if (ret == QMessageBox::Yes)
144 result.push_back(file_name);
146 result.push_back(file_name);
156 auto file_name = file_names.back();
166 QStringList updated_names = current_names + file_names;
167 updated_names.removeDuplicates();
177 if (
m_listView->selectionModel()->selectedIndexes().empty()) {
178 auto flags = QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows;
180 m_listView->selectionModel()->select(toSelect, flags);
bool is_binary(const std::string &filename)
Returns true if file is binary.
MVVM_MODEL_EXPORT std::string parent_path(const std::string &path)
Returns the path to the parent directory.
const QString DataLoaderGroupKey
Constants for QSettings.
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.