LogMessageDelegate.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::
17 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "LogMessageDelegate.h"
24 
25 #include <algorithm>
26 #include <iostream>
27 
28 #include <QPainter>
29 #include <QPalette>
30 #include <QTableView>
31 #include <QTextEdit>
32 
33 #include "LogTableModel.h"
34 
35 namespace armarx
36 {
37  LogMessageDelegate::LogMessageDelegate(QObject* parent) : QStyledItemDelegate(parent)
38  {
39  // _lineEdit = new QLabel();
40  // _lineEdit->setWordWrap(true);
41  }
42 
44  {
45  // delete _lineEdit;
46  }
47 
48  //void LogMessageDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
49  //{
50 
51  // QString logMessageStr = index.data().toString();
52  // _lineEdit->setText(logMessageStr);
53  // int lines = std::count(logMessageStr.begin(), logMessageStr.end(), '\n')+1;
54  // if(lines > 5)
55  // lines = 5;
56  // QRect rect = option.rect;
57 
58  // rect.setHeight(15*lines);
59  // _lineEdit->resize(rect.size());
60  // std::cout << "lines:" << lines << "old height: " << option.rect.height() << " new: " << rect.height() << " lineedit height: " << _lineEdit->height() << std::endl;
61  // // Change background color if the item is selected
62  // QPalette pal;
63  // if ((option.state & QStyle::State_Selected) == QStyle::State_Selected)
64  // {
65  // pal.setBrush(QPalette::Window, QBrush(QColor(Qt::lightGray)));
66  // }
67  // else
68  // {
69  // pal.setBrush(QPalette::Window, QBrush(QColor(Qt::transparent)));
70  // }
71  // _lineEdit->setPalette(pal);
72 
73  // // Paint the widget now.
74  // painter->save();
75  // painter->translate(option.rect.topLeft());
76  // _lineEdit->render(painter);
77  // painter->restore();
78  //}
79 
80  //QSize LogMessageDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
81  //{
82  // const int width = 350;
83 
84  // const int height = 200;
85  // std::cout << "height: " << _lineEdit->height() << std::endl;
86  // return QSize(width, _lineEdit->height());
87  //}
88 
89  QWidget*
91  const QStyleOptionViewItem& option,
92  const QModelIndex& index) const
93  {
94  if (index.column() == 4)
95  {
96  // QTableView* tableView = qobject_cast<QTableView*>(parent);
97  QTextEdit* editor = new QTextEdit(parent);
98  // editor->resize(100,100);
99  editor->adjustSize();
100  editor->setReadOnly(true);
101  // connect(this, SIGNAL(resizeRow(int)),
102  // tableView, SLOT(resizeRowToContents(int)));
103  // emit resizeRow(index.column());
104  // tableView->resizeRowToContents(index.column());
105  return editor;
106  }
107  else
108  {
109  return QStyledItemDelegate::createEditor(parent, option, index);
110  }
111  }
112 
113  void
114  LogMessageDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
115  {
116  QTextEdit* textEdit = qobject_cast<QTextEdit*>(editor);
117  textEdit->setText(index.data((int)LogTableModel::UserRoles::FullMsgRole).toString());
118  }
119 
120  void
122  const QStyleOptionViewItem& option,
123  const QModelIndex& index) const
124  {
125  QRect r = option.rect;
126  r.setX(30); // just for showing the overlay
127  r.setY(10);
128  r.setSize(QSize(700, 300));
129  editor->setGeometry(r);
130  }
131 
132  void
134  {
135  emit closeEditor(qobject_cast<QWidget*>(sender()));
136  }
137 } // namespace armarx
armarx::LogMessageDelegate::commitAndCloseEditor
void commitAndCloseEditor()
Definition: LogMessageDelegate.cpp:133
index
uint8_t index
Definition: EtherCATFrame.h:59
LogTableModel.h
armarx::LogMessageDelegate::updateEditorGeometry
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: LogMessageDelegate.cpp:121
armarx::LogTableModel::UserRoles::FullMsgRole
@ FullMsgRole
armarx::LogMessageDelegate::setEditorData
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Definition: LogMessageDelegate.cpp:114
armarx::LogMessageDelegate::createEditor
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: LogMessageDelegate.cpp:90
LogMessageDelegate.h
armarx::LogMessageDelegate::~LogMessageDelegate
~LogMessageDelegate() override
Definition: LogMessageDelegate.cpp:43
option
#define option(type, fn)
armarx::LogMessageDelegate::LogMessageDelegate
LogMessageDelegate(QObject *parent=0)
Definition: LogMessageDelegate.cpp:37
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27