mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-19 11:26:11 +00:00
bebc2ec36d
* Replace 0 and Q_NULLPTR with nullptr * Use c++11 foreach
98 lines
2.5 KiB
C++
98 lines
2.5 KiB
C++
#ifndef COMMENTSWIDGET_H
|
|
#define COMMENTSWIDGET_H
|
|
|
|
#include <memory>
|
|
#include <QAbstractItemModel>
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include "Cutter.h"
|
|
#include "CutterDockWidget.h"
|
|
|
|
class MainWindow;
|
|
class QTreeWidgetItem;
|
|
|
|
namespace Ui {
|
|
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 = 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 = 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
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit CommentsWidget(MainWindow *main, QAction *action = nullptr);
|
|
~CommentsWidget();
|
|
|
|
protected:
|
|
void resizeEvent(QResizeEvent *event) override;
|
|
|
|
private slots:
|
|
void on_commentsTreeView_doubleClicked(const QModelIndex &index);
|
|
|
|
void on_actionHorizontal_triggered();
|
|
void on_actionVertical_triggered();
|
|
|
|
void showTitleContextMenu(const QPoint &pt);
|
|
|
|
void refreshTree();
|
|
|
|
private:
|
|
std::unique_ptr<Ui::CommentsWidget> ui;
|
|
MainWindow *main;
|
|
|
|
CommentsModel *commentsModel;
|
|
CommentsProxyModel *commentsProxyModel;
|
|
|
|
QList<CommentDescription> comments;
|
|
QMap<QString, QList<CommentDescription>> nestedComments;
|
|
|
|
void setScrollMode();
|
|
};
|
|
|
|
#endif // COMMENTSWIDGET_H
|