cutter/src/widgets/TypesWidget.h

126 lines
3.1 KiB
C
Raw Normal View History

2018-03-06 17:21:48 +00:00
#ifndef TYPESWIDGET_H
#define TYPESWIDGET_H
#include <memory>
#include "Cutter.h"
#include "CutterDockWidget.h"
#include "CutterTreeWidget.h"
2018-03-06 17:21:48 +00:00
#include <QAbstractListModel>
#include <QSortFilterProxyModel>
class MainWindow;
class QTreeWidget;
class TypesWidget;
2018-03-06 17:21:48 +00:00
2018-03-21 20:32:32 +00:00
namespace Ui {
class TypesWidget;
2018-03-06 17:21:48 +00:00
}
class MainWindow;
class QTreeWidgetItem;
class TypesModel: public QAbstractListModel
{
Q_OBJECT
friend TypesWidget;
2018-03-06 17:21:48 +00:00
private:
QList<TypeDescription> *types;
public:
enum Columns { TYPE = 0, SIZE, FORMAT, CATEGORY, COUNT };
2018-03-06 17:21:48 +00:00
static const int TypeDescriptionRole = Qt::UserRole;
TypesModel(QList<TypeDescription> *types, QObject *parent = nullptr);
2018-03-06 17:21:48 +00:00
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
2018-03-06 17:21:48 +00:00
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
2018-03-06 17:21:48 +00:00
};
class TypesSortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
friend TypesWidget;
2018-03-06 17:21:48 +00:00
public:
TypesSortFilterProxyModel(TypesModel *source_model, QObject *parent = nullptr);
2018-03-06 17:21:48 +00:00
protected:
bool filterAcceptsRow(int row, const QModelIndex &parent) const override;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
QString selectedCategory;
2018-03-06 17:21:48 +00:00
};
class TypesWidget : public CutterDockWidget
2018-03-06 17:21:48 +00:00
{
Q_OBJECT
public:
explicit TypesWidget(MainWindow *main, QAction *action = nullptr);
2018-03-06 17:21:48 +00:00
~TypesWidget();
private slots:
void refreshTypes();
/*!
* \brief Show custom context menu
* \param pt Position of the place where the right mouse button was clicked
*/
void showTypesContextMenu(const QPoint &pt);
/*!
* \brief Executed on clicking the Export Types option in the context menu
* It shows the user a file dialog box to select a file where the types
* will be exported. It uses the "tc" command of radare2 to export the types.
*/
void on_actionExport_Types_triggered();
/*!
* \brief Executed on clicking the Load New types option in the context menu
* It will open the LoadNewTypesDialog where the user can either enter the
* types manually, or can select a file from where the types will be loaded
*/
void on_actionLoad_New_Types_triggered();
/*!
* \brief Executed on clicking the Delete Type option in the context menu
* Upon confirmation from the user, it will delete the selected type.
*/
void on_actionDelete_Type_triggered();
2018-03-06 17:21:48 +00:00
private:
std::unique_ptr<Ui::TypesWidget> ui;
TypesModel *types_model;
TypesSortFilterProxyModel *types_proxy_model;
QList<TypeDescription> types;
CutterTreeWidget *tree;
2018-03-06 17:21:48 +00:00
void setScrollMode();
/*!
* \brief Sets the contents of the ComboBox to the supplied contents
* \param categories The list of categories which has to be added to the ComboBox
*/
void refreshCategoryCombo(const QStringList &categories);
2018-03-06 17:21:48 +00:00
};
#endif // TYPESWIDGET_H