99 lines
3.2 KiB
C++
Executable File
99 lines
3.2 KiB
C++
Executable File
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <QtCore/QAbstractItemModel>
|
|
#include <QtCore/QStringList>
|
|
#include "nglwidgets_export.h"
|
|
|
|
class NGLTreeItem;
|
|
|
|
|
|
|
|
|
|
|
|
class NGLWIDGETS_EXPORT NGLTreeModel : public QAbstractItemModel
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
NGLTreeModel(QObject *parent, NGLTreeItem *rootItem,
|
|
const QStringList &titles);
|
|
virtual ~NGLTreeModel();
|
|
void resetModel();
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
|
QVariant headerData(int section, Qt::Orientation orientation,
|
|
int role = Qt::DisplayRole) const override;
|
|
QModelIndex index(int row, int column,
|
|
const QModelIndex &parent = QModelIndex()) const override;
|
|
QModelIndex parent(const QModelIndex &index) const override;
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::EditRole) const override;
|
|
bool setData(const QModelIndex &index, const QVariant &value,
|
|
int role = Qt::EditRole) override;
|
|
QStringList mimeTypes() const override { return { m_mimeType }; }
|
|
|
|
Qt::DropActions supportedDropActions() const override { return Qt::CopyAction | Qt::MoveAction; }
|
|
QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
|
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
|
|
int row, int column, const QModelIndex &parent) override;
|
|
|
|
bool removeRows(int row, int count,
|
|
const QModelIndex &parent = QModelIndex()) override;
|
|
|
|
|
|
NGLTreeItem *privateData(const QModelIndex &index) const;
|
|
void setMimeType(const QString &mimeType);
|
|
|
|
|
|
bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) override
|
|
{
|
|
return QAbstractItemModel::setItemData(index, roles);
|
|
}
|
|
|
|
protected:
|
|
|
|
void setMimeDataWithIcon(bool bWithIcon) { m_bMimeDataWithicon = bWithIcon; }
|
|
|
|
|
|
void resetModifedFlag(NGLTreeItem *rootItem);
|
|
|
|
bool setItemData(const QModelIndex &index, const QVariant &value,
|
|
const QIcon &icon);
|
|
QMimeData *getMimeData(const QModelIndexList &indexes,
|
|
const QString &mimeType) const;
|
|
bool insertMimeData(const QMimeData *data, const QString &mimeType,
|
|
QModelIndex parentR, int beginRow);
|
|
|
|
QVector<NGLTreeItem *> getMimeDataItems(const QMimeData *data,
|
|
const QString &mimeType) const;
|
|
|
|
bool moveRow(const QModelIndex &sourceParent, int sourceRow,
|
|
const QModelIndex &destParent, int destRow);
|
|
bool insertRow(int row, const QModelIndex &parent, NGLTreeItem *item);
|
|
|
|
void setRootItem(NGLTreeItem *rootItem);
|
|
NGLTreeItem *getRootItem() const;
|
|
|
|
virtual NGLTreeItem *createItem(const QVariant &data, const QIcon &icon) const;
|
|
|
|
void streamAddChilds(QDataStream &stream, const NGLTreeItem *item) const;
|
|
|
|
QModelIndex indexFromItem(const NGLTreeItem *item, int column = 0) const;
|
|
|
|
virtual QVariant getItemData(const NGLTreeItem *item) const;
|
|
Q_SIGNALS:
|
|
void signalDataDropped(int row, const QModelIndex &parent);
|
|
void modelDataChanged();
|
|
|
|
protected:
|
|
NGLTreeItem *m_rootItem;
|
|
QStringList m_titles;
|
|
QString m_mimeType;
|
|
bool m_bMimeDataWithicon;
|
|
};
|