Added generic and flexible ResourceSelectDialog class

Functionality from QuickLoadDialog which can be used in similiar dialogs
for selecting resources has been moved into generic and highly flexible
base class ResourceSelectDialog.
This commit is contained in:
Tobias Doerffel
2009-10-26 23:44:57 +01:00
parent 722aa11563
commit 582ce407de
4 changed files with 214 additions and 40 deletions

View File

@@ -23,21 +23,23 @@
*/
#include "QuickLoadDialog.h"
#include "ResourceListModel.h"
#include "engine.h"
#include "ui_QuickLoadDialog.h"
QuickLoadDialog::QuickLoadDialog( QWidget * _parent,
ResourceItem::Type _typeFilter ) :
QDialog( _parent ),
ui( new Ui::QuickLoadDialog ),
m_listModel( new ResourceListModel( engine::mergedResourceDB(), this ) )
ResourceItem::Type _typeFilter,
DatabaseScope _databaseScope ) :
ResourceSelectDialog( _parent, ResourceSelectDialog::ListModel,
_databaseScope ),
ui( new Ui::QuickLoadDialog )
{
// setup form
ui->setupUi( this );
// setup ResourceSelectDialog
setupUi();
// setup type combobox + type filtering
for( int i = ResourceItem::TypeUnknown+1; i < ResourceItem::NumTypes; ++i )
{
@@ -53,16 +55,6 @@ QuickLoadDialog::QuickLoadDialog( QWidget * _parent,
{
ui->resourceTypeComboBox->setCurrentIndex( _typeFilter );
}
// setup list view to display our model
ui->resourceListView->setModel( m_listModel );
ui->resourceListView->selectionModel()->select(
m_listModel->index( 0, 0 ),
QItemSelectionModel::SelectCurrent );
// connect filter edit with model
connect( ui->filterEdit, SIGNAL( textChanged( const QString & ) ),
m_listModel, SLOT( setKeywordFilter( const QString & ) ) );
}
@@ -70,18 +62,6 @@ QuickLoadDialog::QuickLoadDialog( QWidget * _parent,
QuickLoadDialog::~QuickLoadDialog()
{
delete m_listModel;
}
void QuickLoadDialog::setTypeFilter( int _type )
{
m_listModel->setTypeFilter( static_cast<ResourceItem::Type>( _type ) );
}
#include "moc_QuickLoadDialog.cxx"

View File

@@ -0,0 +1,128 @@
/*
* ResourceSelectDialog.cpp - implementation of ResourceSelectDialog
*
* Copyright (c) 2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program 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 2 of the License, or (at your option) any later version.
*
* This program 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 this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include <QtGui/QAbstractItemView>
#include <QtGui/QLineEdit>
#include "ResourceSelectDialog.h"
#include "ResourceListModel.h"
#include "ResourceTreeModel.h"
#include "engine.h"
ResourceSelectDialog::ResourceSelectDialog( QWidget * _parent,
ModelTypes _modelType,
DatabaseScope _databaseScope ) :
QDialog( _parent ),
m_model( NULL )
{
ResourceDB * db = NULL;
switch( _databaseScope )
{
case WorkingDirResources:
db = engine::workingDirResourceDB();
break;
case WebResources:
db = engine::webResourceDB();
break;
case AllResources:
default:
db = engine::mergedResourceDB();
break;
}
switch( _modelType )
{
case ListModel:
m_model = new ResourceListModel( db, this );
break;
case TreeModel:
m_model = new ResourceTreeModel( db, this );
break;
}
}
ResourceSelectDialog::~ResourceSelectDialog()
{
delete m_model;
}
ResourceItem * ResourceSelectDialog::selectedItem()
{
if( result() != QDialog::Accepted )
{
return NULL;
}
QAbstractItemView * resourceView = findChild<QAbstractItemView *>();
if( !resourceView )
{
return NULL;
}
return m_model->item( resourceView->currentIndex() );
}
void ResourceSelectDialog::setupUi( )
{
QAbstractItemView * resourceView = findChild<QAbstractItemView *>();
if( resourceView )
{
// setup view to display our model
resourceView->setModel( m_model );
resourceView->selectionModel()->select( m_model->index( 0, 0 ),
QItemSelectionModel::SelectCurrent );
}
QLineEdit * filterEdit = findChild<QLineEdit *>();
if( filterEdit )
{
// connect filter edit with model
connect( filterEdit, SIGNAL( textChanged( const QString & ) ),
m_model, SLOT( setKeywordFilter( const QString & ) ) );
}
}
void ResourceSelectDialog::setTypeFilter( int _type )
{
m_model->setTypeFilter( static_cast<ResourceItem::Type>( _type ) );
}
#include "moc_ResourceSelectDialog.cxx"