mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-21 12:26:11 +00:00
Refactor CommentsWidget to use Model/View architecture (#469)
Add QuickFilter panel to CommentsWidget
This commit is contained in:
parent
f5f2c4702e
commit
41d2fdc690
@ -1,12 +1,229 @@
|
|||||||
#include <QTreeWidget>
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "CommentsWidget.h"
|
#include "CommentsWidget.h"
|
||||||
#include "ui_CommentsWidget.h"
|
#include "ui_CommentsWidget.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "utils/Helpers.h"
|
#include "utils/Helpers.h"
|
||||||
|
|
||||||
|
CommentsModel::CommentsModel(QList<CommentDescription> *comments,
|
||||||
|
QMap<QString, QList<CommentDescription> > *nestedComments,
|
||||||
|
QObject *parent)
|
||||||
|
: QAbstractItemModel(parent),
|
||||||
|
comments(comments),
|
||||||
|
nestedComments(nestedComments),
|
||||||
|
nested(false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool CommentsModel::isNested() const
|
||||||
|
{
|
||||||
|
return nested;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommentsModel::setNested(bool nested)
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
this->nested = nested;
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex CommentsModel::index(int row, int column, const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
if (!parent.isValid())
|
||||||
|
return createIndex(row, column, (quintptr)0);
|
||||||
|
|
||||||
|
return createIndex(row, column, (quintptr)(parent.row() + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex CommentsModel::parent(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
/* Ignore invalid indexes and root nodes */
|
||||||
|
if (!index.isValid() || index.internalId() == 0)
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
|
return this->index((int)(index.internalId() - 1), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int CommentsModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
if (!parent.isValid())
|
||||||
|
return (isNested() ? nestedComments->size() : comments->count());
|
||||||
|
|
||||||
|
if (isNested() && parent.internalId() == 0) {
|
||||||
|
QString fcnName = nestedComments->keys().at(parent.row());
|
||||||
|
return nestedComments->operator[](fcnName).size();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CommentsModel::columnCount(const QModelIndex&) const
|
||||||
|
{
|
||||||
|
return (isNested() ? CommentsModel::NestedColumnCount : CommentsModel::ColumnCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant CommentsModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (!index.isValid() || (index.internalId() != 0 && !index.parent().isValid()))
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
int commentIndex;
|
||||||
|
bool isSubnode;
|
||||||
|
if (index.internalId() != 0) {
|
||||||
|
/* Subnode */
|
||||||
|
commentIndex = index.parent().row();
|
||||||
|
isSubnode = true;
|
||||||
|
} else {
|
||||||
|
/* Root node */
|
||||||
|
commentIndex = index.row();
|
||||||
|
isSubnode = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString offset;
|
||||||
|
CommentDescription comment;
|
||||||
|
if (isNested()) {
|
||||||
|
offset = nestedComments->keys().at(commentIndex);
|
||||||
|
if (isSubnode) {
|
||||||
|
comment = nestedComments->operator[](offset).at(index.row());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
comment = comments->at(commentIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (role)
|
||||||
|
{
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
if (isNested()) {
|
||||||
|
if (isSubnode) {
|
||||||
|
switch (index.column()) {
|
||||||
|
case OffsetNestedColumn:
|
||||||
|
return RAddressString(comment.offset);
|
||||||
|
case CommentNestedColumn:
|
||||||
|
return comment.name;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (index.column() == OffsetNestedColumn) {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (index.column()) {
|
||||||
|
case CommentsModel::OffsetColumn:
|
||||||
|
return RAddressString(comment.offset);
|
||||||
|
case CommentsModel::FunctionColumn:
|
||||||
|
return Core()->cmdFunctionAt(comment.offset);
|
||||||
|
case CommentsModel::CommentColumn:
|
||||||
|
return comment.name;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CommentsModel::CommentDescriptionRole:
|
||||||
|
if (isNested() && index.internalId() == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return QVariant::fromValue(comment);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant CommentsModel::headerData(int section, Qt::Orientation, int role) const
|
||||||
|
{
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
if (isNested()) {
|
||||||
|
switch (section) {
|
||||||
|
case CommentsModel::OffsetNestedColumn:
|
||||||
|
return tr("Function/Offset");
|
||||||
|
case CommentsModel::CommentNestedColumn:
|
||||||
|
return tr("Comment");
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (section) {
|
||||||
|
case CommentsModel::OffsetColumn:
|
||||||
|
return tr("Offset");
|
||||||
|
case CommentsModel::FunctionColumn:
|
||||||
|
return tr("Function");
|
||||||
|
case CommentsModel::CommentColumn:
|
||||||
|
return tr("Comment");
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommentsModel::beginReloadComments()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommentsModel::endReloadComments()
|
||||||
|
{
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
CommentsProxyModel::CommentsProxyModel(CommentsModel *sourceModel, QObject *parent)
|
||||||
|
: QSortFilterProxyModel(parent)
|
||||||
|
{
|
||||||
|
setSourceModel(sourceModel);
|
||||||
|
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CommentsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
CommentsModel *srcModel = static_cast<CommentsModel *>(sourceModel());
|
||||||
|
if (srcModel->isNested()) {
|
||||||
|
// Disable filtering
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex index = sourceModel()->index(row, 0, parent);
|
||||||
|
auto comment = index.data(CommentsModel::CommentDescriptionRole).value<CommentDescription>();
|
||||||
|
|
||||||
|
return comment.name.contains(filterRegExp());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CommentsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||||
|
{
|
||||||
|
CommentsModel *srcModel = static_cast<CommentsModel *>(sourceModel());
|
||||||
|
if (srcModel->isNested()) {
|
||||||
|
// Disable sorting
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!left.isValid() || !right.isValid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (left.parent().isValid() || right.parent().isValid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto leftComment = left.data(CommentsModel::CommentDescriptionRole).value<CommentDescription>();
|
||||||
|
auto rightComment = right.data(CommentsModel::CommentDescriptionRole).value<CommentDescription>();
|
||||||
|
|
||||||
|
switch (left.column()) {
|
||||||
|
case CommentsModel::OffsetColumn:
|
||||||
|
return leftComment.offset < rightComment.offset;
|
||||||
|
case CommentsModel::FunctionColumn:
|
||||||
|
return Core()->cmdFunctionAt(leftComment.offset) < Core()->cmdFunctionAt(rightComment.offset);
|
||||||
|
case CommentsModel::CommentColumn:
|
||||||
|
return leftComment.name < rightComment.name;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
CommentsWidget::CommentsWidget(MainWindow *main, QAction *action) :
|
CommentsWidget::CommentsWidget(MainWindow *main, QAction *action) :
|
||||||
CutterDockWidget(main, action),
|
CutterDockWidget(main, action),
|
||||||
ui(new Ui::CommentsWidget),
|
ui(new Ui::CommentsWidget),
|
||||||
@ -14,13 +231,27 @@ CommentsWidget::CommentsWidget(MainWindow *main, QAction *action) :
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
ui->commentsTreeWidget->sortByColumn(2, Qt::AscendingOrder);
|
commentsModel = new CommentsModel(&comments, &nestedComments, this);
|
||||||
|
commentsProxyModel = new CommentsProxyModel(commentsModel, this);
|
||||||
|
ui->commentsTreeView->setModel(commentsProxyModel);
|
||||||
|
ui->commentsTreeView->sortByColumn(CommentsModel::CommentColumn, Qt::AscendingOrder);
|
||||||
|
|
||||||
QTabBar *tabs = ui->tabWidget->tabBar();
|
// Ctrl-F to show/hide the filter entry
|
||||||
tabs->setVisible(false);
|
QShortcut *searchShortcut = new QShortcut(QKeySequence::Find, this);
|
||||||
|
connect(searchShortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::showFilter);
|
||||||
|
searchShortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
||||||
|
|
||||||
|
// Esc to clear the filter entry
|
||||||
|
QShortcut *clearShortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
||||||
|
connect(clearShortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::clearFilter);
|
||||||
|
clearShortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
||||||
|
|
||||||
|
connect(ui->quickFilterView, SIGNAL(filterTextChanged(const QString &)),
|
||||||
|
commentsProxyModel, SLOT(setFilterWildcard(const QString &)));
|
||||||
|
connect(ui->quickFilterView, SIGNAL(filterClosed()), ui->commentsTreeView, SLOT(setFocus()));
|
||||||
|
|
||||||
|
setScrollMode();
|
||||||
|
|
||||||
// Use a custom context menu on the dock title bar
|
|
||||||
//this->title_bar = this->titleBarWidget();
|
|
||||||
ui->actionHorizontal->setChecked(true);
|
ui->actionHorizontal->setChecked(true);
|
||||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
|
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
|
||||||
@ -28,47 +259,32 @@ CommentsWidget::CommentsWidget(MainWindow *main, QAction *action) :
|
|||||||
|
|
||||||
connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshTree()));
|
connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshTree()));
|
||||||
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshTree()));
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshTree()));
|
||||||
|
|
||||||
// Hide the buttons frame
|
|
||||||
ui->frame->hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CommentsWidget::~CommentsWidget() {}
|
CommentsWidget::~CommentsWidget() {}
|
||||||
|
|
||||||
void CommentsWidget::on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
void CommentsWidget::on_commentsTreeView_doubleClicked(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
if (column < 0)
|
if (!index.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Get offset and name of item double clicked
|
if (commentsModel->isNested() && !index.parent().isValid())
|
||||||
CommentDescription comment = item->data(0, Qt::UserRole).value<CommentDescription>();
|
return;
|
||||||
|
|
||||||
|
auto comment = index.data(CommentsModel::CommentDescriptionRole).value<CommentDescription>();
|
||||||
Core()->seek(comment.offset);
|
Core()->seek(comment.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommentsWidget::on_nestedCmtsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
void CommentsWidget::on_actionHorizontal_triggered()
|
||||||
{
|
{
|
||||||
if (column < 0)
|
commentsModel->setNested(false);
|
||||||
return;
|
ui->commentsTreeView->setIndentation(8);
|
||||||
|
|
||||||
// don't react on top-level items
|
|
||||||
if (item->parent() == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get offset and name of item double clicked
|
|
||||||
CommentDescription comment = item->data(0, Qt::UserRole).value<CommentDescription>();
|
|
||||||
Core()->seek(comment.offset);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommentsWidget::on_toolButton_clicked()
|
void CommentsWidget::on_actionVertical_triggered()
|
||||||
{
|
{
|
||||||
ui->tabWidget->setCurrentIndex(0);
|
commentsModel->setNested(true);
|
||||||
}
|
ui->commentsTreeView->setIndentation(20);
|
||||||
|
|
||||||
void CommentsWidget::on_toolButton_2_clicked()
|
|
||||||
{
|
|
||||||
ui->tabWidget->setCurrentIndex(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommentsWidget::showTitleContextMenu(const QPoint &pt)
|
void CommentsWidget::showTitleContextMenu(const QPoint &pt)
|
||||||
@ -79,7 +295,7 @@ void CommentsWidget::showTitleContextMenu(const QPoint &pt)
|
|||||||
menu->addAction(ui->actionHorizontal);
|
menu->addAction(ui->actionHorizontal);
|
||||||
menu->addAction(ui->actionVertical);
|
menu->addAction(ui->actionVertical);
|
||||||
|
|
||||||
if (ui->tabWidget->currentIndex() == 0) {
|
if (!commentsModel->isNested()) {
|
||||||
ui->actionHorizontal->setChecked(true);
|
ui->actionHorizontal->setChecked(true);
|
||||||
ui->actionVertical->setChecked(false);
|
ui->actionVertical->setChecked(false);
|
||||||
} else {
|
} else {
|
||||||
@ -93,18 +309,6 @@ void CommentsWidget::showTitleContextMenu(const QPoint &pt)
|
|||||||
delete menu;
|
delete menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommentsWidget::on_actionHorizontal_triggered()
|
|
||||||
{
|
|
||||||
ui->tabWidget->setCurrentIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommentsWidget::on_actionVertical_triggered()
|
|
||||||
{
|
|
||||||
ui->tabWidget->setCurrentIndex(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CommentsWidget::resizeEvent(QResizeEvent *event)
|
void CommentsWidget::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
if (main->responsive && isVisible()) {
|
if (main->responsive && isVisible()) {
|
||||||
@ -119,61 +323,23 @@ void CommentsWidget::resizeEvent(QResizeEvent *event)
|
|||||||
QDockWidget::resizeEvent(event);
|
QDockWidget::resizeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
QMap<QString, QList<QList<QString>>> CutterCore::getNestedComments()
|
|
||||||
{
|
|
||||||
QMap<QString, QList<QList<QString>>> ret;
|
|
||||||
QString comments = cmd("CC~CCu");
|
|
||||||
|
|
||||||
for (QString line : comments.split("\n"))
|
|
||||||
{
|
|
||||||
QStringList fields = line.split("CCu");
|
|
||||||
if (fields.length() == 2)
|
|
||||||
{
|
|
||||||
QList<QString> tmp = QList<QString>();
|
|
||||||
tmp << fields[1].split("\"")[1].trimmed();
|
|
||||||
tmp << fields[0].trimmed();
|
|
||||||
QString fcn_name = this->cmdFunctionAt(fields[0].trimmed());
|
|
||||||
ret[fcn_name].append(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void CommentsWidget::refreshTree()
|
void CommentsWidget::refreshTree()
|
||||||
{
|
{
|
||||||
ui->nestedCmtsTreeWidget->clear();
|
commentsModel->beginReloadComments();
|
||||||
QList<CommentDescription> comments = Core()->getAllComments("CCu");
|
|
||||||
QMap<QString, QList<CommentDescription>> nestedComments;
|
|
||||||
|
|
||||||
|
comments = Core()->getAllComments("CCu");
|
||||||
|
nestedComments.clear();
|
||||||
for (CommentDescription comment : comments) {
|
for (CommentDescription comment : comments) {
|
||||||
QString fcn_name = Core()->cmdFunctionAt(comment.offset);
|
QString fcnName = Core()->cmdFunctionAt(comment.offset);
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
nestedComments[fcnName].append(comment);
|
||||||
item->setText(0, RAddressString(comment.offset));
|
|
||||||
item->setText(1, fcn_name);
|
|
||||||
item->setText(2, comment.name);
|
|
||||||
item->setData(0, Qt::UserRole, QVariant::fromValue(comment));
|
|
||||||
ui->commentsTreeWidget->addTopLevelItem(item);
|
|
||||||
|
|
||||||
nestedComments[fcn_name].append(comment);
|
|
||||||
}
|
}
|
||||||
qhelpers::adjustColumns(ui->commentsTreeWidget, 0);
|
|
||||||
|
|
||||||
// Add nested comments
|
commentsModel->endReloadComments();
|
||||||
ui->nestedCmtsTreeWidget->clear();
|
|
||||||
for (auto functionName : nestedComments.keys()) {
|
qhelpers::adjustColumns(ui->commentsTreeView, 3, 0);
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem(ui->nestedCmtsTreeWidget);
|
}
|
||||||
item->setText(0, functionName);
|
|
||||||
for (CommentDescription comment : nestedComments.value(functionName)) {
|
void CommentsWidget::setScrollMode()
|
||||||
QTreeWidgetItem *it = new QTreeWidgetItem();
|
{
|
||||||
it->setText(0, RAddressString(comment.offset));
|
qhelpers::setVerticalScrollMode(ui->commentsTreeView);
|
||||||
it->setText(1, comment.name);
|
|
||||||
it->setData(0, Qt::UserRole, QVariant::fromValue(comment));
|
|
||||||
item->addChild(it);
|
|
||||||
}
|
|
||||||
ui->nestedCmtsTreeWidget->addTopLevelItem(item);
|
|
||||||
}
|
|
||||||
qhelpers::adjustColumns(ui->nestedCmtsTreeWidget, 0);
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
#define COMMENTSWIDGET_H
|
#define COMMENTSWIDGET_H
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
#include "Cutter.h"
|
||||||
#include "CutterDockWidget.h"
|
#include "CutterDockWidget.h"
|
||||||
|
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
@ -12,6 +15,51 @@ namespace Ui {
|
|||||||
class CommentsWidget;
|
class CommentsWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CommentsModel : public QAbstractItemModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<CommentDescription> *comments;
|
||||||
|
QMap<QString, QList<CommentDescription>> *nestedComments;
|
||||||
|
bool nested;
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum Column { OffsetColumn = 0, FunctionColumn, CommentColumn, ColumnCount };
|
||||||
|
enum NestedColumn { OffsetNestedColumn = 0, CommentNestedColumn, NestedColumnCount };
|
||||||
|
enum Role { CommentDescriptionRole = Qt::UserRole, FunctionRole };
|
||||||
|
|
||||||
|
CommentsModel(QList<CommentDescription> *comments, QMap<QString, QList<CommentDescription>> *nestedComments,
|
||||||
|
QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
QModelIndex parent(const QModelIndex &index) const;
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
|
||||||
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
void beginReloadComments();
|
||||||
|
void endReloadComments();
|
||||||
|
|
||||||
|
bool isNested() const;
|
||||||
|
void setNested(bool nested);
|
||||||
|
};
|
||||||
|
|
||||||
|
class CommentsProxyModel : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
CommentsProxyModel(CommentsModel *sourceModel, QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool filterAcceptsRow(int row, const QModelIndex &parent) const override;
|
||||||
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
||||||
|
};
|
||||||
|
|
||||||
class CommentsWidget : public CutterDockWidget
|
class CommentsWidget : public CutterDockWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -24,11 +72,7 @@ protected:
|
|||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
|
void on_commentsTreeView_doubleClicked(const QModelIndex &index);
|
||||||
void on_nestedCmtsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
|
|
||||||
|
|
||||||
void on_toolButton_clicked();
|
|
||||||
void on_toolButton_2_clicked();
|
|
||||||
|
|
||||||
void on_actionHorizontal_triggered();
|
void on_actionHorizontal_triggered();
|
||||||
void on_actionVertical_triggered();
|
void on_actionVertical_triggered();
|
||||||
@ -39,7 +83,15 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Ui::CommentsWidget> ui;
|
std::unique_ptr<Ui::CommentsWidget> ui;
|
||||||
MainWindow *main;
|
MainWindow *main;
|
||||||
|
|
||||||
|
CommentsModel *commentsModel;
|
||||||
|
CommentsProxyModel *commentsProxyModel;
|
||||||
|
|
||||||
|
QList<CommentDescription> comments;
|
||||||
|
QMap<QString, QList<CommentDescription>> nestedComments;
|
||||||
|
|
||||||
|
void setScrollMode();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COMMENTSWIDGET_H
|
#endif // COMMENTSWIDGET_H
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<string notr="true">Comments</string>
|
<string notr="true">Comments</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="dockWidgetContents">
|
<widget class="QWidget" name="dockWidgetContents">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
@ -31,283 +31,17 @@
|
|||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QFrame" name="frame">
|
<widget class="QTreeView" name="commentsTreeView">
|
||||||
<property name="styleSheet">
|
<property name="sortingEnabled">
|
||||||
<string notr="true">background-color: #333;</string>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="frameShape">
|
<attribute name="headerShowSortIndicator" stdset="0">
|
||||||
<enum>QFrame::NoFrame</enum>
|
<bool>true</bool>
|
||||||
</property>
|
</attribute>
|
||||||
<property name="frameShadow">
|
|
||||||
<enum>QFrame::Raised</enum>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<property name="spacing">
|
|
||||||
<number>5</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>10</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="QToolButton" name="toolButton">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string notr="true">Show plain list</string>
|
|
||||||
</property>
|
|
||||||
<property name="styleSheet">
|
|
||||||
<string notr="true">QToolButton { /* all types of tool button */
|
|
||||||
border: 5px solid #333;
|
|
||||||
border-left: 10px solid #333;
|
|
||||||
border-right: 10px solid #333;
|
|
||||||
border-radius: 0px;
|
|
||||||
background-color: #333;
|
|
||||||
}
|
|
||||||
|
|
||||||
QToolButton:hover {
|
|
||||||
border: 5px solid #444;
|
|
||||||
border-left: 10px solid #444;
|
|
||||||
border-right: 10px solid #444;
|
|
||||||
border-radius: 0px;
|
|
||||||
background-color: #444;
|
|
||||||
}
|
|
||||||
|
|
||||||
QToolButton:checked {
|
|
||||||
border: 5px solid #2180a9;
|
|
||||||
border-left: 10px solid #2180a9;
|
|
||||||
border-right: 10px solid #2180a9;
|
|
||||||
border-radius: 0px;
|
|
||||||
background-color: #2180a9;
|
|
||||||
}
|
|
||||||
|
|
||||||
QToolTip {
|
|
||||||
background-color: #444;
|
|
||||||
border: 3px solid #444;
|
|
||||||
color: rgb(232, 232, 232);
|
|
||||||
}</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="../resources.qrc">
|
|
||||||
<normaloff>:/img/icons/hexdump_light.svg</normaloff>
|
|
||||||
<normalon>:/img/icons/hexdump_white.svg</normalon>
|
|
||||||
<activeon>:/img/icons/hexdump_white.svg</activeon>:/img/icons/hexdump_light.svg</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="checkable">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<attribute name="buttonGroup">
|
|
||||||
<string notr="true">buttonGroup</string>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QToolButton" name="toolButton_2">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string notr="true">Show grouped list</string>
|
|
||||||
</property>
|
|
||||||
<property name="styleSheet">
|
|
||||||
<string notr="true">QToolButton { /* all types of tool button */
|
|
||||||
border: 5px solid #333;
|
|
||||||
border-left: 10px solid #333;
|
|
||||||
border-right: 10px solid #333;
|
|
||||||
border-radius: 0px;
|
|
||||||
background-color: #333;
|
|
||||||
}
|
|
||||||
|
|
||||||
QToolButton:hover {
|
|
||||||
border: 5px solid #444;
|
|
||||||
border-radius: 0px;
|
|
||||||
background-color: #444;
|
|
||||||
}
|
|
||||||
|
|
||||||
QToolButton:checked {
|
|
||||||
border: 5px solid #2180a9;
|
|
||||||
border-radius: 0px;
|
|
||||||
background-color: #2180a9;
|
|
||||||
}
|
|
||||||
|
|
||||||
QToolTip {
|
|
||||||
background-color: #444;
|
|
||||||
border: 3px solid #444;
|
|
||||||
color: rgb(232, 232, 232);
|
|
||||||
}</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true"/>
|
|
||||||
</property>
|
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="../resources.qrc">
|
|
||||||
<normaloff>:/img/icons/disas_light.svg</normaloff>
|
|
||||||
<normalon>:/img/icons/disas_white.svg</normalon>
|
|
||||||
<activeon>:/img/icons/disas_white.svg</activeon>:/img/icons/disas_light.svg</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="checkable">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<attribute name="buttonGroup">
|
|
||||||
<string notr="true">buttonGroup</string>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
<widget class="QuickFilterView" name="quickFilterView" native="true"/>
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="styleSheet">
|
|
||||||
<string notr="true">QTabWidget::pane { /* The tab widget frame */
|
|
||||||
border-top: 0px;
|
|
||||||
}</string>
|
|
||||||
</property>
|
|
||||||
<property name="tabPosition">
|
|
||||||
<enum>QTabWidget::West</enum>
|
|
||||||
</property>
|
|
||||||
<property name="currentIndex">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<widget class="QWidget" name="plain">
|
|
||||||
<attribute name="title">
|
|
||||||
<string>Plain</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
|
||||||
<property name="spacing">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="QTreeWidget" name="commentsTreeWidget">
|
|
||||||
<property name="styleSheet">
|
|
||||||
<string notr="true">QTreeWidget::item
|
|
||||||
{
|
|
||||||
padding-top: 1px;
|
|
||||||
padding-bottom: 1px;
|
|
||||||
}</string>
|
|
||||||
</property>
|
|
||||||
<property name="frameShape">
|
|
||||||
<enum>QFrame::NoFrame</enum>
|
|
||||||
</property>
|
|
||||||
<property name="indentation">
|
|
||||||
<number>8</number>
|
|
||||||
</property>
|
|
||||||
<property name="sortingEnabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Offset</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Function</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Comment</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<widget class="QWidget" name="nested">
|
|
||||||
<attribute name="title">
|
|
||||||
<string>Nested</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
|
||||||
<property name="spacing">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="QTreeWidget" name="nestedCmtsTreeWidget">
|
|
||||||
<property name="styleSheet">
|
|
||||||
<string notr="true">QTreeWidget::item
|
|
||||||
{
|
|
||||||
padding-top: 1px;
|
|
||||||
padding-bottom: 1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
QToolTip {
|
|
||||||
background-color: #444;
|
|
||||||
border: 3px solid #444;
|
|
||||||
color: rgb(232, 232, 232);
|
|
||||||
font: 11pt "Monaco";
|
|
||||||
}</string>
|
|
||||||
</property>
|
|
||||||
<property name="frameShape">
|
|
||||||
<enum>QFrame::NoFrame</enum>
|
|
||||||
</property>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Function/Offset</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Comment</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@ -334,11 +68,14 @@ QToolTip {
|
|||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<customwidgets>
|
||||||
<include location="../resources.qrc"/>
|
<customwidget>
|
||||||
</resources>
|
<class>QuickFilterView</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>widgets/QuickFilterView.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
<buttongroups>
|
|
||||||
<buttongroup name="buttonGroup"/>
|
|
||||||
</buttongroups>
|
|
||||||
</ui>
|
</ui>
|
||||||
|
Loading…
Reference in New Issue
Block a user