mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-27 12:40:25 +00:00
Stop adding and deleting rows
This commit is contained in:
parent
672cefd594
commit
0db8026356
5 changed files with 39 additions and 70 deletions
|
@ -6,9 +6,11 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
|
#include <QDataStream>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
#include <QIODevice>
|
||||||
|
|
||||||
#include <components/esm/format.hpp>
|
#include <components/esm/format.hpp>
|
||||||
#include <components/esm3/esmreader.hpp>
|
#include <components/esm3/esmreader.hpp>
|
||||||
|
@ -315,34 +317,12 @@ bool ContentSelectorModel::ContentModel::setData(const QModelIndex& index, const
|
||||||
|
|
||||||
bool ContentSelectorModel::ContentModel::insertRows(int position, int rows, const QModelIndex& parent)
|
bool ContentSelectorModel::ContentModel::insertRows(int position, int rows, const QModelIndex& parent)
|
||||||
{
|
{
|
||||||
if (parent.isValid())
|
return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
beginInsertRows(parent, position, position + rows - 1);
|
|
||||||
{
|
|
||||||
for (int row = 0; row < rows; ++row)
|
|
||||||
mFiles.insert(position, new EsmFile);
|
|
||||||
}
|
|
||||||
endInsertRows();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContentSelectorModel::ContentModel::removeRows(int position, int rows, const QModelIndex& parent)
|
bool ContentSelectorModel::ContentModel::removeRows(int position, int rows, const QModelIndex& parent)
|
||||||
{
|
{
|
||||||
if (parent.isValid())
|
return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
beginRemoveRows(parent, position, position + rows - 1);
|
|
||||||
{
|
|
||||||
for (int row = 0; row < rows; ++row)
|
|
||||||
delete mFiles.takeAt(position);
|
|
||||||
}
|
|
||||||
endRemoveRows();
|
|
||||||
|
|
||||||
// at this point we know that drag and drop has finished.
|
|
||||||
checkForLoadOrderErrors();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::DropActions ContentSelectorModel::ContentModel::supportedDropActions() const
|
Qt::DropActions ContentSelectorModel::ContentModel::supportedDropActions() const
|
||||||
|
@ -358,13 +338,14 @@ QStringList ContentSelectorModel::ContentModel::mimeTypes() const
|
||||||
QMimeData* ContentSelectorModel::ContentModel::mimeData(const QModelIndexList& indexes) const
|
QMimeData* ContentSelectorModel::ContentModel::mimeData(const QModelIndexList& indexes) const
|
||||||
{
|
{
|
||||||
QByteArray encodedData;
|
QByteArray encodedData;
|
||||||
|
QDataStream stream(&encodedData, QIODevice::WriteOnly);
|
||||||
|
|
||||||
for (const QModelIndex& index : indexes)
|
for (const QModelIndex& index : indexes)
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
encodedData.append(item(index.row())->encodedData());
|
stream << index.row();
|
||||||
}
|
}
|
||||||
|
|
||||||
QMimeData* mimeData = new QMimeData();
|
QMimeData* mimeData = new QMimeData();
|
||||||
|
@ -396,26 +377,31 @@ bool ContentSelectorModel::ContentModel::dropMimeData(
|
||||||
QByteArray encodedData = data->data(mMimeType);
|
QByteArray encodedData = data->data(mMimeType);
|
||||||
QDataStream stream(&encodedData, QIODevice::ReadOnly);
|
QDataStream stream(&encodedData, QIODevice::ReadOnly);
|
||||||
|
|
||||||
|
std::vector<EsmFile*> toMove;
|
||||||
while (!stream.atEnd())
|
while (!stream.atEnd())
|
||||||
{
|
{
|
||||||
|
int sourceRow;
|
||||||
QString value;
|
stream >> sourceRow;
|
||||||
QStringList values;
|
toMove.emplace_back(mFiles.at(sourceRow));
|
||||||
QStringList gamefiles;
|
|
||||||
|
|
||||||
for (int i = 0; i < EsmFile::FileProperty_GameFile; ++i)
|
|
||||||
{
|
|
||||||
stream >> value;
|
|
||||||
values << value;
|
|
||||||
}
|
|
||||||
|
|
||||||
stream >> gamefiles;
|
|
||||||
|
|
||||||
insertRows(beginRow, 1);
|
|
||||||
|
|
||||||
QModelIndex idx = index(beginRow++, 0, QModelIndex());
|
|
||||||
setData(idx, QStringList() << values << gamefiles, Qt::EditRole);
|
|
||||||
}
|
}
|
||||||
|
int minRow = mFiles.size();
|
||||||
|
int maxRow = 0;
|
||||||
|
for (EsmFile* file : toMove)
|
||||||
|
{
|
||||||
|
int from = mFiles.indexOf(file);
|
||||||
|
int to = beginRow;
|
||||||
|
if (from < beginRow)
|
||||||
|
to--;
|
||||||
|
else if (from > beginRow)
|
||||||
|
beginRow++;
|
||||||
|
minRow = std::min(minRow, std::min(to, from));
|
||||||
|
maxRow = std::max(maxRow, std::max(to, from));
|
||||||
|
mFiles.move(from, to);
|
||||||
|
}
|
||||||
|
|
||||||
|
dataChanged(index(minRow, 0), index(maxRow, 0));
|
||||||
|
// at this point we know that drag and drop has finished.
|
||||||
|
checkForLoadOrderErrors();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -566,6 +552,7 @@ void ContentSelectorModel::ContentModel::clearFiles()
|
||||||
if (filesCount > 0)
|
if (filesCount > 0)
|
||||||
{
|
{
|
||||||
beginRemoveRows(QModelIndex(), 0, filesCount - 1);
|
beginRemoveRows(QModelIndex(), 0, filesCount - 1);
|
||||||
|
qDeleteAll(mFiles);
|
||||||
mFiles.clear();
|
mFiles.clear();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
@ -688,7 +675,7 @@ void ContentSelectorModel::ContentModel::checkForLoadOrderErrors()
|
||||||
{
|
{
|
||||||
for (int row = 0; row < mFiles.count(); ++row)
|
for (int row = 0; row < mFiles.count(); ++row)
|
||||||
{
|
{
|
||||||
EsmFile* file = item(row);
|
EsmFile* file = mFiles.at(row);
|
||||||
bool isRowInError = checkForLoadOrderErrors(file, row).count() != 0;
|
bool isRowInError = checkForLoadOrderErrors(file, row).count() != 0;
|
||||||
if (isRowInError)
|
if (isRowInError)
|
||||||
{
|
{
|
||||||
|
@ -765,13 +752,8 @@ bool ContentSelectorModel::ContentModel::setCheckState(const QString& filepath,
|
||||||
if (!file)
|
if (!file)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Qt::CheckState state = Qt::Unchecked;
|
|
||||||
|
|
||||||
if (checkState)
|
if (checkState)
|
||||||
{
|
|
||||||
state = Qt::Checked;
|
|
||||||
mCheckedFiles.insert(file);
|
mCheckedFiles.insert(file);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
mCheckedFiles.erase(file);
|
mCheckedFiles.erase(file);
|
||||||
|
|
||||||
|
@ -781,7 +763,7 @@ bool ContentSelectorModel::ContentModel::setCheckState(const QString& filepath,
|
||||||
refreshModel();
|
refreshModel();
|
||||||
|
|
||||||
// if we're checking an item, ensure all "upstream" files (dependencies) are checked as well.
|
// if we're checking an item, ensure all "upstream" files (dependencies) are checked as well.
|
||||||
if (state == Qt::Checked)
|
if (checkState)
|
||||||
{
|
{
|
||||||
for (const QString& upstreamName : file->gameFiles())
|
for (const QString& upstreamName : file->gameFiles())
|
||||||
{
|
{
|
||||||
|
@ -796,7 +778,7 @@ bool ContentSelectorModel::ContentModel::setCheckState(const QString& filepath,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// otherwise, if we're unchecking an item (or the file is a game file) ensure all downstream files are unchecked.
|
// otherwise, if we're unchecking an item (or the file is a game file) ensure all downstream files are unchecked.
|
||||||
if (state == Qt::Unchecked)
|
else
|
||||||
{
|
{
|
||||||
for (const EsmFile* downstreamFile : mFiles)
|
for (const EsmFile* downstreamFile : mFiles)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
#include "esmfile.hpp"
|
#include "esmfile.hpp"
|
||||||
|
|
||||||
#include <QDataStream>
|
|
||||||
#include <QIODevice>
|
|
||||||
|
|
||||||
int ContentSelectorModel::EsmFile::sPropertyCount = 7;
|
|
||||||
|
|
||||||
ContentSelectorModel::EsmFile::EsmFile(const QString& fileName, ModelItem* parent)
|
ContentSelectorModel::EsmFile::EsmFile(const QString& fileName, ModelItem* parent)
|
||||||
: ModelItem(parent)
|
: ModelItem(parent)
|
||||||
, mFileName(fileName)
|
, mFileName(fileName)
|
||||||
|
@ -46,17 +41,6 @@ void ContentSelectorModel::EsmFile::setDescription(const QString& description)
|
||||||
mDescription = description;
|
mDescription = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray ContentSelectorModel::EsmFile::encodedData() const
|
|
||||||
{
|
|
||||||
QByteArray encodedData;
|
|
||||||
QDataStream stream(&encodedData, QIODevice::WriteOnly);
|
|
||||||
|
|
||||||
stream << mFileName << mAuthor << mVersion << mModified.toString(Qt::ISODate) << mPath << mDescription
|
|
||||||
<< mGameFiles;
|
|
||||||
|
|
||||||
return encodedData;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ContentSelectorModel::EsmFile::isGameFile() const
|
bool ContentSelectorModel::EsmFile::isGameFile() const
|
||||||
{
|
{
|
||||||
return (mGameFiles.size() == 0)
|
return (mGameFiles.size() == 0)
|
||||||
|
|
|
@ -64,10 +64,6 @@ namespace ContentSelectorModel
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isGameFile() const;
|
bool isGameFile() const;
|
||||||
QByteArray encodedData() const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static int sPropertyCount;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString mTooltipTemlate = tr(
|
QString mTooltipTemlate = tr(
|
||||||
|
|
|
@ -108,6 +108,7 @@ void ContentSelectorView::ContentSelector::buildAddonView()
|
||||||
connect(ui->addonView, &QTableView::activated, this, &ContentSelector::slotAddonTableItemActivated);
|
connect(ui->addonView, &QTableView::activated, this, &ContentSelector::slotAddonTableItemActivated);
|
||||||
connect(mContentModel, &ContentSelectorModel::ContentModel::dataChanged, this,
|
connect(mContentModel, &ContentSelectorModel::ContentModel::dataChanged, this,
|
||||||
&ContentSelector::signalAddonDataChanged);
|
&ContentSelector::signalAddonDataChanged);
|
||||||
|
connect(mContentModel, &ContentSelectorModel::ContentModel::dataChanged, this, &ContentSelector::slotRowsMoved);
|
||||||
buildContextMenu();
|
buildContextMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,3 +332,8 @@ void ContentSelectorView::ContentSelector::slotSearchFilterTextChanged(const QSt
|
||||||
{
|
{
|
||||||
ui->addonView->setDragEnabled(newText.isEmpty());
|
ui->addonView->setDragEnabled(newText.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContentSelectorView::ContentSelector::slotRowsMoved()
|
||||||
|
{
|
||||||
|
ui->addonView->selectionModel()->clearSelection();
|
||||||
|
}
|
|
@ -85,6 +85,7 @@ namespace ContentSelectorView
|
||||||
void slotUncheckMultiSelectedItems();
|
void slotUncheckMultiSelectedItems();
|
||||||
void slotCopySelectedItemsPaths();
|
void slotCopySelectedItemsPaths();
|
||||||
void slotSearchFilterTextChanged(const QString& newText);
|
void slotSearchFilterTextChanged(const QString& newText);
|
||||||
|
void slotRowsMoved();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue