ChartDisplayWidget.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/charts/ChartDisplayWidget.cpp
22 
23  \brief A dialog used to display a set of charts.
24 */
25 
26 //Terralib
27 #include "../../../dataaccess.h"
28 #include "../../../dataaccess/dataset/ObjectIdSet.h"
29 #include "../../../datatype/Property.h"
30 #include "ChartDisplay.h"
31 #include "ChartDisplayWidget.h"
32 #include "ChartProperties.h"
33 #include "ChartStyle.h"
34 #include "Utils.h"
35 #include "ui_ChartDisplayWidgetForm.h"
36 
37 //QT
38 #include <QMessageBox>
39 #include <QFileDialog>
40 
41 //QWT
42 #include <qwt_plot_seriesitem.h>
43 
44 te::qt::widgets::ChartDisplayWidget::ChartDisplayWidget(QwtPlotSeriesItem* chart, int type, te::qt::widgets::ChartDisplay* display, QWidget* parent, Qt::WindowFlags f)
45  : QWidget(parent, f),
46  m_ui(new Ui::ChartDisplayWidgetForm),
47  m_chart(chart),
48  m_type(type),
49  m_display(display)
50 {
51  m_ui->setupUi(this);
52 
53  QGridLayout* layout = new QGridLayout(m_ui->m_plotFrame);
54  layout->addWidget(m_display);
55 
56 // connect signal and slots
57  m_ui->m_exportToolButton->setIcon(QIcon::fromTheme("document-save"));
58 
59  connect(m_ui->m_exportToolButton, SIGNAL(clicked()), this, SLOT(onExportToolButtonnClicked()));
60  connect(m_ui->m_settingsToolButton, SIGNAL(clicked()), this, SLOT(onSettingsToolButtonnClicked()));
61  connect (m_display, SIGNAL(selected(te::da::ObjectIdSet*, const bool&)), SLOT(selectionChanged(te::da::ObjectIdSet*, const bool&)));
62 }
63 
65 {
66  delete m_chart;
67 }
68 
70 {
71  return m_chart;
72 }
73 
74 void te::qt::widgets::ChartDisplayWidget::setChart(QwtPlotSeriesItem* newChart)
75 {
76  m_chart = newChart;
77  m_display->replot();
78 }
79 
81 {
82  return m_display;
83 }
84 
86 {
87  m_display = newDisplay;
88 
89  if(this->parentWidget())
90  this->parentWidget()->setWindowTitle(m_display->getStyle()->getTitle());
91 
92  m_display->replot();
93 }
94 
96 {
97  return m_type;
98 }
99 
101 {
102  m_display->highlightOIds(oids, dataType);
103 }
104 
106 {
107  const QwtPlotItemList& itmList = m_display->itemList();
108 
109  //Iterating over every chart being plotted
110  for (QwtPlotItemIterator it = itmList.begin();
111  it != itmList.end(); ++it)
112  {
113  try
114  {
115  if((m_chart->rtti() != te::qt::widgets::HISTOGRAM_CHART) &&
117  QMessageBox::warning(this, tr("Chart Display"), tr("This function is not supported on this chart type."));
118  else
119  {
120  QString fileName = QFileDialog::getSaveFileName(nullptr, tr("Export chart..."), QString(), tr("CSV (*.csv *.CSV)"));
121 
122  if (!fileName.isEmpty())
123  {
124  QFileInfo info(fileName);
125 
126  if (info.suffix().isEmpty())
127  fileName.append(".csv");
128 
129  te::qt::widgets::exportChart(*it, m_display->getStyle(), fileName.toStdString());
130  }
131  }
132  }
133  catch (te::common::Exception& e)
134  {
135  QMessageBox::warning(this, tr("Chart Display"), e.what());
136  }
137  catch (const std::exception& e)
138  {
139  QMessageBox::warning(this, tr("Chart Display"), e.what());
140  }
141  catch (...)
142  {
143  QMessageBox::warning(this, tr("Chart Display"), tr("Unknown error occurred."));
144  }
145  }
146 }
147 
149 {
150  te::qt::widgets::ChartProperties dlg(this, this->parentWidget());
151  dlg.exec();
152 }
153 
155 {
156  emit selected(oids, add);
157 }
158 
160 {
161  m_display->setSelectionColor(selColor);
162 }
ChartDisplayWidget(QwtPlotSeriesItem *chart, int type, te::qt::widgets::ChartDisplay *display, QWidget *parent=0, Qt::WindowFlags f=0)
Constructor.
A dialog used to customize a graphic&#39;s parameters.
void onSettingsToolButtonnClicked()
Called when the user clicks on the Settings tool button.
QwtPlotSeriesItem * getChart()
Returns a pointer to the chart being displayed.
void setChart(QwtPlotSeriesItem *newChart)
It sets the chart that will be displayed
A class that models the description of a dataset.
Definition: DataSetType.h:72
virtual const char * what() const
It outputs the exception message.
void selected(te::da::ObjectIdSet *, const bool &)
Emmit when objects were selected.
TEQTWIDGETSEXPORT void exportChart(QwtPlotItem *plotItem, te::qt::widgets::ChartStyle *style, std::string filepath)
Function that exports a chart&#39;s data to a .csv file.
QwtPlotSeriesItem * m_chart
The chart that will be plotted by this widget.
void setSelectionColor(QColor selColor)
color used to hgihlight selected objects on this display.
ChartDisplay * m_display
The display that will be used to plot the chart.
QString & getTitle()
Returns a reference to the style&#39;s Title.
Definition: ChartStyle.cpp:66
void highlightOIds(const te::da::ObjectIdSet *oids, te::da::DataSetType *dataType)
Highlights the objects identified by oids.
te::qt::widgets::ChartDisplay * getDisplay()
Returns a pointer to the display being used.
void onExportToolButtonnClicked()
Called when the user clicks on the export tool button.
void selectionChanged(te::da::ObjectIdSet *oids, const bool &add)
Called when objects were selected.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
A class to represent a chart display.
Definition: ChartDisplay.h:65
void setSelectionColor(QColor selColor)
color used to hgihlight selected objects on this display.
int m_type
The type of the chart that will be plotted by this widget.
void highlightOIds(const te::da::ObjectIdSet *oids, te::da::DataSetType *dataType)
Highlights the objects identified by oids.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A widget used to display a set of charts.
A class used to define a chartDisplay&#39;s style.
A dialog used to customize a graphic&#39;s parameters, weather it is about it&#39;s data or it&#39;s visual style...
void setDisplay(te::qt::widgets::ChartDisplay *newDisplay)
It sets the display that will be used
std::unique_ptr< Ui::ChartDisplayWidgetForm > m_ui
The widget form.
te::qt::widgets::ChartStyle * getStyle()
Returns a pointer to the display&#39;s style.
A class to represent a chart display.
This file contains a set of utility chart functions.