All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TextGridItem.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 TextGridItem.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "TextGridItem.h"
30 #include "../../core/pattern/mvc/ItemController.h"
31 #include "../../core/AbstractScene.h"
32 #include "../../core/pattern/mvc/Observable.h"
33 #include "../../../color/RGBAColor.h"
34 #include "../../../qt/widgets/Utils.h"
35 #include "../../../geometry/Envelope.h"
36 #include "../../../common/STLUtils.h"
37 #include "../../item/TextGridModel.h"
38 #include "../../core/pattern/singleton/Context.h"
39 
40 // Qt
41 #include <QTextDocument>
42 #include <QTextCursor>
43 #include <QTextTableCell>
44 
46  TitleItem(controller, o)
47 {
48  init();
49 }
50 
52 {
53 
54 }
55 
57 {
58  TitleModel* model = dynamic_cast<TitleModel*>(m_model);
59 
60  if(!model)
61  return;
62 
63  updateDocument();
64 
65  resetEdit();
66 }
67 
69 {
70  if(!m_model)
71  return;
72 
73  TitleModel* model = dynamic_cast<TitleModel*>(m_model);
74 
75  if(!model)
76  return;
77 
78  QImage img = createImage();
79  QPointF pp = scenePos();
80  te::gm::Envelope box(pp.x(), pp.y(), pp.x() + img.widthMM(), pp.y() + img.heightMM());
81 
82  model->setBox(box);
83 
84  // Update Model
85  int countRows = m_table->rows();
86  int countColumns = m_table->columns();
87 
88  //Table Headers (Hrz)
89  for(int i = 1 ; i < countRows ; ++i)
90  {
91  QTextTableCell cellOne = m_table->cellAt(i, 0);
92  QTextCursor cellCursorOne = cellOne.firstCursorPosition();
93  std::string txtOne = cellCursorOne.block().text().toStdString();
94  //model->setTitle(txtOne);
95  }
96 
97  //Table Headers (Vrt)
98  for(int j = 0 ; j < countColumns ; ++j)
99  {
100  QTextTableCell cellTwo = m_table->cellAt(0, j);
101  QTextCursor cellCursorTwo = cellTwo.firstCursorPosition();
102  std::string txtTwo = cellCursorTwo.block().text().toStdString();
103  //model->setText(txtTwo);
104  }
105 
106  //Table
107  for (int i = 1 ; i < countRows ; ++i)
108  {
109  for(int j = 1 ; j < countColumns ; ++j)
110  {
111  QTextTableCell cellThree = m_table->cellAt(i, j);
112  QTextCursor cellCursorThree = cellThree.firstCursorPosition();
113  std::string txtThree = cellCursorThree.block().text().toStdString();
114  //model->setText(txtThree);
115  }
116  }
117 }
118 
120 {
121  TextGridModel* model = dynamic_cast<TextGridModel*>(m_model);
122 
123  if(!model)
124  return;
125 
126  document()->clear();
127 
128  QTextDocument* doc = document();
129 
130  QTextCursor cursor(doc);
131  cursor.movePosition(QTextCursor::Start);
132 
133  QBrush blackBrush(Qt::SolidPattern);
134 
135  QTextTableFormat tableFormat;
136  tableFormat.setAlignment(Qt::AlignLeft);
137  tableFormat.setBorderBrush(blackBrush);
138  tableFormat.setBorder(0.5);
139 
140  int columns = model->getNumberColumns();
141  int rows = model->getNumberRows();
142 
143  tableFormat.setCellSpacing(3);
144  tableFormat.setCellPadding(3);
145  tableFormat.setHeaderRowCount(1);
146 
147  m_table = cursor.insertTable(rows, columns, tableFormat);
148 
149  int countRows = m_table->rows();
150  int countColumns = m_table->columns();
151 
152  //Table Headers (Hrz)
153  for(int i = 1 ; i < countRows ; ++i)
154  {
155  QTextTableCell cellOne = m_table->cellAt(i, 0);
156  QTextCharFormat fmtOne = cellOne.format();
157  fmtOne.setBackground(Qt::gray);
158  fmtOne.setFontWeight(QFont::Bold);
159  cellOne.setFormat(fmtOne);
160  }
161 
162  //Table Headers (Vrt)
163  for(int j = 0 ; j < countColumns ; ++j)
164  {
165  QTextTableCell cellTwo = m_table->cellAt(0, j);
166  QTextCharFormat fmtTwo = cellTwo.format();
167  fmtTwo.setBackground(Qt::gray);
168  fmtTwo.setFontWeight(QFont::Bold);
169  cellTwo.setFormat(fmtTwo);
170  }
171 }
Abstract class to represent an observable. "Model" part of MVC component.
Definition: Observable.h:56
virtual int getNumberColumns()
Definition: TitleModel.cpp:304
virtual void refreshDocument()
Abstract class to represent a controller. "Controller" part of MVC component. All classes representin...
Class that represents a "Model" part of TextGrid MVC component. Its coordinate system is the same of ...
Definition: TextGridModel.h:55
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
virtual int getNumberRows()
Definition: TitleModel.cpp:314
virtual void updateDocument()
Class that represents a "Model" part of Title MVC component. Its coordinate system is the same of sce...
Definition: TitleModel.h:52
Class daughter of te::layout::TextItem representing a grid with two cells which can be inserted texts...
Definition: TitleItem.h:48
Class daughter of te::layout::TitleItem representing a grid with cells which can be inserted texts...
virtual ~TextGridItem()
Destructor.
virtual void setBox(te::gm::Envelope box)
Change the bounding rectangle.
TextGridItem(ItemController *controller, Observable *o)
Constructor.