All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SymbolTableWidget.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/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 <QGridLayout>
33 #include <QHeaderView>
34 #include <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 #if (QT_VERSION >= 0x050000)
47  m_previewTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
48 #else
49  m_previewTable->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
50 #endif
51  m_previewTable->horizontalHeader()->setDefaultSectionSize(m_size.width());
52  m_previewTable->horizontalHeader()->hide();
53 #if (QT_VERSION >= 0x050000)
54  m_previewTable->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
55 #else
56  m_previewTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);
57 #endif
58  m_previewTable->verticalHeader()->setDefaultSectionSize(m_size.height());
59  m_previewTable->setSelectionMode(QAbstractItemView::SingleSelection);
60  m_previewTable->setSelectionBehavior(QAbstractItemView::SelectRows);
61  m_previewTable->setIconSize(m_size);
62 
63  // Adjusting...
64  QGridLayout* layout = new QGridLayout(this);
65  layout->setContentsMargins(0, 0, 0, 0);
66  layout->addWidget(m_previewTable);
67 
68  // Signals & slots
69  connect(m_previewTable, SIGNAL(itemSelectionChanged()), SLOT(onPreviewTableItemSelectionChanged()));
70 }
71 
73 {
74 }
75 
77 {
78  assert(symbol);
79 
80  std::size_t nSymbolizers = symbol->getSymbolizersCount();
81 
82  m_previewTable->setRowCount(nSymbolizers);
83 
84  for(std::size_t i = 0; i < nSymbolizers; ++i)
85  {
86  QTableWidgetItem* item = new QTableWidgetItem(te::qt::widgets::SymbologyPreview::build(symbol->getSymbolizer(i), m_size), "");
87  m_previewTable->setItem(i, 0, item);
88  }
89 }
90 
92 {
93  m_previewTable->selectRow(index);
94 }
95 
97 {
98  return QSize(m_size.width() + m_previewTable->verticalHeader()->size().width(), m_size.height() * 4);
99 }
100 
102 {
103  emit symbolizerClicked(m_previewTable->currentRow());
104 }
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.
std::size_t getSymbolizersCount() const
It returns the number of Symbolizers that compose of the symbol.
Definition: Symbol.cpp:60
Static class used to generate preview of Symbology elements.
QSize sizeHint() const
Return the size hint to this widget.
This class represents a symbol. TODO: More description!
Definition: Symbol.h:54
A widget used to preview a symbol as separated layers.
QTableWidget * m_previewTable
Qt element that will be used to visualize preview results.
void selectSymbolizer(const int &index)
Selects the given index on symbol table layer.
void updatePreview(Symbol *symbol)
Preview a symbol 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...
static QPixmap build(const te::se::Symbolizer *symb, const QSize &size)
Generates the preview of given symbolizer element.