EditedDelegate.cpp
Go to the documentation of this file.
1 #include "EditedDelegate.h"
2 
3 #include "../../../core/utils/Platform.h"
4 #include "../../widgets/layer/explorer/LayerItem.h"
5 
6 #include <QPainter>
7 
8 
9 QPainterPath GetStar()
10 {
11  QPainterPath star, aux;
12 
13  aux.setFillRule(Qt::WindingFill);
14 
15  aux.moveTo(1.0, 0.5);
16  for(int i = 1; i < 5; ++i)
17  {
18  QPointF pt(0.5 + 0.5 * cos(0.8 * i * 3.14),
19  0.5 + 0.5 * sin(0.8 * i * 3.14));
20  aux.lineTo(pt);
21  star = aux.simplified();
22  }
23 
24  return star;
25 }
26 
27 QPainterPath RecalculateMark(const QPainterPath& markShape, const int& markSize)
28 {
29  QMatrix m;
30  m.scale(markSize*2, markSize*2);
31 
32  return m.map(markShape);
33 }
34 
35 QImage GetStarImage(const QSize& size, const QColor& c)
36 {
37  QImage img(size, QImage::Format_ARGB32_Premultiplied);
38 
39  img.fill(Qt::color0);
40 
41  QPainter p(&img);
42  QPainterPath star = GetStar();
43  star = RecalculateMark(star, size.height()/2);
44 
45  p.translate(img.rect().center()-star.boundingRect().center());
46 
47  p.fillPath(star, Qt::color1);
48  p.setPen(QPen(Qt::color1, 1));
49  p.drawPath(star);
50 
51  p.fillPath(star, c);
52  p.setPen(QPen(Qt::black, 1));
53  p.drawPath(star);
54 
55  return img;
56 }
57 
58 QIcon GetIcon(const bool& stash)
59 {
60  QPixmap p1 = QIcon::fromTheme("dataset-layer").pixmap(20, 20);
61  QPixmap p2;
62 
63  if(stash)
64  p2 = QPixmap(te::core::FindInTerraLibPath("resources/images/png/stash.png").c_str()).scaled(15, 15, Qt::KeepAspectRatio);
65  else
66  p2 = QPixmap(te::core::FindInTerraLibPath("resources/images/png/mem_edit.png").c_str()).scaled(15, 15, Qt::KeepAspectRatio);
67 
68  QPainter pt(&p1);
69 
70  pt.drawPixmap(5, 5, p2);
71 
72  pt.end();
73 
74  return p1;
75 }
76 
77 
78 EditDelegate::EditDelegate(QStyledItemDelegate* decorated, QObject* parent) :
79  te::common::Decorator<QStyledItemDelegate>(decorated)
80 {
81  setParent(parent);
82 
83  m_stash = GetIcon(true);
84  m_memory = GetIcon(false);
85 }
86 
87 EditDelegate::~EditDelegate() = default;
88 
89 void EditDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
90 {
91  te::qt::widgets::TreeItem* item = static_cast<te::qt::widgets::TreeItem*>(index.internalPointer());
92  QStyleOptionViewItem opt(option);
93 
94  if(item->getType() == "LAYER")
95  {
97 
98  if (l->getType() == "DATASETLAYER")
99  {
100  if (m_stashed.find(l->getTitle()) != m_stashed.end())
101  {
102 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
103  opt.icon = m_stash;
104 #endif
105  opt.palette.setColor(QPalette::Text, Qt::green);
106  opt.font.setItalic(true);
107  opt.font.setBold(true);
108  }
109  else if (m_edited.find(l->getTitle()) != m_edited.end())
110  {
111 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
112  opt.icon = m_memory;
113 #endif
114  opt.palette.setColor(QPalette::Text, Qt::red);
115  opt.font.setItalic(true);
116  opt.font.setBold(true);
117  }
118  }
119  }
120 
121  if(m_decorated != nullptr)
122  m_decorated->paint(painter, opt, index);
123  else
124  QStyledItemDelegate::paint(painter, opt, index);
125 }
126 
127 void EditDelegate::addStashed(const std::string& lName)
128 {
129  m_stashed.insert(lName);
130  removeEdited(lName);
131 }
132 
133 void EditDelegate::removeStashed(const std::string& lName)
134 {
135  m_stashed.erase(lName);
136 }
137 
138 void EditDelegate::addEdited(const std::string& lName)
139 {
140  m_edited.insert(lName);
141  removeStashed(lName);
142 }
143 
144 void EditDelegate::removeEdited(const std::string& lName)
145 {
146  m_edited.erase(lName);
147 }
148 
149 bool EditDelegate::isStached(const std::string& lName)
150 {
151  return (m_stashed.find(lName) != m_stashed.end());
152 }
std::set< std::string > m_edited
QImage GetStarImage(const QSize &size, const QColor &c)
QPainterPath GetStar()
QIcon GetIcon(const bool &stash)
An item that contains a te::map::AbstractLayerPtr.
Definition: LayerItem.h:51
std::set< std::string > m_stashed
QPainterPath RecalculateMark(const QPainterPath &markShape, const int &markSize)
Defines a hierarchical structure.
QStyledItemDelegate * m_decorated
The object decorated.
Definition: Decorator.h:98
URI C++ Library.
Definition: Attributes.h:37
void addEdited(const std::string &lName)
te::gm::Polygon * p
void addStashed(const std::string &lName)
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.
EditDelegate(QStyledItemDelegate *decorated, QObject *parent=0)
void removeStashed(const std::string &lName)
bool isStached(const std::string &lName)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void removeEdited(const std::string &lName)
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
std::string getType() const
Returns the type of the item.
void paint(te::qt::widgets::Canvas *c, bool generatePNG, std::string fileName)