All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SymbolTableWidget.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 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/se/SymbolTableWidget.cpp
22 
23  \brief A widget used to preview a symbol as separated layers.
24 */
25 
26 // TerraLib
27 #include "Symbol.h"
28 #include "SymbologyPreview.h"
29 #include "SymbolTableWidget.h"
30 
31 // Qt
32 #include <QtGui/QGridLayout>
33 #include <QtGui/QHeaderView>
34 #include <QtGui/QTableWidget>
35 
36 // STL
37 #include <cassert>
38 
39 te::qt::widgets::SymbolTableWidget::SymbolTableWidget(const QSize& size, QWidget* parent)
40  : QWidget(parent),
41  m_size(size)
42 {
43  // Table preview
44  m_previewTable = new QTableWidget(this);
45  m_previewTable->setColumnCount(1);
46  m_previewTable->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
47  m_previewTable->horizontalHeader()->setDefaultSectionSize(m_size.width());
48  m_previewTable->horizontalHeader()->hide();
49  m_previewTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
50  m_previewTable->verticalHeader()->setDefaultSectionSize(m_size.height());
51  m_previewTable->setSelectionMode(QAbstractItemView::SingleSelection);
52  m_previewTable->setSelectionBehavior(QAbstractItemView::SelectRows);
53  m_previewTable->setIconSize(m_size);
54 
55  // Adjusting...
56  QGridLayout* layout = new QGridLayout(this);
57  layout->setContentsMargins(0, 0, 0, 0);
58  layout->addWidget(m_previewTable);
59 
60  // Signals & slots
61  connect(m_previewTable, SIGNAL(itemSelectionChanged()), SLOT(onPreviewTableItemSelectionChanged()));
62 }
63 
65 {
66 }
67 
69 {
70  assert(symbol);
71 
72  std::size_t nSymbolizers = symbol->getSymbolizersCount();
73 
74  m_previewTable->setRowCount(nSymbolizers);
75 
76  for(std::size_t i = 0; i < nSymbolizers; ++i)
77  {
78  QTableWidgetItem* item = new QTableWidgetItem(te::qt::widgets::SymbologyPreview::build(symbol->getSymbolizer(i), m_size), "");
79  m_previewTable->setItem(i, 0, item);
80  }
81 }
82 
84 {
85  m_previewTable->selectRow(index);
86 }
87 
89 {
90  return QSize(m_size.width() + m_previewTable->verticalHeader()->size().width(), m_size.height() * 4);
91 }
92 
94 {
95  emit symbolizerClicked(m_previewTable->currentRow());
96 }
static QPixmap build(const te::se::Symbolizer *symb, const QSize &size)
Generates the preview of given symbolizer element.
SymbolTableWidget(const QSize &size, QWidget *parent=0)
Constructs a symbol table widget with fixed size, which is a child of parent, with widget flags set t...
te::se::Symbolizer * getSymbolizer(const std::size_t &i) const
It returns the n-th Symbolizer.
Definition: Symbol.cpp:65
This class represents a symbol. TODO: More description!
Definition: Symbol.h:54
A widget used to preview a symbol as separated layers.
void updatePreview(Symbol *symbol)
Preview a symbol element.
void selectSymbolizer(const int &index)
Selects the given index on symbol table layer.
std::size_t getSymbolizersCount() const
It returns the number of Symbolizers that compose of the symbol.
Definition: Symbol.cpp:60
QTableWidget * m_previewTable
Qt element that will be used to visualize preview results.
QSize sizeHint() const
Return the size hint to this widget.
Static class used to generate preview of Symbology elements.
This class represents a symbol.