cutter/src/widgets/CommentsWidget.h

98 lines
2.5 KiB
C
Raw Normal View History

#ifndef COMMENTSWIDGET_H
#define COMMENTSWIDGET_H
2017-10-02 09:41:28 +00:00
#include <memory>
#include <QAbstractItemModel>
#include <QSortFilterProxyModel>
#include "Cutter.h"
#include "CutterDockWidget.h"
class MainWindow;
class QTreeWidgetItem;
2018-03-21 20:32:32 +00:00
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);
2017-09-02 08:46:48 +00:00
void refreshTree();
private:
2017-10-02 09:41:28 +00:00
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