Qt
::ItemFlags EsxModel
::ContentModel::flags(const QModelIndex &index
) const{
if (!index.isValid())
return Qt::NoItemFlags;
EsmFile *file = item(index.row());
if (!file)
return Qt::NoItemFlags;
Qt::ItemFlags dragDropFlags = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
Qt::ItemFlags checkFlags = Qt::ItemIsUserCheckable;
Qt::ItemFlags defaultFlags = Qt::ItemIsDropEnabled | Qt::ItemIsSelectable;
if (canBeChecked(file))
return Qt::ItemIsEnabled | dragDropFlags | checkFlags | defaultFlags;
else
return defaultFlags;
}
bool EsxModel
::ContentModel::setData(const QModelIndex &index,
const QVariant &value,
int role
) {
if (index.isValid() && role == Qt::EditRole)
{
QString fname
= value.
value<QString>
();
mFiles.replace(index.row(), findItem(fname));
emit dataChanged(index, index);
return true;
}
return false;
}
bool EsxModel
::ContentModel::insertRows(int position,
int rows,
const QModelIndex &parent
) {
beginInsertRows
(QModelIndex(), position, position
+rows
-1);
for (int row = 0; row < rows; ++row)
mFiles.insert(position, new EsmFile);
endInsertRows();
return true;
}
bool EsxModel
::ContentModel::removeRows(int position,
int rows,
const QModelIndex &parent
) {
beginRemoveRows
(QModelIndex(), position, position
+rows
-1);
for (int row = 0; row < rows; ++row)
mFiles.removeAt(position);
endRemoveRows();
emit dataChanged(index(0,0,parent), index(rowCount()-1, 0, parent));
return true;
}
Qt::DropActions EsxModel::ContentModel::supportedDropActions() const
{
return Qt::CopyAction | Qt::MoveAction;
}
{
types << "application/omwcontent";
return types;
}
QMimeData *EsxModel
::ContentModel::mimeData(const QModelIndexList
&indexes
) const {
{
if (index.isValid())
{
QString text
= data
(index, Qt
::DisplayRole).
toString();
stream << text;
}
}
mimeData->setData("application/omwcontent", encodedData);
return mimeData;
}
bool EsxModel
::ContentModel::dropMimeData(const QMimeData *data, Qt
::DropAction action,
int row,
int column,
const QModelIndex &parent
) {
if (action == Qt::IgnoreAction)
return true;
if (!data->hasFormat("application/omwcontent"))
return false;
if (column > 0)
return false;
int beginRow;
if (row != -1)
beginRow = row;
else if (parent.isValid())
beginRow = parent.row();
else
QByteArray encodedData
= data
->data
("application/omwcontent");
int rows = 0;
while (!stream.atEnd())
{
stream >> text;
newItems << text;
++rows;
}
foreach
(const QString &text, newItems
) {
setData(idx, text);
beginRow++;
}
return true;
}
Qt::ItemFlags EsxModel::ContentModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::NoItemFlags;
EsmFile *file = item(index.row());
if (!file)
return Qt::NoItemFlags;
Qt::ItemFlags dragDropFlags = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
Qt::ItemFlags checkFlags = Qt::ItemIsUserCheckable;
Qt::ItemFlags defaultFlags = Qt::ItemIsDropEnabled | Qt::ItemIsSelectable;
if (canBeChecked(file))
return Qt::ItemIsEnabled | dragDropFlags | checkFlags | defaultFlags;
else
return defaultFlags;
}
bool EsxModel::ContentModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid() && role == Qt::EditRole)
{
QString fname = value.value<QString>();
mFiles.replace(index.row(), findItem(fname));
emit dataChanged(index, index);
return true;
}
return false;
}
bool EsxModel::ContentModel::insertRows(int position, int rows, const QModelIndex &parent)
{
beginInsertRows(QModelIndex(), position, position+rows-1);
for (int row = 0; row < rows; ++row)
mFiles.insert(position, new EsmFile);
endInsertRows();
return true;
}
bool EsxModel::ContentModel::removeRows(int position, int rows, const QModelIndex &parent)
{
beginRemoveRows(QModelIndex(), position, position+rows-1);
for (int row = 0; row < rows; ++row)
mFiles.removeAt(position);
endRemoveRows();
emit dataChanged(index(0,0,parent), index(rowCount()-1, 0, parent));
return true;
}
Qt::DropActions EsxModel::ContentModel::supportedDropActions() const
{
return Qt::CopyAction | Qt::MoveAction;
}
QStringList EsxModel::ContentModel::mimeTypes() const
{
QStringList types;
types << "application/omwcontent";
return types;
}
QMimeData *EsxModel::ContentModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
foreach (const QModelIndex &index, indexes)
{
if (index.isValid())
{
QString text = data(index, Qt::DisplayRole).toString();
stream << text;
}
}
mimeData->setData("application/omwcontent", encodedData);
return mimeData;
}
bool EsxModel::ContentModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
if (action == Qt::IgnoreAction)
return true;
if (!data->hasFormat("application/omwcontent"))
return false;
if (column > 0)
return false;
int beginRow;
if (row != -1)
beginRow = row;
else if (parent.isValid())
beginRow = parent.row();
else
beginRow = rowCount(QModelIndex());
QByteArray encodedData = data->data("application/omwcontent");
QDataStream stream(&encodedData, QIODevice::ReadOnly);
QStringList newItems;
int rows = 0;
while (!stream.atEnd())
{
QString text;
stream >> text;
newItems << text;
++rows;
}
insertRows(beginRow, rows, QModelIndex());
foreach (const QString &text, newItems)
{
QModelIndex idx = index(beginRow, 0, QModelIndex());
setData(idx, text);
beginRow++;
}
return true;
}
To copy to clipboard, switch view to plain text mode
{
setFilterRole (Qt::UserRole);
if (model)
setSourceModel (model);
}
{
}
EsxModel::MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableModel* model) :
QSortFilterProxyModel(parent)
{
setFilterRegExp(QString("game"));
setFilterRole (Qt::UserRole);
if (model)
setSourceModel (model);
}
QVariant EsxModel::MasterProxyModel::data(const QModelIndex &index, int role) const
{
return QSortFilterProxyModel::data (index, role);
}
To copy to clipboard, switch view to plain text mode
Bookmarks