1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-10-04 09:31:41 +02:00
Files
tomahawk/src/widgets/AccountModelFactoryProxy.cpp
Teo Mrnjavac 85a20b4ae9 Initial commit for the new Accounts pop-up widget.
Still much left to do.
2012-08-15 22:42:09 +02:00

67 lines
2.0 KiB
C++

/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AccountModelFactoryProxy.h"
using namespace Tomahawk;
using namespace Accounts;
AccountModelFactoryProxy::AccountModelFactoryProxy( QObject* parent )
: QSortFilterProxyModel( parent )
, m_filterEnabled( false )
, m_filterRowType( AccountModel::TopLevelFactory )
{
}
bool
AccountModelFactoryProxy::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
{
if ( !m_filterEnabled )
return true;
const QModelIndex idx = sourceModel()->index( sourceRow, 0, sourceParent );
const Qt::CheckState checkState = static_cast< Qt::CheckState >( idx.data( Qt::CheckStateRole ).value< int >() );
if( checkState == Qt::Unchecked ) //if the service is not even enabled
return false;
const AccountModel::RowType rowType = static_cast< AccountModel::RowType >( idx.data( AccountModel::RowTypeRole ).value< int >() );
return rowType == m_filterRowType;
}
void
AccountModelFactoryProxy::setFilterEnabled( bool enabled )
{
m_filterEnabled = enabled;
invalidate();
}
void
AccountModelFactoryProxy::setFilterRowType( AccountModel::RowType rowType )
{
if( rowType == m_filterRowType )
return;
m_filterRowType = rowType;
if( m_filterEnabled )
invalidate();
}