VPTissue Reference Manual
StepFilterProxyModel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
21 
22 #include <cassert>
23 
24 namespace SimPT_Shell {
25 
27  : QSortFilterProxyModel(parent)
28 {
29 }
30 
32 {
33 }
34 
35 void StepFilterProxyModel::SetStepRanges(const QString &ranges)
36 {
37  assert(QRegExp(StepSelection::g_repeated_regex).exactMatch(ranges) && "Ranges string doesn't match StepSelection::g_repeated_regex");
38  m_step_selection.SetSelectionText(ranges.toStdString());
39  invalidateFilter();
40 }
41 
42 bool StepFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
43 {
44  QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
45  bool ok;
46  int step = sourceModel()->data(index).toInt(&ok);
47 
48  assert(ok && "Couldn't get int from item in first column (of sourceModel)");
49 
50  return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent) && m_step_selection.Contains(step);
51 }
52 
53 } // namespace
bool Contains(int step) const
Checks whether the selection contains a specified step.
Namespace for SimPT shell package.
Definition: Client.cpp:50
Interface for StepFilterProxyModel.
void SetSelectionText(const std::string &ranges)
Sets the selected ranges of steps.
see the online Qt documentation
StepFilterProxyModel(QObject *parent=nullptr)
Constructor.
see the online Qt documentation
static const QRegExp g_repeated_regex
Regex for a series of repeated ranges, separated by , of ;.
Definition: StepSelection.h:54
void SetStepRanges(const QString &ranges)
Sets the ranges of the accepted steps of the first column.