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 "../../../../core/translator/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  default;
61 
63 {
64  m_selectorWidget.get()->setDataSource(dsType);
65 }
66 
67 const std::list<te::da::DataSourceInfoPtr>& te::qt::widgets::DataSourceSelectorDialog::getSelecteds() const
68 {
69  return m_selecteds;
70 }
71 
73 {
74  return m_selectorWidget.get();
75 }
76 
78 {
79  try
80  {
81  m_selecteds = m_selectorWidget->getSelecteds();
82 
83  if(m_selecteds.empty())
84  throw Exception(TE_TR("There is no selected data sources!"));
85 
86  accept();
87  }
88  catch(const std::exception& e)
89  {
90  QMessageBox::warning(this,
91  tr("TerraLib Qt Components"),
92  tr(e.what()));
93 
94  m_selecteds.clear();
95  }
96  catch(...)
97  {
98  QMessageBox::warning(this,
99  tr("TerraLib Qt Components"),
100  tr("Unknown error while selecting a data source!"));
101 
102  m_selecteds.clear();
103  }
104 }
105 
107 {
108  if(m_selectorWidget.get() == nullptr)
109  return;
110 
111  bool hasSelectedItems = !m_selectorWidget->getForm()->m_datasourceListWidget->selectedItems().empty();
112 
113  m_ui->m_selectPushButton->setEnabled(hasSelectedItems);
114 }
115 
Base exception class for plugin module.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
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)
std::unique_ptr< DataSourceSelectorWidget > m_selectorWidget
const std::list< te::da::DataSourceInfoPtr > & getSelecteds() const
std::unique_ptr< Ui::DataSourceSelectorDialogForm > m_ui
std::list< te::da::DataSourceInfoPtr > m_selecteds
A dialog for selecting a data source.