cutter/src/widgets/FlagsWidget.h
Nics c4e8a1c178 Small refactor for the widgets of Cutter (#405)
* Small refactor for the widgets of Cutter

This refactor include the following :

* Creation of a new class
Creation of a new class, named CutterWidget, that inherits from QDockWidget and
is used to represent all of the widgets of the main window.
The goal of this class is to regroup all the behaviour shared by the widgets of
Cutter.

For example : in the constructor, instructions corresponding of those
present in the macro **ADD_DOCK** (in MainWindow.cpp) are executed.
This was made because I think that the macro **ADD_DOCK** which is used
to construct the widgets does not take advantage of the object structure.

* Ensure that every widget has a parent
Some widgets were created using the constructor QDockWidget, but using
**nullptr** (default) as argument, thus they haven't got any parent.

The constructor of a CutterWidget takes as argument the MainWindow and an
action (optional) and calls the constructor of QDockWidget with the main
window as argument. This is valid under the assumption that it is mandatory
for every widget to have the main window as a parent.

* Constructors removal
The constructors of some widgets are not used anywhere and does not seem not
fullfill any current usecase. They were removed.

* Renaming CutterWidget to CutterDockWidget
2018-03-16 22:46:57 +01:00

93 lines
2.0 KiB
C++

#ifndef FLAGSWIDGET_H
#define FLAGSWIDGET_H
#include <memory>
#include <QAbstractItemModel>
#include <QSortFilterProxyModel>
#include "Cutter.h"
#include "CutterDockWidget.h"
class MainWindow;
class QTreeWidgetItem;
class FlagsModel: public QAbstractListModel
{
Q_OBJECT
private:
QList<FlagDescription> *flags;
public:
enum Columns { OFFSET = 0, SIZE, NAME, COUNT };
static const int FlagDescriptionRole = Qt::UserRole;
FlagsModel(QList<FlagDescription> *flags, QObject *parent = 0);
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 beginReloadFlags();
void endReloadFlags();
};
class FlagsSortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
FlagsSortFilterProxyModel(FlagsModel *source_model, QObject *parent = 0);
protected:
bool filterAcceptsRow(int row, const QModelIndex &parent) const override;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
};
namespace Ui
{
class FlagsWidget;
}
class FlagsWidget : public CutterDockWidget
{
Q_OBJECT
public:
explicit FlagsWidget(MainWindow *main, QAction *action = nullptr);
~FlagsWidget();
private slots:
void on_flagsTreeView_doubleClicked(const QModelIndex &index);
void on_flagspaceCombo_currentTextChanged(const QString &arg1);
void on_actionRename_triggered();
void on_actionDelete_triggered();
void showContextMenu(const QPoint &pt);
void flagsChanged();
void refreshFlagspaces();
private:
std::unique_ptr<Ui::FlagsWidget> ui;
MainWindow *main;
FlagsModel *flags_model;
FlagsSortFilterProxyModel *flags_proxy_model;
QList<FlagDescription> flags;
void refreshFlags();
void setScrollMode();
};
#endif // FLAGSWIDGET_H