2015-02-02 22:25:30 +00:00
|
|
|
/* Copyright 2013-2015 MultiMC Contributors
|
2013-11-04 01:53:05 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-09-15 23:54:39 +01:00
|
|
|
#include "EnabledItemFilter.h"
|
|
|
|
|
2013-11-04 01:53:05 +00:00
|
|
|
EnabledItemFilter::EnabledItemFilter(QObject *parent) : QSortFilterProxyModel(parent)
|
2013-09-15 23:54:39 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnabledItemFilter::setActive(bool active)
|
|
|
|
{
|
|
|
|
m_active = active;
|
|
|
|
invalidateFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EnabledItemFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
|
|
|
{
|
2013-11-04 01:53:05 +00:00
|
|
|
if (!m_active)
|
2013-09-15 23:54:39 +01:00
|
|
|
return true;
|
|
|
|
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
2013-11-04 01:53:05 +00:00
|
|
|
if (sourceModel()->flags(index) & Qt::ItemIsEnabled)
|
2013-09-15 23:54:39 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-04 01:53:05 +00:00
|
|
|
bool EnabledItemFilter::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
2013-09-15 23:54:39 +01:00
|
|
|
{
|
2013-11-04 01:53:05 +00:00
|
|
|
return QSortFilterProxyModel::lessThan(left, right);
|
2013-09-15 23:54:39 +01:00
|
|
|
}
|