cutter/src/widgets/TypesWidget.h

98 lines
2.0 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;
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;
};
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();
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