24 #include "selectdialog.h"
26 #include <klocalizedstring.h>
27 #include <kmessagebox.h>
31 #include <QListWidget>
37 class SelectDialog::SelectDialogPrivate
40 QListWidget *mResourceId;
41 QMap<int, Resource*> mResourceMap;
50 : KDialog( parent ), d( new SelectDialogPrivate )
53 setCaption( i18n(
"Resource Selection" ) );
55 setButtons( Ok|Cancel );
56 setDefaultButton( Ok );
58 QWidget *widget =
new QWidget(
this );
59 setMainWidget( widget );
61 QVBoxLayout *mainLayout =
new QVBoxLayout( widget );
62 mainLayout->setMargin( 0 );
64 QGroupBox *groupBox =
new QGroupBox( widget );
65 QGridLayout *grid =
new QGridLayout;
66 groupBox->setLayout( grid );
67 groupBox->setTitle( i18n(
"Resources" ) );
69 d->mResourceId =
new QListWidget( groupBox );
70 grid->addWidget( d->mResourceId, 0, 0 );
72 mainLayout->addWidget( groupBox );
75 qSort( list.begin(), list.end(), resourceNameLessThan );
79 for (
int i = 0; i < list.count(); ++i ) {
81 if ( resource && !resource->
readOnly() ) {
82 d->mResourceMap.insert( counter, resource );
88 d->mResourceId->setCurrentRow( 0 );
89 connect( d->mResourceId, SIGNAL(itemActivated(QListWidgetItem*)),
100 if ( d->mResourceId->currentRow() != -1 ) {
101 return d->mResourceMap[ d->mResourceId->currentRow() ];
109 if ( list.count() == 0 ) {
110 KMessageBox::error( parent, i18n(
"There is no resource available." ) );
114 if ( list.count() == 1 ) {
122 for (
int i=0; i< list.size(); ++i ) {
123 if ( !list.at( i )->readOnly() ) {
129 found = list.at( i );
138 if ( dlg.exec() == KDialog::Accepted ) {
static Resource * getResource(QList< Resource * > list, QWidget *parent=0)
Opens a dialog showing the available resources and returns the resource the user has selected...
Dialog for selecting a resource.
Resource * resource()
Returns selected resource.
~SelectDialog()
Destructor.
SelectDialog(QList< Resource * > list, QWidget *parent=0)
Constructor.
This class provides a resource which is managed in a general way.
virtual bool readOnly() const
Returns, if the resource is read-only.
virtual QString resourceName() const
Returns the name of resource.