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 #include "LogTableModel.h"
25 
26 #include <QPalette>
27 #include <QPainter>
28 #include <QTextEdit>
29 #include <QTableView>
30 
31 #include <iostream>
32 #include <algorithm>
33 
34 
35 namespace armarx
36 {
38  QStyledItemDelegate(parent)
39  {
40  // _lineEdit = new QLabel();
41  // _lineEdit->setWordWrap(true);
42  }
43 
45  {
46  // delete _lineEdit;
47  }
48 
49 
50 
51  //void LogMessageDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
52  //{
53 
54  // QString logMessageStr = index.data().toString();
55  // _lineEdit->setText(logMessageStr);
56  // int lines = std::count(logMessageStr.begin(), logMessageStr.end(), '\n')+1;
57  // if(lines > 5)
58  // lines = 5;
59  // QRect rect = option.rect;
60 
61  // rect.setHeight(15*lines);
62  // _lineEdit->resize(rect.size());
63  // std::cout << "lines:" << lines << "old height: " << option.rect.height() << " new: " << rect.height() << " lineedit height: " << _lineEdit->height() << std::endl;
64  // // Change background color if the item is selected
65  // QPalette pal;
66  // if ((option.state & QStyle::State_Selected) == QStyle::State_Selected)
67  // {
68  // pal.setBrush(QPalette::Window, QBrush(QColor(Qt::lightGray)));
69  // }
70  // else
71  // {
72  // pal.setBrush(QPalette::Window, QBrush(QColor(Qt::transparent)));
73  // }
74  // _lineEdit->setPalette(pal);
75 
76  // // Paint the widget now.
77  // painter->save();
78  // painter->translate(option.rect.topLeft());
79  // _lineEdit->render(painter);
80  // painter->restore();
81  //}
82 
83  //QSize LogMessageDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
84  //{
85  // const int width = 350;
86 
87  // const int height = 200;
88  // std::cout << "height: " << _lineEdit->height() << std::endl;
89  // return QSize(width, _lineEdit->height());
90  //}
91 
92  QWidget* LogMessageDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, 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 LogMessageDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
114  {
115  QTextEdit* textEdit = qobject_cast<QTextEdit*>(editor);
116  textEdit->setText(index.data((int)LogTableModel::UserRoles::FullMsgRole).toString());
117 
118  }
119 
120  void LogMessageDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
121  {
122  QRect r = option.rect;
123  r.setX(30); // just for showing the overlay
124  r.setY(10);
125  r.setSize(QSize(700, 300));
126  editor->setGeometry(r);
127  }
128 
130  {
131  emit closeEditor(qobject_cast<QWidget*>(sender()));
132  }
133 }
armarx::LogMessageDelegate::commitAndCloseEditor
void commitAndCloseEditor()
Definition: LogMessageDelegate.cpp:129
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:120
armarx::LogTableModel::UserRoles::FullMsgRole
@ FullMsgRole
armarx::LogMessageDelegate::setEditorData
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Definition: LogMessageDelegate.cpp:113
armarx::LogMessageDelegate::createEditor
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: LogMessageDelegate.cpp:92
LogMessageDelegate.h
armarx::LogMessageDelegate::~LogMessageDelegate
~LogMessageDelegate() override
Definition: LogMessageDelegate.cpp:44
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:28