ResourceChooser.cpp
Go to the documentation of this file.
1 #include "ResourceChooser.h"
2 
3 #include "FileChooser.h"
4 
5 //! Qt include files
6 #include <QHBoxLayout>
7 #include <QVBoxLayout>
8 #include <QGridLayout>
9 #include <QRadioButton>
10 #include <QPushButton>
11 #include <QButtonGroup>
12 #include <QDialog>
13 
14 namespace te_qt = te::qt::widgets;
15 
17 QWidget(parent)
18 {
19  m_fchooser = new FileChooser(this);
20  QRadioButton* f = new QRadioButton(tr("File"), this);
21  QRadioButton* d = new QRadioButton(tr("Directory"), this);
22  QButtonGroup* grp = new QButtonGroup(this);
23  QHBoxLayout* hlay = new QHBoxLayout;
24  QVBoxLayout* vlay = new QVBoxLayout;
25 
26  hlay->addWidget(m_fchooser);
27  vlay->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
28  hlay->addWidget(f);
29  hlay->addWidget(d);
30 
31  vlay->addLayout(hlay);
32  vlay->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
33 
34  QGridLayout* grd = new QGridLayout(this);
35  grd->addLayout(vlay, 0, 0, 1, 1);
36 
37  grp->addButton(f, FileChooser::FILE);
38  grp->addButton(d, FileChooser::FOLDER);
39 
40  f->setChecked(true);
41 
42  connect(grp, SIGNAL(buttonClicked(int)), SLOT(setResource(int)));
43 }
44 
46 
48 {
50 }
51 
52 void te_qt::ResourceChooser::setFilterPattern(const QString& filter)
53 {
55 }
56 
57 QString te_qt::ResourceChooser::getResource(const QString& initialPath, const QString& filter, QWidget* parent)
58 {
59  QDialog dlg(parent);
60  ResourceChooser* rsc = new ResourceChooser(&dlg);
61  QPushButton* okBtn = new QPushButton(tr("&Ok"), &dlg);
62  QPushButton* cancelBtn = new QPushButton(tr("&Cancel"), &dlg);
63  QPushButton* helpBtn = new QPushButton(tr("&Help"), &dlg);
64  QHBoxLayout* hlay = new QHBoxLayout;
65  QVBoxLayout* vlay = new QVBoxLayout;
66  QGridLayout* grd = new QGridLayout(&dlg);
67 
68  hlay->addWidget(helpBtn);
69  hlay->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
70  hlay->addWidget(okBtn);
71  hlay->addWidget(cancelBtn);
72 
73  vlay->addWidget(rsc);
74  vlay->addLayout(hlay);
75  grd->addLayout(vlay, 0, 0, 1, 1);
76 
77  rsc->m_fchooser->setInitialPath(initialPath);
78  rsc->setFilterPattern(filter);
79 
80  dlg.setWindowTitle(tr("Choose a xml file or a directory containing xml plug-in files"));
81 
82  dlg.connect(okBtn, SIGNAL(pressed()), SLOT(accept()));
83  dlg.connect(cancelBtn, SIGNAL(pressed()), SLOT(reject()));
84 // dlg.connect(helpBtn, SIGNAL(), SLOT());
85 
86  if(dlg.exec() == QDialog::Accepted)
87  return rsc->getSelectedResource();
88 
89  return "";
90 }
91 
93 {
95 }
void setResource(int id)
This is called when the user changes the type of resource to search.
Namespace for the Qt Widgets module of TerraLib.
QString getSelectedResource()
Returns the selected resource.
Defines a component for choose a file.
void setInitialPath(const QString &path)
This will open the dialog of file selection in the given path.
Definition: FileChooser.cpp:60
FileChooser * m_fchooser
File chooser component.
Defines a component for choose a file.
Definition: FileChooser.h:60
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
static QString getResource(const QString &initialPath, const QString &filter, QWidget *parent=0)
use the static when the ResourceChooser have to be presented as a Dialog.
ResourceType
Type of resource required.
Definition: FileChooser.h:69
Defines a component for choosing a file or directory.
ResourceChooser(QWidget *parent=0)
Constructor.
void setResourceType(const ResourceType &type)
Updates the resource type of the search to be done.
Definition: FileChooser.cpp:81
QString getSelectedResource() const
Returns the text presented in line edit.
Definition: FileChooser.cpp:76
Defines a component for choosing a file or directory.
void setFilterPattern(const QString &filter)
Defines the filter for files of interest.
Definition: FileChooser.cpp:70
void setFilterPattern(const QString &filter)
Setts a pattern for filtering the searched files.