Merge branch 'work/traceanalyzer_comments' into 'develop'
Add ability to change the text in comments See merge request ems/astdm/dram.sys!298
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
* Janik Schlemminger
|
||||
* Robert Gernhardt
|
||||
* Matthias Jung
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef COMMENT_H
|
||||
@@ -54,6 +55,10 @@ public:
|
||||
{
|
||||
return text;
|
||||
}
|
||||
void changeText(QString newText)
|
||||
{
|
||||
text = newText;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // COMMENT_H
|
||||
|
||||
@@ -33,12 +33,49 @@
|
||||
* Janik Schlemminger
|
||||
* Robert Gernhardt
|
||||
* Matthias Jung
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#include "commenttreewidget.h"
|
||||
#include <QTreeWidgetItem>
|
||||
#include <iostream>
|
||||
#include <QMenu>
|
||||
#include <QKeyEvent>
|
||||
#include <QInputDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
CommentTreeWidget::CommentTreeWidget(QWidget *parent) : QTreeWidget(parent),
|
||||
deleteComment(new QAction("Delete comment", this)),
|
||||
changeCommentText(new QAction("Change comment text", this))
|
||||
{
|
||||
connect(deleteComment, &QAction::triggered, this, [this](){
|
||||
for (QTreeWidgetItem *item : selectedItems())
|
||||
{
|
||||
CommentTreeItem *commentItem = static_cast<CommentTreeItem *>(item);
|
||||
navigator->removeCommentAtTime(commentItem->Time());
|
||||
}
|
||||
});
|
||||
|
||||
connect(changeCommentText, &QAction::triggered, this, [this](){
|
||||
for (QTreeWidgetItem *item : selectedItems())
|
||||
{
|
||||
CommentTreeItem *commentItem = static_cast<CommentTreeItem *>(item);
|
||||
|
||||
bool ok;
|
||||
QString newText = QInputDialog::getText(this, QString("Change comment text"),
|
||||
QString("Change comment text"), QLineEdit::Normal,
|
||||
QString(), &ok);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
deleteComment->trigger();
|
||||
navigator->insertComment({commentItem->Time(), newText});
|
||||
}
|
||||
|
||||
commentsChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void CommentTreeWidget::init(TraceNavigator *navigator)
|
||||
{
|
||||
@@ -54,7 +91,6 @@ void CommentTreeWidget::init(TraceNavigator *navigator)
|
||||
QObject::connect(this, SIGNAL(customContextMenuRequested(QPoint)), this,
|
||||
SLOT(ContextMenuRequested(QPoint)));
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
deleteComment = new QAction("Delete comment", this);
|
||||
printComments();
|
||||
}
|
||||
|
||||
@@ -82,16 +118,9 @@ void CommentTreeWidget::itemDoubleClicked(QTreeWidgetItem *item, int /*column*/)
|
||||
|
||||
void CommentTreeWidget::ContextMenuRequested(QPoint point)
|
||||
{
|
||||
QMenu contextMenu;
|
||||
contextMenu.addActions({deleteComment});
|
||||
QAction *selectedItem = contextMenu.exec(mapToGlobal(point));
|
||||
|
||||
if (selectedItem) {
|
||||
for (QTreeWidgetItem *item : selectedItems()) {
|
||||
CommentTreeItem *commentItem = static_cast<CommentTreeItem *>(item);
|
||||
navigator->removeCommentAtTime(commentItem->Time());
|
||||
}
|
||||
}
|
||||
QMenu contextMenu(this);
|
||||
contextMenu.addActions({deleteComment, changeCommentText});
|
||||
contextMenu.exec(mapToGlobal(point));
|
||||
}
|
||||
|
||||
|
||||
@@ -101,3 +130,13 @@ CommentTreeWidget::CommentTreeItem::CommentTreeItem(QTreeWidget *parent,
|
||||
this->setText(0, prettyFormatTime(comment.Time()));
|
||||
this->setText(1, comment.Text());
|
||||
}
|
||||
|
||||
void CommentTreeWidget::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Delete)
|
||||
deleteComment->trigger();
|
||||
else if (event->key() == Qt::Key_F2)
|
||||
changeCommentText->trigger();
|
||||
|
||||
QTreeWidget::keyPressEvent(event);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
* Janik Schlemminger
|
||||
* Robert Gernhardt
|
||||
* Matthias Jung
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef COMMENTTREEWIDGET_H
|
||||
@@ -48,20 +49,23 @@ class CommentTreeWidget : public QTreeWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CommentTreeWidget(QWidget *parent = 0) : QTreeWidget(parent),
|
||||
isInitialized(false) {}
|
||||
CommentTreeWidget(QWidget *parent = nullptr);
|
||||
void init(TraceNavigator *navigator);
|
||||
|
||||
public Q_SLOTS:
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void commentsChanged();
|
||||
void itemDoubleClicked(QTreeWidgetItem *item, int column);
|
||||
void ContextMenuRequested(QPoint point);
|
||||
void itemDoubleClicked(QTreeWidgetItem *item, int column);
|
||||
|
||||
private:
|
||||
bool isInitialized;
|
||||
bool isInitialized = false;
|
||||
TraceNavigator *navigator;
|
||||
void printComments();
|
||||
QAction *deleteComment;
|
||||
QAction *changeCommentText;
|
||||
|
||||
class CommentTreeItem : public QTreeWidgetItem
|
||||
{
|
||||
@@ -69,10 +73,18 @@ private:
|
||||
Comment comment;
|
||||
public:
|
||||
CommentTreeItem(QTreeWidget *parent, const Comment &comment);
|
||||
QString Text()
|
||||
{
|
||||
return comment.Text();
|
||||
}
|
||||
traceTime Time()
|
||||
{
|
||||
return comment.Time();
|
||||
}
|
||||
void changeText(QString newText)
|
||||
{
|
||||
comment.changeText(newText);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user