All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OrderByWidget.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/query/OrderByWidget.cpp
22 
23  \brief This file has the OrderByWidget class.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/query/OrderByItem.h"
28 #include "../../../dataaccess/query/PropertyName.h"
29 #include "OrderByWidget.h"
30 #include "ui_OrderByWidgetForm.h"
31 
32 
33 // Qt
34 #include <QIcon>
35 #include <QMessageBox>
36 
37 te::qt::widgets::OrderByWidget::OrderByWidget(QWidget* parent, Qt::WindowFlags f)
38  : QWidget(parent, f),
39  m_ui(new Ui::OrderByWidgetForm)
40 {
41  m_ui->setupUi(this);
42 
43  //set order types
44  m_orderTypes.insert(std::map<std::string, int>::value_type(tr("ASC").toStdString(), te::da::ASC));
45  m_orderTypes.insert(std::map<std::string, int>::value_type(tr("DESC").toStdString(), te::da::DESC));
46 
47  std::map<std::string, int>::iterator it = m_orderTypes.begin();
48 
49  while(it != m_orderTypes.end())
50  {
51  m_ui->m_orderComboBox->addItem(it->first.c_str());
52 
53  ++it;
54  }
55 
56  // set icons
57  m_ui->m_addOrderPushButton->setIcon(QIcon::fromTheme("list-add"));
58  m_ui->m_removeOrderPushButton->setIcon(QIcon::fromTheme("list-remove"));
59 
60  //connects
61  connect(m_ui->m_addOrderPushButton, SIGNAL(clicked()), this, SLOT(onAddOrderPushButton()));
62  connect(m_ui->m_removeOrderPushButton, SIGNAL(clicked()), this, SLOT(onRemoveOrderPushButton()));
63 }
64 
66 {
67 }
68 
69 Ui::OrderByWidgetForm* te::qt::widgets::OrderByWidget::getForm() const
70 {
71  return m_ui.get();
72 }
73 
75 {
76  std::vector<std::pair<std::string, std::string> > vec;
77 
78  getOrderItems(vec);
79 
80  if(vec.empty())
81  return 0;
82 
83  te::da::OrderBy* order = new te::da::OrderBy;
84 
85  for(size_t t = 0; t < vec.size(); ++t)
86  {
87  std::map<std::string, int>::iterator it = m_orderTypes.find(vec[t].second);
88 
89  if(it != m_orderTypes.end())
90  {
91  te::da::OrderByItem* o = new te::da::OrderByItem(vec[t].first, (te::da::SortOrder)it->second);
92 
93  order->push_back(o);
94  }
95  }
96 
97  return order;
98 }
99 
100 void te::qt::widgets::OrderByWidget::setAttributeList(const std::vector<std::string>& vec)
101 {
102  m_ui->m_orderPropertyComboBox->clear();
103 
104  for(size_t t = 0; t <vec.size(); ++t)
105  {
106  m_ui->m_orderPropertyComboBox->addItem(vec[t].c_str());
107  }
108 }
109 
110 void te::qt::widgets::OrderByWidget::getOrderItems(std::vector<std::pair<std::string, std::string> >& list)
111 {
112  int row = m_ui->m_orderTableWidget->rowCount();
113 
114  //get properties for each data set
115  for(int i = 0; i < row; ++i)
116  {
117  //alias name
118  QTableWidgetItem* itemType = m_ui->m_orderTableWidget->item(i, 1);
119  std::string type = itemType->text().toStdString();
120 
121  //data set name
122  QTableWidgetItem* itemName = m_ui->m_orderTableWidget->item(i, 0);
123  std::string name = itemName->text().toStdString();
124 
125  list.push_back(std::pair<std::string, std::string> (name, type));
126  }
127 }
128 
130 {
131  if(m_ui->m_orderPropertyComboBox->currentText().isEmpty())
132  {
133  QMessageBox::warning(this, tr("Query Builder"), tr("Property value not defined."));
134  return;
135  }
136 
137  int newrow = m_ui->m_orderTableWidget->rowCount();
138 
139  std::string propertyValue = m_ui->m_orderPropertyComboBox->currentText().toStdString();
140  std::string order = m_ui->m_orderComboBox->currentText().toStdString();
141 
142 //new entry
143  m_ui->m_orderTableWidget->insertRow(newrow);
144 
145  QTableWidgetItem* itemProperty = new QTableWidgetItem(QString::fromStdString(propertyValue));
146  m_ui->m_orderTableWidget->setItem(newrow, 0, itemProperty);
147 
148  QTableWidgetItem* itemOrder = new QTableWidgetItem(QString::fromStdString(order));
149  m_ui->m_orderTableWidget->setItem(newrow, 1, itemOrder);
150 
151  m_ui->m_orderTableWidget->resizeColumnsToContents();
152 }
153 
155 {
156  int row = m_ui->m_orderTableWidget->currentRow();
157 
158  if(row >= 0)
159  m_ui->m_orderTableWidget->removeRow(row);
160 
161  m_ui->m_orderTableWidget->resizeColumnsToContents();
162 }
OrderByWidget(QWidget *parent=0, Qt::WindowFlags f=0)
boost::ptr_vector< OrderByItem > OrderBy
A class that can be used to model an ORDER BY clause.
Definition: OrderBy.h:37
Ui::OrderByWidgetForm * getForm() const
std::map< std::string, int > m_orderTypes
Definition: OrderByWidget.h:89
This file has the OrderByWidget class.
SortOrder
Sort order type: asc or desc.
Definition: Enums.h:38
std::auto_ptr< Ui::OrderByWidgetForm > m_ui
Definition: OrderByWidget.h:87
te::da::OrderBy * gerOrderBy()
void getOrderItems(std::vector< std::pair< std::string, std::string > > &list)
A class that can be used in an ORDER BY clause to sort the items of a resulting query.
Definition: OrderByItem.h:53
void setAttributeList(const std::vector< std::string > &vec)