25 #include <QApplication>
29 #include <QGraphicsScene>
30 #include <QGraphicsView>
31 #include <QHeaderView>
35 #include <QMessageBox>
37 #include <QRegExpValidator>
39 #include <QStandardItemModel>
50 ConversionList::ConversionList(
QWidget *parent)
52 m_model(new QStandardItemModel(this)),
55 connect(m_model, SIGNAL(itemChanged(QStandardItem*)),
this, SLOT(UpdateSelectAllCheckState()));
56 m_filter_model->setSourceModel(m_model);
57 m_filter_model->setFilterKeyColumn(1);
69 QList<QStandardItem*> row;
71 auto timestep_item =
new QStandardItem();
72 auto filename_item =
new QStandardItem();
74 timestep_item->setCheckable(
true);
75 timestep_item->setData(entry.timestep, Qt::DisplayRole);
76 timestep_item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
77 timestep_item->setEditable(
false);
78 row.append(timestep_item);
80 filename_item->setData(QString::fromStdString(entry.files), Qt::DisplayRole);
81 filename_item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
82 filename_item->setEditable(
false);
83 row.append(filename_item);
85 m_model->appendRow(row);
91 m_model->setHorizontalHeaderLabels(QStringList() <<
"Step" <<
"File(s)");
92 m_select_all_check_box->setChecked(
false);
95 void ConversionList::EmitSelectionChanged()
97 emit
SelectionChanged(!m_table_view->selectionModel()->selection().isEmpty());
100 vector<ConversionList::EntryType> ConversionList::GetCheckedEntries()
const
102 vector<EntryType> result;
103 for (
int i = 0; i < m_model->rowCount(); ++i) {
104 auto timestep_item = m_model->item(i, 0);
105 if (timestep_item->checkState() == Qt::Checked) {
106 auto filename_item = m_model->item(i, 1);
108 int timestep = timestep_item->data(Qt::DisplayRole).toInt(&ok);
109 assert(ok &&
"Couldn't get int from checked row");
110 string filename = filename_item->data(Qt::DisplayRole).toString().toStdString();
111 result.push_back(EntryType({timestep, filename}));
117 bool ConversionList::HasCheckedEntries()
const
119 return m_model->rowCount() > 0 && m_select_all_check_box->checkState() != Qt::Unchecked;
122 void ConversionList::UpdateStepFilter()
124 if (m_step_filter->hasAcceptableInput())
128 UpdateSelectAllCheckState();
131 void ConversionList::UpdateFileFilter()
133 m_filter_model->setFilterWildcard(m_file_filter->text());
136 UpdateSelectAllCheckState();
139 void ConversionList::UpdateSelectAllCheckState()
141 Qt::CheckState checkState = Qt::Unchecked;
142 if (m_filter_model->rowCount() > 0) {
143 QModelIndex index = m_filter_model->mapToSource(m_filter_model->index(0, 0));
144 checkState = m_model->itemFromIndex(index)->checkState();
145 for (
int i = 1; i < m_filter_model->rowCount(); ++i) {
146 index = m_filter_model->mapToSource(m_filter_model->index(i, 0));
147 if (checkState != m_model->itemFromIndex(index)->checkState()) {
148 checkState = Qt::PartiallyChecked;
155 m_select_all_check_box->setTristate(
false);
156 m_select_all_check_box->setCheckState(checkState);
160 void ConversionList::SelectAll()
162 Qt::CheckState checkState = m_select_all_check_box->checkState();
163 for (
int i = 0; i < m_filter_model->rowCount(); ++i) {
164 QModelIndex index = m_filter_model->mapToSource(m_filter_model->index(i, 0));
165 m_model->itemFromIndex(index)->setCheckState(checkState);
168 m_select_all_check_box->setTristate(
false);
172 void ConversionList::SetupGui()
175 QVBoxLayout* layout =
new QVBoxLayout();
176 layout->setMargin(0);
179 m_table_view =
new QTableView();
180 m_table_view->setModel(m_filter_model);
181 m_table_view->setShowGrid(
false);
182 m_table_view->verticalHeader()->setHidden(
true);
183 m_table_view->setSelectionBehavior(QAbstractItemView::SelectRows);
184 m_table_view->setHorizontalScrollMode(QTableView::ScrollPerPixel);
185 #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
186 m_table_view->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
187 m_table_view->horizontalHeader()->setSectionsClickable(
false);
189 m_table_view->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
190 m_table_view->horizontalHeader()->setClickable(
false);
192 m_table_view->horizontalHeader()->setStretchLastSection(
true);
193 m_table_view->horizontalHeader()->setHighlightSections(
false);
194 layout->addWidget(m_table_view);
195 connect(m_table_view->selectionModel(), SIGNAL(selectionChanged(
const QItemSelection&,
const QItemSelection&)),
196 this, SLOT(EmitSelectionChanged()));
200 QHBoxLayout* selectionLayout =
new QHBoxLayout();
201 selectionLayout->addWidget(
new QLabel(
"Filter:"));
204 m_step_filter =
new QLineEdit();
205 m_step_filter->setPlaceholderText(
"steps");
206 m_step_filter->setSizePolicy(QSizePolicy::Ignored, m_step_filter->sizePolicy().verticalPolicy());
208 selectionLayout->addWidget(m_step_filter, 1);
209 connect(m_step_filter, SIGNAL(textChanged(
const QString&)),
this, SLOT(UpdateStepFilter()));
212 selectionLayout->addWidget(
new QLabel(
"in"));
215 m_file_filter =
new QLineEdit();
216 m_file_filter->setPlaceholderText(
"files");
217 m_file_filter->setSizePolicy(QSizePolicy::Ignored, m_file_filter->sizePolicy().verticalPolicy());
218 selectionLayout->addWidget(m_file_filter, 1);
219 connect(m_file_filter, SIGNAL(textChanged(
const QString&)),
this, SLOT(UpdateFileFilter()));
222 m_select_all_check_box =
new QCheckBox(
"Select All");
223 connect(m_select_all_check_box, SIGNAL(clicked()),
this, SLOT(SelectAll()));
224 selectionLayout->addWidget(m_select_all_check_box);
225 layout->addLayout(selectionLayout);
233 void ConversionList::ResizeColumns()
236 int scrollPos = m_table_view->verticalScrollBar()->value();
237 m_table_view->scrollToBottom();
238 m_table_view->resizeColumnsToContents();
239 m_table_view->horizontalHeader()->setStretchLastSection(
true);
240 m_table_view->verticalScrollBar()->setValue(scrollPos);
Interface for ConversionList.
void AddEntry(const EntryType &)
Add entry.
Custom proxy model to filter a QStandardModel with file names with time steps.
Namespace for miscellaneous utilities.
Namespace for SimPT shell package.
Interface for StepSelection.
Interface for StepFilterProxyModel.
void CheckedChanged()
Signal emitted when the check state of some SimStates in the conversion has changed.
void Clear()
Clear all entries.
void SelectionChanged(bool selected)
Signal emitted when the selection in the conversion changes.
see the online Qt documentation
static const QRegExp g_repeated_regex
Regex for a series of repeated ranges, separated by , of ;.
void SetStepRanges(const QString &ranges)
Sets the ranges of the accepted steps of the first column.
virtual ~ConversionList()
Destructor.