All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataSourceSelectorDialog.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/connector/DataSourceSelectorDialog.cpp
22 
23  \brief A dialog for connecting to a data source.
24 */
25 
26 // TerraLib
27 #include "../../../../common/Translator.h"
28 #include "../../Exception.h"
31 #include "ui_DataSourceSelectorDialogForm.h"
32 #include "ui_DataSourceSelectorWidgetForm.h"
33 
34 // Qt
35 #include <QMessageBox>
36 #include <QVBoxLayout>
37 
39  : QDialog(parent, f),
40  m_ui(new Ui::DataSourceSelectorDialogForm)
41 {
42 // add controls
43  m_ui->setupUi(this);
44 
45  m_selectorWidget.reset(new DataSourceSelectorWidget(this, f));
46 
47  QVBoxLayout* layout = new QVBoxLayout(this);
48  layout->addWidget(m_selectorWidget.get(), 1);
49  layout->addWidget(m_ui->layoutWidget, 0);
50 
51 // connect signal and slots
52  connect(m_ui->m_selectPushButton, SIGNAL(pressed()), this, SLOT(selectPushButtonPressed()));
53  connect(m_selectorWidget->getForm()->m_datasourceListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(checkButtonsState()));
54  connect(m_selectorWidget->getForm()->m_datasourceListWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectPushButtonPressed()));
55 
56  m_ui->m_helpPushButton->setPageReference("widgets/datasource_selector/datasource_selector.html");
57 }
58 
60 {
61 }
62 
64 {
65  m_selectorWidget.get()->setDataSource(dsType);
66 }
67 
68 const std::list<te::da::DataSourceInfoPtr>& te::qt::widgets::DataSourceSelectorDialog::getSelecteds() const
69 {
70  return m_selecteds;
71 }
72 
74 {
75  return m_selectorWidget.get();
76 }
77 
79 {
80  try
81  {
82  m_selecteds = m_selectorWidget->getSelecteds();
83 
84  if(m_selecteds.empty())
85  throw Exception(TE_TR("There is no selected data sources!"));
86 
87  accept();
88  }
89  catch(const std::exception& e)
90  {
91  QMessageBox::warning(this,
92  tr("TerraLib Qt Components"),
93  tr(e.what()));
94 
95  m_selecteds.clear();
96  }
97  catch(...)
98  {
99  QMessageBox::warning(this,
100  tr("TerraLib Qt Components"),
101  tr("Unknown error while selecting a data source!"));
102 
103  m_selecteds.clear();
104  }
105 }
106 
108 {
109  if(m_selectorWidget.get() == 0)
110  return;
111 
112  bool hasSelectedItems = !m_selectorWidget->getForm()->m_datasourceListWidget->selectedItems().empty();
113 
114  m_ui->m_selectPushButton->setEnabled(hasSelectedItems);
115 }
116 
std::auto_ptr< DataSourceSelectorWidget > m_selectorWidget
std::auto_ptr< Ui::DataSourceSelectorDialogForm > m_ui
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
A dialog for selecting a data source.
A dialog for selecting a data source.
DataSourceSelectorWidget * getSelectorWidget() const
DataSourceSelectorDialog(QWidget *parent=0, Qt::WindowFlags f=0)
const std::list< te::da::DataSourceInfoPtr > & getSelecteds() const
A dialog for selecting a data source.