2018-03-06 17:21:48 +00:00
|
|
|
#ifndef TYPESWIDGET_H
|
|
|
|
#define TYPESWIDGET_H
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/Cutter.h"
|
2018-03-16 21:46:57 +00:00
|
|
|
#include "CutterDockWidget.h"
|
2019-02-01 16:11:50 +00:00
|
|
|
#include "CutterTreeWidget.h"
|
2018-03-06 17:21:48 +00:00
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
|
|
|
class MainWindow;
|
|
|
|
class QTreeWidget;
|
2018-10-10 11:33:55 +00:00
|
|
|
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
|
|
|
|
|
2018-10-10 11:33:55 +00:00
|
|
|
friend TypesWidget;
|
|
|
|
|
2018-03-06 17:21:48 +00:00
|
|
|
private:
|
|
|
|
QList<TypeDescription> *types;
|
|
|
|
|
|
|
|
public:
|
2019-02-01 16:11:50 +00:00
|
|
|
enum Columns { TYPE = 0, SIZE, FORMAT, CATEGORY, COUNT };
|
2018-03-06 17:21:48 +00:00
|
|
|
static const int TypeDescriptionRole = Qt::UserRole;
|
|
|
|
|
2018-05-04 07:58:32 +00:00
|
|
|
TypesModel(QList<TypeDescription> *types, QObject *parent = nullptr);
|
2018-03-06 17:21:48 +00:00
|
|
|
|
2019-02-11 09:34:15 +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
|
|
|
|
2019-02-11 09:34:15 +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
|
|
|
|
|
2019-02-01 16:11:50 +00:00
|
|
|
friend TypesWidget;
|
|
|
|
|
2018-03-06 17:21:48 +00:00
|
|
|
public:
|
2018-05-04 07:58:32 +00:00
|
|
|
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;
|
2019-02-01 16:11:50 +00:00
|
|
|
|
|
|
|
QString selectedCategory;
|
2018-03-06 17:21:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
class TypesWidget : public CutterDockWidget
|
2018-03-06 17:21:48 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-03-16 21:46:57 +00:00
|
|
|
explicit TypesWidget(MainWindow *main, QAction *action = nullptr);
|
2018-03-06 17:21:48 +00:00
|
|
|
~TypesWidget();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void refreshTypes();
|
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Show custom context menu
|
|
|
|
* @param pt Position of the place where the right mouse button was clicked
|
2019-02-11 09:34:15 +00:00
|
|
|
*/
|
|
|
|
void showTypesContextMenu(const QPoint &pt);
|
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Executed on clicking the Export Types option in the context menu
|
2019-02-11 09:34:15 +00:00
|
|
|
* 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();
|
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Executed on clicking the Load New types option in the context menu
|
2019-06-13 06:22:20 +00:00
|
|
|
* It will open the TypesInteractionDialog where the user can either enter the
|
2019-02-11 09:34:15 +00:00
|
|
|
* types manually, or can select a file from where the types will be loaded
|
|
|
|
*/
|
|
|
|
void on_actionLoad_New_Types_triggered();
|
|
|
|
|
2019-06-13 06:22:20 +00:00
|
|
|
/**
|
|
|
|
* @brief Executed on clicking either the Edit Type or View Type options in the context menu
|
|
|
|
* It will open the TypesInteractionDialog filled with the selected type. Depends on Edit or View mode
|
|
|
|
* the text view would be read-only or not.
|
|
|
|
*/
|
|
|
|
void viewType(bool readOnly=true);
|
|
|
|
|
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Executed on clicking the Delete Type option in the context menu
|
2019-02-11 09:34:15 +00:00
|
|
|
* Upon confirmation from the user, it will delete the selected type.
|
|
|
|
*/
|
|
|
|
void on_actionDelete_Type_triggered();
|
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Executed on clicking the Link To Address option in the context menu
|
2019-03-04 21:45:17 +00:00
|
|
|
* Opens the LinkTypeDialog box from where the user can link a address to a type
|
|
|
|
*/
|
|
|
|
void on_actionLink_Type_To_Address_triggered();
|
|
|
|
|
2019-06-13 06:22:20 +00:00
|
|
|
/**
|
|
|
|
* @brief triggers when the user double-clicks an item. This will open
|
|
|
|
* a dialog that shows the Type's content
|
|
|
|
*/
|
|
|
|
void typeItemDoubleClicked(const QModelIndex &index);
|
|
|
|
|
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;
|
2019-02-01 16:11:50 +00:00
|
|
|
CutterTreeWidget *tree;
|
2019-06-13 06:22:20 +00:00
|
|
|
QAction *actionViewType;
|
|
|
|
QAction *actionEditType;
|
2018-03-06 17:21:48 +00:00
|
|
|
|
|
|
|
void setScrollMode();
|
2019-02-01 16:11:50 +00:00
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
|
|
|
* @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
|
2019-02-01 16:11:50 +00:00
|
|
|
*/
|
|
|
|
void refreshCategoryCombo(const QStringList &categories);
|
2018-03-06 17:21:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // TYPESWIDGET_H
|