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:
@@ -25,29 +25,22 @@
|
||||
#ifndef _QUICK_LOAD_DIALOG_H
|
||||
#define _QUICK_LOAD_DIALOG_H
|
||||
|
||||
#include <QtGui/QDialog>
|
||||
|
||||
#include "ResourceItem.h"
|
||||
#include "ResourceSelectDialog.h"
|
||||
|
||||
namespace Ui { class QuickLoadDialog; }
|
||||
class ResourceListModel;
|
||||
|
||||
class QuickLoadDialog : public QDialog
|
||||
class QuickLoadDialog : public ResourceSelectDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QuickLoadDialog( QWidget * _parent, ResourceItem::Type _typeFilter =
|
||||
ResourceItem::TypeUnknown );
|
||||
ResourceItem::TypeUnknown,
|
||||
DatabaseScope _databaseScope = AllResources );
|
||||
virtual ~QuickLoadDialog();
|
||||
|
||||
|
||||
private slots:
|
||||
void setTypeFilter( int );
|
||||
|
||||
|
||||
private:
|
||||
Ui::QuickLoadDialog * ui;
|
||||
ResourceListModel * m_listModel;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
73
include/ResourceSelectDialog.h
Normal file
73
include/ResourceSelectDialog.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* ResourceSelectDialog.h - header file for 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _RESOURCE_SELECT_DIALOG_H
|
||||
#define _RESOURCE_SELECT_DIALOG_H
|
||||
|
||||
#include <QtGui/QDialog>
|
||||
|
||||
class ResourceItem;
|
||||
class ResourceModel;
|
||||
|
||||
class ResourceSelectDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum ModelTypes
|
||||
{
|
||||
ListModel,
|
||||
TreeModel
|
||||
} ;
|
||||
|
||||
enum DatabaseScope
|
||||
{
|
||||
WorkingDirResources,
|
||||
WebResources,
|
||||
AllResources
|
||||
} ;
|
||||
|
||||
ResourceSelectDialog( QWidget * _parent, ModelTypes _modelType,
|
||||
DatabaseScope _databaseScope = AllResources );
|
||||
virtual ~ResourceSelectDialog();
|
||||
|
||||
// returns the selected item (NULL if the dialog was not accepted or no
|
||||
// valid item was selected)
|
||||
ResourceItem * selectedItem();
|
||||
|
||||
|
||||
protected:
|
||||
void setupUi();
|
||||
|
||||
|
||||
private slots:
|
||||
void setTypeFilter( int );
|
||||
|
||||
|
||||
private:
|
||||
ResourceModel * m_model;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
128
src/gui/ResourceSelectDialog.cpp
Normal file
128
src/gui/ResourceSelectDialog.cpp
Normal 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"
|
||||
|
||||
Reference in New Issue
Block a user