mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-28 19:21:04 +00:00
Implemneting drag and drop
This commit is contained in:
parent
a6e7cf9a8c
commit
0eb06ada39
@ -7,7 +7,6 @@
|
||||
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
|
||||
#include <components/esxselector/model/datafilesmodel.hpp>
|
||||
#include <components/esxselector/model/pluginsproxymodel.hpp>
|
||||
#include <components/esxselector/model/esmfile.hpp>
|
||||
|
||||
@ -20,6 +19,7 @@
|
||||
#include "settings/launchersettings.hpp"
|
||||
|
||||
#include "utils/textinputdialog.hpp"
|
||||
#include "components/esxselector/view/contentselector.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
@ -27,8 +27,8 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gam
|
||||
: mCfgMgr(cfg)
|
||||
, mGameSettings(gameSettings)
|
||||
, mLauncherSettings(launcherSettings)
|
||||
, ContentSelector(parent)
|
||||
{
|
||||
mContentSelector.setParent(parent);
|
||||
QMetaObject::connectSlotsByName(this);
|
||||
|
||||
projectGroupBox->hide();
|
||||
@ -51,24 +51,21 @@ void DataFilesPage::createActions()
|
||||
|
||||
void DataFilesPage::setupDataFiles()
|
||||
{
|
||||
if (!mDataFilesModel)
|
||||
qDebug() << "data files model undefined";
|
||||
|
||||
// Set the encoding to the one found in openmw.cfg or the default
|
||||
mDataFilesModel->setEncoding(mGameSettings.value(QString("encoding"), QString("win1252")));
|
||||
mContentSelector.setEncoding(mGameSettings.value(QString("encoding"), QString("win1252")));
|
||||
|
||||
QStringList paths = mGameSettings.getDataDirs();
|
||||
|
||||
foreach (const QString &path, paths) {
|
||||
mDataFilesModel->addFiles(path);
|
||||
mContentSelector.addFiles(path);
|
||||
}
|
||||
|
||||
QString dataLocal = mGameSettings.getDataLocal();
|
||||
if (!dataLocal.isEmpty())
|
||||
mDataFilesModel->addFiles(dataLocal);
|
||||
mContentSelector.addFiles(dataLocal);
|
||||
|
||||
// Sort by date accessed for now
|
||||
mDataFilesModel->sort(3);
|
||||
//mContentSelector->sort(3);
|
||||
|
||||
QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/"));
|
||||
QString profile = mLauncherSettings.value(QString("Profiles/currentprofile"));
|
||||
@ -107,11 +104,11 @@ void DataFilesPage::loadSettings()
|
||||
if (profile.isEmpty())
|
||||
return;
|
||||
|
||||
mDataFilesModel->uncheckAll();
|
||||
// mContentSelector.uncheckAll();
|
||||
|
||||
QStringList masters = mLauncherSettings.values(QString("Profiles/") + profile + QString("/master"), Qt::MatchExactly);
|
||||
QStringList plugins = mLauncherSettings.values(QString("Profiles/") + profile + QString("/plugin"), Qt::MatchExactly);
|
||||
|
||||
/*
|
||||
foreach (const QString &master, masters) {
|
||||
QModelIndex index = mDataFilesModel->indexFromItem(mDataFilesModel->findItem(master));
|
||||
if (index.isValid())
|
||||
@ -123,12 +120,13 @@ void DataFilesPage::loadSettings()
|
||||
if (index.isValid())
|
||||
mDataFilesModel->setCheckState(index, Qt::Checked);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void DataFilesPage::saveSettings()
|
||||
{
|
||||
if (mDataFilesModel->rowCount() < 1)
|
||||
return;
|
||||
// if (mDataFilesModel->rowCount() < 1)
|
||||
// return;
|
||||
|
||||
QString profile = mLauncherSettings.value(QString("Profiles/currentprofile"));
|
||||
|
||||
@ -143,8 +141,8 @@ void DataFilesPage::saveSettings()
|
||||
mGameSettings.remove(QString("master"));
|
||||
mGameSettings.remove(QString("plugin"));
|
||||
|
||||
EsxModel::EsmFileList items = mDataFilesModel->checkedItems();
|
||||
|
||||
// EsxModel::EsmFileList items = mDataFilesModel->checkedItems();
|
||||
/*
|
||||
foreach(const EsxModel::EsmFile *item, items) {
|
||||
|
||||
if (item->masters().size() == 0) {
|
||||
@ -156,7 +154,7 @@ void DataFilesPage::saveSettings()
|
||||
mGameSettings.setMultiValue(QString("plugin"), item->fileName());
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
void DataFilesPage::updateOkButton(const QString &text)
|
||||
@ -241,7 +239,7 @@ void DataFilesPage::setPluginsCheckstates(Qt::CheckState state)
|
||||
if (!sourceIndex.isValid())
|
||||
return;
|
||||
|
||||
mDataFilesModel->setCheckState(sourceIndex, state);
|
||||
//mDataFilesModel->setCheckState(sourceIndex, state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@ private slots:
|
||||
private:
|
||||
|
||||
QMenu *mContextMenu;
|
||||
ContentSelector mContentSelector;
|
||||
|
||||
Files::ConfigurationManager &mCfgMgr;
|
||||
|
||||
|
@ -72,7 +72,7 @@ find_package(Qt4 COMPONENTS QtCore QtGui)
|
||||
|
||||
if(QT_QTGUI_LIBRARY AND QT_QTCORE_LIBRARY)
|
||||
add_component_qt_dir (esxselector
|
||||
model/masterproxymodel model/modelitem model/datafilesmodel
|
||||
model/masterproxymodel model/modelitem
|
||||
model/pluginsproxymodel model/esmfile model/naturalsort
|
||||
model/contentmodel
|
||||
view/profilescombobox view/comboboxlineedit
|
||||
|
@ -21,20 +21,7 @@ int EsxModel::ContentModel::columnCount(const QModelIndex &parent) const
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
QModelIndex EsxModel::ContentModel::parent(const QModelIndex &child) const
|
||||
{
|
||||
if(!child.isValid())
|
||||
return 0;
|
||||
|
||||
return child.parent();
|
||||
}
|
||||
|
||||
QModelIndex EsxModel::ContentModel::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
int EsxModel::ContentModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if(parent.isValid())
|
||||
@ -43,6 +30,53 @@ int EsxModel::ContentModel::rowCount(const QModelIndex &parent) const
|
||||
return mFiles.size();
|
||||
}
|
||||
|
||||
EsxModel::EsmFile* EsxModel::ContentModel::item(int row) const
|
||||
{
|
||||
if (row >= 0 && row < mFiles.count())
|
||||
return mFiles.at(row);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EsxModel::EsmFile* EsxModel::ContentModel::findItem(const QString &name)
|
||||
{
|
||||
for (int i = 0; i < mFiles.size(); ++i)
|
||||
{
|
||||
if (name == item(i)->fileName())
|
||||
return item(i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QModelIndex EsxModel::ContentModel::indexFromItem(EsmFile *item) const
|
||||
{
|
||||
if (item)
|
||||
return index(mFiles.indexOf(item),0);
|
||||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
@ -70,18 +104,14 @@ QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const
|
||||
case 1:
|
||||
return file->author();
|
||||
case 2:
|
||||
return QString("%1 kB").arg(int((file->size() + 1023) / 1024));
|
||||
case 3:
|
||||
return file->modified().toString(Qt::ISODate);
|
||||
case 4:
|
||||
return file->accessed().toString(Qt::TextDate);
|
||||
case 5:
|
||||
case 3:
|
||||
return file->version();
|
||||
case 6:
|
||||
case 4:
|
||||
return file->path();
|
||||
case 7:
|
||||
case 5:
|
||||
return file->masters().join(", ");
|
||||
case 8:
|
||||
case 6:
|
||||
return file->description();
|
||||
}
|
||||
|
||||
@ -97,8 +127,6 @@ QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const
|
||||
return Qt::AlignLeft + Qt::AlignVCenter;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
return Qt::AlignRight + Qt::AlignVCenter;
|
||||
default:
|
||||
return Qt::AlignLeft + Qt::AlignVCenter;
|
||||
@ -124,47 +152,88 @@ QVariant EsxModel::ContentModel::data(const QModelIndex &index, int role) const
|
||||
.arg(file->masters().join(", "));
|
||||
}
|
||||
|
||||
case Qt::CheckStateRole:
|
||||
if (!file->isMaster())
|
||||
return isChecked(file->fileName());
|
||||
break;
|
||||
|
||||
case Qt::UserRole:
|
||||
{
|
||||
if (file->masters().size() == 0)
|
||||
if (file->isMaster())
|
||||
return "game";
|
||||
else
|
||||
return "addon";
|
||||
}
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
case Qt::UserRole + 1:
|
||||
return isChecked(file->fileName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool EsxModel::ContentModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (index.isValid() && role == Qt::EditRole)
|
||||
if(!index.isValid())
|
||||
return false;
|
||||
|
||||
EsmFile *file = item(index.row());
|
||||
QString fileName = file->fileName();
|
||||
|
||||
switch(role)
|
||||
{
|
||||
QString fname = value.value<QString>();
|
||||
mFiles.replace(index.row(), findItem(fname));
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
case Qt::EditRole:
|
||||
{
|
||||
QStringList list = value.toStringList();
|
||||
|
||||
//iterate the string list, assigning values to proeprties
|
||||
//index-enum correspondence 1:1
|
||||
for (int i = 0; i < EsxModel::Property_Master; i++)
|
||||
file->setProperty(static_cast<EsmFileProperty>(i), list.at(i));
|
||||
|
||||
//iterate the remainder of the string list, assifning everything
|
||||
// as
|
||||
for (int i = EsxModel::Property_Master; i < list.size(); i++)
|
||||
file->setProperty (EsxModel::Property_Master, list.at(i));
|
||||
|
||||
//emit data changed for the item itself
|
||||
emit dataChanged(index, index);
|
||||
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case Qt::UserRole+1:
|
||||
{
|
||||
setCheckState(fileName, value.toBool());
|
||||
|
||||
emit dataChanged(index, index);
|
||||
|
||||
for(int i = 0; i < mFiles.size(); i++)
|
||||
{
|
||||
|
||||
if (mFiles.at(i)->masters().contains(fileName))
|
||||
{
|
||||
QModelIndex idx = QAbstractTableModel::index(i, 0);
|
||||
emit dataChanged(idx, idx);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case Qt::CheckStateRole:
|
||||
{
|
||||
bool checked = ((value.toInt() == Qt::Checked) && !isChecked(fileName));
|
||||
|
||||
setCheckState(fileName, checked);
|
||||
|
||||
emit dataChanged(index, index);
|
||||
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -172,24 +241,31 @@ bool EsxModel::ContentModel::setData(const QModelIndex &index, const QVariant &v
|
||||
|
||||
bool EsxModel::ContentModel::insertRows(int position, int rows, const QModelIndex &parent)
|
||||
{
|
||||
if (parent.isValid())
|
||||
return false;
|
||||
|
||||
beginInsertRows(parent, position, position+rows-1);
|
||||
{
|
||||
for (int row = 0; row < rows; ++row)
|
||||
mFiles.insert(position, new EsmFile);
|
||||
|
||||
for (int row = 0; row < rows; ++row)
|
||||
mFiles.insert(position, new EsmFile);
|
||||
} endInsertRows();
|
||||
|
||||
endInsertRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EsxModel::ContentModel::removeRows(int position, int rows, const QModelIndex &parent)
|
||||
{
|
||||
if (parent.isValid())
|
||||
return false;
|
||||
|
||||
beginRemoveRows(parent, position, position+rows-1);
|
||||
{
|
||||
for (int row = 0; row < rows; ++row)
|
||||
delete mFiles.takeAt(position);
|
||||
|
||||
for (int row = 0; row < rows; ++row)
|
||||
mFiles.removeAt(position);
|
||||
} endRemoveRows();
|
||||
|
||||
endRemoveRows();
|
||||
emit dataChanged(index(0,0,parent), index(rowCount()-1, 0, parent));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -201,27 +277,30 @@ Qt::DropActions EsxModel::ContentModel::supportedDropActions() const
|
||||
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;
|
||||
}
|
||||
if (!index.isValid())
|
||||
continue;
|
||||
|
||||
QByteArray fileData = item(index.row())->encodedData();
|
||||
|
||||
foreach (const char c, fileData)
|
||||
encodedData.append(c);
|
||||
}
|
||||
|
||||
QMimeData *mimeData = new QMimeData();
|
||||
mimeData->setData("application/omwcontent", encodedData);
|
||||
|
||||
return mimeData;
|
||||
}
|
||||
|
||||
@ -240,31 +319,66 @@ bool EsxModel::ContentModel::dropMimeData(const QMimeData *data, Qt::DropAction
|
||||
|
||||
if (row != -1)
|
||||
beginRow = row;
|
||||
|
||||
else if (parent.isValid())
|
||||
beginRow = parent.row();
|
||||
|
||||
else
|
||||
beginRow = rowCount();
|
||||
|
||||
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;
|
||||
QStringList values;
|
||||
|
||||
for (int i = 0; i < EsmFile::sPropertyCount; ++i)
|
||||
stream >> values;
|
||||
|
||||
insertRows(beginRow, 1);
|
||||
|
||||
QModelIndex idx = index(beginRow++, 0, QModelIndex());
|
||||
setData(idx, values, Qt::EditRole);
|
||||
}
|
||||
|
||||
insertRows(beginRow, rows, QModelIndex());
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (const QString &text, newItems)
|
||||
bool EsxModel::ContentModel::canBeChecked(const EsmFile *file) const
|
||||
{
|
||||
//element can be checked if all its dependencies are
|
||||
foreach (const QString &master, file->masters())
|
||||
{
|
||||
QModelIndex idx = index(beginRow, 0, QModelIndex());
|
||||
setData(idx, text);
|
||||
beginRow++;
|
||||
{// if the master is not found in checkstates
|
||||
// or it is not specifically checked, return false
|
||||
if (!mCheckStates.contains(master))
|
||||
return false;
|
||||
|
||||
if (!isChecked(master))
|
||||
return false;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
|
||||
//iterate each file, if it is not a master and
|
||||
//does not have a master that is currently checked,
|
||||
//return false.
|
||||
foreach(const EsmFile *file, mFiles)
|
||||
{
|
||||
QString filename = file->fileName();
|
||||
|
||||
found = (filename == master);
|
||||
|
||||
if (found)
|
||||
{
|
||||
if (!isChecked(filename))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -272,9 +386,10 @@ bool EsxModel::ContentModel::dropMimeData(const QMimeData *data, Qt::DropAction
|
||||
|
||||
void EsxModel::ContentModel::addFile(EsmFile *file)
|
||||
{
|
||||
emit beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count());
|
||||
mFiles.append(file);
|
||||
emit endInsertRows();
|
||||
beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count());
|
||||
{
|
||||
mFiles.append(file);
|
||||
} endInsertRows();
|
||||
}
|
||||
|
||||
void EsxModel::ContentModel::addFiles(const QString &path)
|
||||
@ -319,9 +434,9 @@ void EsxModel::ContentModel::addFiles(const QString &path)
|
||||
}
|
||||
|
||||
file->setAuthor(decoder->toUnicode(fileReader.getAuthor().c_str()));
|
||||
file->setSize(info.size());
|
||||
file->setDates(info.lastModified(), info.lastRead());
|
||||
file->setVersion(fileReader.getFVer());
|
||||
//file->setSize(info.size());
|
||||
file->setDate(info.lastModified());
|
||||
file->setVersion(0.0f);
|
||||
file->setPath(info.absoluteFilePath());
|
||||
file->setMasters(masters);
|
||||
file->setDescription(decoder->toUnicode(fileReader.getDesc().c_str()));
|
||||
@ -342,66 +457,22 @@ void EsxModel::ContentModel::addFiles(const QString &path)
|
||||
delete decoder;
|
||||
}
|
||||
|
||||
EsxModel::EsmFile* EsxModel::ContentModel::findItem(const QString &name)
|
||||
bool EsxModel::ContentModel::isChecked(const QString& name) const
|
||||
{
|
||||
for (int i = 0; i < mFiles.size(); ++i)
|
||||
{
|
||||
if (name == item(i)->fileName())
|
||||
return item(i);
|
||||
}
|
||||
|
||||
// Not found
|
||||
return 0;
|
||||
return (mCheckStates[name] == Qt::Checked);
|
||||
}
|
||||
|
||||
EsxModel::EsmFile* EsxModel::ContentModel::item(int row) const
|
||||
void EsxModel::ContentModel::setCheckState(const QString &name, bool isChecked)
|
||||
{
|
||||
if (row >= 0 && row < mFiles.count())
|
||||
return mFiles.at(row);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QModelIndex EsxModel::ContentModel::indexFromItem(EsmFile *item) const
|
||||
{
|
||||
if (item)
|
||||
//return createIndex(mFiles.indexOf(item), 0);
|
||||
return index(mFiles.indexOf(item),0);
|
||||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
Qt::CheckState EsxModel::ContentModel::checkState(const QModelIndex &index)
|
||||
{
|
||||
return mCheckStates[item(index.row())->fileName()];
|
||||
}
|
||||
|
||||
void EsxModel::ContentModel::setCheckState(const QModelIndex &index, Qt::CheckState state)
|
||||
{
|
||||
if (!index.isValid())
|
||||
if (name.isEmpty())
|
||||
return;
|
||||
|
||||
QString name = item(index.row())->fileName();
|
||||
Qt::CheckState state = Qt::Unchecked;
|
||||
|
||||
if (isChecked)
|
||||
state = Qt::Checked;
|
||||
|
||||
mCheckStates[name] = state;
|
||||
|
||||
// Force a redraw of the view since unchecking one item can affect another
|
||||
QModelIndex firstIndex = indexFromItem(mFiles.first());
|
||||
QModelIndex lastIndex = indexFromItem(mFiles.last());
|
||||
|
||||
emit dataChanged(firstIndex, lastIndex);
|
||||
//emit checkedItemsChanged(checkedItems());
|
||||
|
||||
}
|
||||
|
||||
bool EsxModel::ContentModel::canBeChecked(const EsmFile *file) const
|
||||
{
|
||||
//element can be checked if all its dependencies are
|
||||
foreach (const QString &master, file->masters())
|
||||
{
|
||||
if (!mCheckStates.contains(master) || mCheckStates[master] != Qt::Checked)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
EsxModel::ContentFileList EsxModel::ContentModel::checkedItems() const
|
||||
|
@ -37,14 +37,11 @@ namespace EsxModel
|
||||
QModelIndex indexFromItem(EsmFile *item) const;
|
||||
EsxModel::EsmFile *findItem(const QString &name);
|
||||
|
||||
Qt::CheckState checkState(const QModelIndex &index);
|
||||
void setCheckState(const QModelIndex &index, Qt::CheckState state);
|
||||
bool isChecked(const QString &name) const;
|
||||
void setCheckState(const QString &name, bool isChecked);
|
||||
ContentFileList checkedItems() const;
|
||||
void uncheckAll();
|
||||
/*
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent) const;
|
||||
QModelIndex parent(const QModelIndex &child) const;
|
||||
*/
|
||||
|
||||
private:
|
||||
|
||||
void addFile(EsmFile *file);
|
||||
|
@ -24,6 +24,340 @@ EsxModel::DataFilesModel::~DataFilesModel()
|
||||
{
|
||||
}
|
||||
|
||||
int EsxModel::DataFilesModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : mFiles.count();
|
||||
}
|
||||
|
||||
int EsxModel::DataFilesModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : 1;
|
||||
}
|
||||
|
||||
const EsxModel::EsmFile* EsxModel::DataFilesModel::findItem(const QString &name)
|
||||
{
|
||||
for (int i = 0; i < mFiles.size(); ++i)
|
||||
{
|
||||
const EsmFile *file = item(i);
|
||||
|
||||
if (name == file->fileName())
|
||||
return file;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const EsxModel::EsmFile* EsxModel::DataFilesModel::item(int row) const
|
||||
{
|
||||
if (row >= 0 && row < mFiles.count())
|
||||
return mFiles.at(row);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Qt::ItemFlags EsxModel::DataFilesModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
const EsmFile *file = item(index.row());
|
||||
|
||||
if (!file)
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
Qt::ItemFlags dragDropFlags = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
||||
Qt::ItemFlags checkFlags = Qt::ItemIsUserCheckable | Qt::ItemIsEditable;
|
||||
Qt::ItemFlags defaultFlags = Qt::ItemIsDropEnabled | Qt::ItemIsSelectable;
|
||||
|
||||
if (canBeChecked(file))
|
||||
return defaultFlags | dragDropFlags | checkFlags | Qt::ItemIsEnabled;
|
||||
else
|
||||
return defaultFlags;
|
||||
}
|
||||
|
||||
QVariant EsxModel::DataFilesModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (index.row() >= mFiles.size())
|
||||
return QVariant();
|
||||
|
||||
const EsmFile *file = item(index.row());
|
||||
|
||||
if (!file)
|
||||
return QVariant();
|
||||
|
||||
const int column = index.column();
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case Qt::EditRole:
|
||||
case Qt::DisplayRole:
|
||||
{
|
||||
|
||||
switch (column)
|
||||
{
|
||||
case 0:
|
||||
return file->fileName();
|
||||
case 1:
|
||||
return file->author();
|
||||
case 2:
|
||||
return file->modified().toString(Qt::ISODate);
|
||||
case 3:
|
||||
return file->version();
|
||||
case 4:
|
||||
return file->path();
|
||||
case 5:
|
||||
return file->masters().join(", ");
|
||||
case 6:
|
||||
return file->description();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Qt::TextAlignmentRole:
|
||||
{
|
||||
switch (column)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
return Qt::AlignLeft + Qt::AlignVCenter;
|
||||
case 2:
|
||||
case 3:
|
||||
return Qt::AlignRight + Qt::AlignVCenter;
|
||||
default:
|
||||
return Qt::AlignLeft + Qt::AlignVCenter;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
{
|
||||
if (column != 0)
|
||||
return QVariant();
|
||||
|
||||
if (file->version() == 0.0f)
|
||||
return QVariant(); // Data not set
|
||||
|
||||
QString tooltip =
|
||||
QString("<b>Author:</b> %1<br/> \
|
||||
<b>Version:</b> %2<br/> \
|
||||
<br/><b>Description:</b><br/>%3<br/> \
|
||||
<br/><b>Dependencies: </b>%4<br/>")
|
||||
.arg(file->author())
|
||||
.arg(QString::number(file->version()))
|
||||
.arg(file->description())
|
||||
.arg(file->masters().join(", "));
|
||||
|
||||
|
||||
return tooltip;
|
||||
break;
|
||||
}
|
||||
|
||||
case Qt::UserRole:
|
||||
{
|
||||
if (file->masters().size() == 0)
|
||||
return "game";
|
||||
else
|
||||
return "addon";
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Qt::UserRole + 1:
|
||||
//return check state here
|
||||
break;
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool EsxModel::DataFilesModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid())
|
||||
return false;
|
||||
|
||||
switch (role)
|
||||
{
|
||||
case Qt::EditRole:
|
||||
{
|
||||
const EsmFile *file = item(index.row());
|
||||
|
||||
// iterate loop to repopulate file pointer with data in string list.
|
||||
QStringList list = value.toStringList();
|
||||
for (int i = 0; i <999; ++i)
|
||||
{
|
||||
file->setProperty(i, value.at(i));
|
||||
}
|
||||
|
||||
//populate master list here (emit data changed for each master and
|
||||
//each item (other than the dropped item) which share each of the masters
|
||||
file->masters().append(masterList);
|
||||
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case Qt::UserRole + 1:
|
||||
{
|
||||
EsmFile *file = item(index.row());
|
||||
//set file's checkstate to the passed checkstate
|
||||
emit dataChanged(index, index);
|
||||
|
||||
for (int i = 0; i < mFiles.size(); ++i)
|
||||
if (mFiles.at(i)->getMasters().contains(file->fileName()))
|
||||
emit dataChanged(QAbstractTableModel::index(i,0), QAbstractTableModel::index(i,0));
|
||||
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case Qt::CheckStateRole:
|
||||
{
|
||||
EsmFile *file = item(index.row());
|
||||
|
||||
if ((value.toInt() == Qt::Checked) && !file->isChecked())
|
||||
file->setChecked(true);
|
||||
else if (value.toInt() == Qt::Checked && file->isChecked())
|
||||
file->setChecked(false);
|
||||
else if (value.toInt() == Qt::UnChecked)
|
||||
file->setChecked(false);
|
||||
|
||||
emit dataChanged(index, index);
|
||||
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EsxModel::DataFilesModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
if (parent.isValid())
|
||||
return false;
|
||||
|
||||
beginInsertRows(QModelIndex(),row, row+count-1);
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
mFiles.insert(row, new EsmFile());
|
||||
} endInsertRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EsxModel::DataFilesModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
if (parent.isValid())
|
||||
return false;
|
||||
|
||||
beginRemoveRows(QModelIndex(), row, row+count-1);
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
delete mFiles.takeAt(row);
|
||||
} endRemoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Qt::DropActions EsxModel::DataFilesModel::supportedDropActions() const
|
||||
{
|
||||
return Qt::CopyAction | Qt::MoveAction;
|
||||
}
|
||||
|
||||
QStringList EsxModel::DataFilesModel::mimeTypes() const
|
||||
{
|
||||
QStringList types;
|
||||
types << "application/omwcontent";
|
||||
return types;
|
||||
}
|
||||
|
||||
QMimeData *EsxModel::DataFilesModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
QMimeData *mimeData = new QMimeData();
|
||||
QByteArray encodedData;
|
||||
|
||||
QDataStream stream (&encodedData, QIODevice::WriteOnly);
|
||||
|
||||
foreach (const QModelIndex &index, indexes)
|
||||
{
|
||||
if (index.isValid())
|
||||
{
|
||||
EsmFile *file = item (index.row());
|
||||
|
||||
for (int i = 0; i < file->propertyCount(); ++i)
|
||||
stream << data(index, Qt::DisplayRole).toString();
|
||||
|
||||
EsmFile *file = item(index.row());
|
||||
stream << file->getMasters();
|
||||
}
|
||||
}
|
||||
|
||||
mimeData->setData("application/omwcontent", encodedData);
|
||||
|
||||
return mimeData;
|
||||
}
|
||||
|
||||
bool EsxModel::DataFilesModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
||||
{
|
||||
if (action == Qt::IgnoreAction)
|
||||
return true;
|
||||
|
||||
if (action != Qt::MoveAction)
|
||||
return false;
|
||||
|
||||
if (!data->hasFormat("application/omwcontent"))
|
||||
return false;
|
||||
|
||||
int dropRow = row;
|
||||
|
||||
if (dropRow == -1)
|
||||
{
|
||||
if (parent.isValid())
|
||||
dropRow = parent.row();
|
||||
else
|
||||
dropRow = rowCount(QModelIndex());
|
||||
}
|
||||
|
||||
if (parent.isValid())
|
||||
qDebug() << "parent: " << parent.data().toString();
|
||||
qDebug() << "dragged file: " << (qobject_cast<const EsmFile *>(data))->fileName();
|
||||
// qDebug() << "inserting file: " << droppedfile->fileName() << " ahead of " << file->fileName();
|
||||
insertRows (dropRow, 1, QModelIndex());
|
||||
|
||||
|
||||
const EsmFile *draggedFile = qobject_cast<const EsmFile *>(data);
|
||||
|
||||
int dragRow = -1;
|
||||
|
||||
for (int i = 0; i < mFiles.size(); ++i)
|
||||
if (draggedFile->fileName() == mFiles.at(i)->fileName())
|
||||
{
|
||||
dragRow = i;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < mFiles.count(); ++i)
|
||||
{
|
||||
qDebug() << "index: " << i << "file: " << item(i)->fileName();
|
||||
qDebug() << mFiles.at(i)->fileName();
|
||||
}
|
||||
|
||||
qDebug() << "drop row: " << dropRow << "; drag row: " << dragRow;
|
||||
// const EsmFile *file = qobject_cast<const EsmFile *>(data);
|
||||
// int index = mFiles.indexOf(file);
|
||||
//qDebug() << "file name: " << file->fileName() << "; index: " << index;
|
||||
mFiles.swap(dropRow, dragRow);
|
||||
//setData(index(startRow, 0), varFile);
|
||||
emit dataChanged(index(0,0), index(rowCount(),0));
|
||||
return true;
|
||||
}
|
||||
|
||||
void EsxModel::DataFilesModel::setEncoding(const QString &encoding)
|
||||
{
|
||||
mEncoding = encoding;
|
||||
@ -51,17 +385,6 @@ Qt::CheckState EsxModel::DataFilesModel::checkState(const QModelIndex &index)
|
||||
return mCheckStates[item(index.row())->fileName()];
|
||||
}
|
||||
|
||||
int EsxModel::DataFilesModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : 1;
|
||||
}
|
||||
|
||||
int EsxModel::DataFilesModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : mFiles.count();
|
||||
}
|
||||
|
||||
|
||||
bool EsxModel::DataFilesModel::moveRow(int oldrow, int row, const QModelIndex &parent)
|
||||
{
|
||||
if (oldrow < 0 || row < 0 || oldrow == row)
|
||||
@ -76,124 +399,6 @@ bool EsxModel::DataFilesModel::moveRow(int oldrow, int row, const QModelIndex &p
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant EsxModel::DataFilesModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
const EsmFile *file = item(index.row());
|
||||
|
||||
if (!file)
|
||||
return QVariant();
|
||||
|
||||
const int column = index.column();
|
||||
|
||||
switch (role) {
|
||||
case Qt::EditRole:
|
||||
case Qt::DisplayRole: {
|
||||
|
||||
switch (column) {
|
||||
case 0:
|
||||
return file->fileName();
|
||||
case 1:
|
||||
return file->author();
|
||||
case 2:
|
||||
return QString("%1 kB").arg(int((file->size() + 1023) / 1024));
|
||||
case 3:
|
||||
//return file->modified().toString(Qt::TextDate);
|
||||
return file->modified().toString(Qt::ISODate);
|
||||
case 4:
|
||||
return file->accessed().toString(Qt::TextDate);
|
||||
case 5:
|
||||
return file->version();
|
||||
case 6:
|
||||
return file->path();
|
||||
case 7:
|
||||
return file->masters().join(", ");
|
||||
case 8:
|
||||
return file->description();
|
||||
}
|
||||
}
|
||||
|
||||
case Qt::TextAlignmentRole: {
|
||||
switch (column) {
|
||||
case 0:
|
||||
case 1:
|
||||
return Qt::AlignLeft + Qt::AlignVCenter;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
return Qt::AlignRight + Qt::AlignVCenter;
|
||||
default:
|
||||
return Qt::AlignLeft + Qt::AlignVCenter;
|
||||
}
|
||||
}
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
{
|
||||
if (column != 0)
|
||||
return QVariant();
|
||||
|
||||
if (file->version() == 0.0f)
|
||||
return QVariant(); // Data not set
|
||||
|
||||
QString tooltip =
|
||||
QString("<b>Author:</b> %1<br/> \
|
||||
<b>Version:</b> %2<br/> \
|
||||
<br/><b>Description:</b><br/>%3<br/> \
|
||||
<br/><b>Dependencies: </b>%4<br/>")
|
||||
.arg(file->author())
|
||||
.arg(QString::number(file->version()))
|
||||
.arg(file->description())
|
||||
.arg(file->masters().join(", "));
|
||||
|
||||
|
||||
return tooltip;
|
||||
|
||||
}
|
||||
|
||||
case Qt::UserRole:
|
||||
{
|
||||
if (file->masters().size() == 0)
|
||||
return "game";
|
||||
else
|
||||
return "addon";
|
||||
}
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Qt::ItemFlags EsxModel::DataFilesModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
const EsmFile *file = item(index.row());
|
||||
|
||||
Qt::ItemFlags dragDropFlags = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
||||
Qt::ItemFlags checkFlags = Qt::ItemIsUserCheckable | Qt::ItemIsSelectable;
|
||||
|
||||
if (!file)
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
if (canBeChecked(file))
|
||||
{
|
||||
if (index.column() == 0)
|
||||
return dragDropFlags | checkFlags | Qt::ItemIsEnabled;
|
||||
else
|
||||
return Qt::ItemIsDropEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
if (index.column() == 0)
|
||||
return dragDropFlags | checkFlags;
|
||||
|
||||
return Qt::ItemIsDropEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
QVariant EsxModel::DataFilesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
@ -215,22 +420,6 @@ QVariant EsxModel::DataFilesModel::headerData(int section, Qt::Orientation orien
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool EsxModel::DataFilesModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid())
|
||||
return false;
|
||||
|
||||
if (role == Qt::EditRole)
|
||||
{
|
||||
qDebug() << "replacing: " << mFiles.at(index.row())->fileName();
|
||||
// mFiles.replace(index.row(), value.value<const EsxModel::EsmFile *>());
|
||||
qDebug() << "with: " << mFiles.at(index.row())->fileName();
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!
|
||||
bool lessThanEsmFile(const EsxModel::EsmFile *e1, const EsxModel::EsmFile *e2)
|
||||
{
|
||||
@ -345,32 +534,6 @@ QModelIndex EsxModel::DataFilesModel::indexFromItem(const EsmFile *item) const
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
const EsxModel::EsmFile* EsxModel::DataFilesModel::findItem(const QString &name)
|
||||
{
|
||||
EsmFileList::ConstIterator it;
|
||||
EsmFileList::ConstIterator itEnd = mFiles.constEnd();
|
||||
|
||||
int i = 0;
|
||||
for (it = mFiles.constBegin(); it != itEnd; ++it) {
|
||||
const EsmFile *file = item(i);
|
||||
++i;
|
||||
|
||||
if (name == file->fileName())
|
||||
return file;
|
||||
}
|
||||
|
||||
// Not found
|
||||
return 0;
|
||||
}
|
||||
|
||||
const EsxModel::EsmFile* EsxModel::DataFilesModel::item(int row) const
|
||||
{
|
||||
if (row >= 0 && row < mFiles.count())
|
||||
return mFiles.at(row);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EsxModel::EsmFileList EsxModel::DataFilesModel::checkedItems()
|
||||
{
|
||||
EsmFileList list;
|
||||
@ -443,110 +606,3 @@ bool EsxModel::DataFilesModel::canBeChecked(const EsmFile *file) const
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Qt::DropActions EsxModel::DataFilesModel::supportedDropActions() const
|
||||
{
|
||||
return Qt::CopyAction | Qt::MoveAction;
|
||||
}
|
||||
|
||||
QStringList EsxModel::DataFilesModel::mimeTypes() const
|
||||
{
|
||||
QStringList types;
|
||||
types << "application/omwcontent";
|
||||
return types;
|
||||
}
|
||||
|
||||
QMimeData *EsxModel::DataFilesModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
// if (indexes.at(0).isValid())
|
||||
// return new EsmFile(*item(indexes.at(0).row()));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool EsxModel::DataFilesModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
||||
{
|
||||
if (action == Qt::IgnoreAction)
|
||||
return true;
|
||||
|
||||
if (action != Qt::MoveAction)
|
||||
return false;
|
||||
|
||||
if (!data->hasFormat("application/omwcontent"))
|
||||
return false;
|
||||
|
||||
int dropRow = row;
|
||||
|
||||
if (dropRow == -1)
|
||||
{
|
||||
if (parent.isValid())
|
||||
dropRow = parent.row();
|
||||
else
|
||||
dropRow = rowCount(QModelIndex());
|
||||
}
|
||||
|
||||
if (parent.isValid())
|
||||
qDebug() << "parent: " << parent.data().toString();
|
||||
qDebug() << "dragged file: " << (qobject_cast<const EsmFile *>(data))->fileName();
|
||||
// qDebug() << "inserting file: " << droppedfile->fileName() << " ahead of " << file->fileName();
|
||||
insertRows (dropRow, 1, QModelIndex());
|
||||
|
||||
|
||||
const EsmFile *draggedFile = qobject_cast<const EsmFile *>(data);
|
||||
|
||||
int dragRow = -1;
|
||||
|
||||
for (int i = 0; i < mFiles.size(); ++i)
|
||||
if (draggedFile->fileName() == mFiles.at(i)->fileName())
|
||||
{
|
||||
dragRow = i;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < mFiles.count(); ++i)
|
||||
{
|
||||
qDebug() << "index: " << i << "file: " << item(i)->fileName();
|
||||
qDebug() << mFiles.at(i)->fileName();
|
||||
}
|
||||
|
||||
qDebug() << "drop row: " << dropRow << "; drag row: " << dragRow;
|
||||
// const EsmFile *file = qobject_cast<const EsmFile *>(data);
|
||||
// int index = mFiles.indexOf(file);
|
||||
//qDebug() << "file name: " << file->fileName() << "; index: " << index;
|
||||
mFiles.swap(dropRow, dragRow);
|
||||
//setData(index(startRow, 0), varFile);
|
||||
emit dataChanged(index(0,0), index(rowCount(),0));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EsxModel::DataFilesModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
qDebug() << "inserting row: " << row << " count: " << count;
|
||||
beginInsertRows(QModelIndex(),row, row+count-1);
|
||||
|
||||
EsmFile *file = new EsmFile();
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
mFiles.insert(row + i, file);
|
||||
|
||||
endInsertRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EsxModel::DataFilesModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
qDebug() << "removing row: " << row << " count: " << count;
|
||||
beginRemoveRows(QModelIndex(), row, row+count-1);
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
mFiles.removeAt(i);
|
||||
}
|
||||
|
||||
endRemoveRows();
|
||||
qDebug() <<"remove success";
|
||||
|
||||
emit dataChanged(parent, index(rowCount()-1, 0, parent));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,12 @@
|
||||
#include "esmfile.hpp"
|
||||
|
||||
#include <QMimeData>
|
||||
#include <QDataStream>
|
||||
|
||||
int EsxModel::EsmFile::sPropertyCount = 7;
|
||||
|
||||
EsxModel::EsmFile::EsmFile(QString fileName, ModelItem *parent)
|
||||
: ModelItem(parent), mFileName(fileName), mSize(0), mVersion(0.0f)
|
||||
: ModelItem(parent), mFileName(fileName), mVersion(0.0f)
|
||||
{}
|
||||
/*
|
||||
EsxModel::EsmFile::EsmFile(const EsmFile &file)
|
||||
@ -22,15 +27,9 @@ void EsxModel::EsmFile::setAuthor(const QString &author)
|
||||
mAuthor = author;
|
||||
}
|
||||
|
||||
void EsxModel::EsmFile::setSize(const int size)
|
||||
{
|
||||
mSize = size;
|
||||
}
|
||||
|
||||
void EsxModel::EsmFile::setDates(const QDateTime &modified, const QDateTime &accessed)
|
||||
void EsxModel::EsmFile::setDate(const QDateTime &modified)
|
||||
{
|
||||
mModified = modified;
|
||||
mAccessed = accessed;
|
||||
}
|
||||
|
||||
void EsxModel::EsmFile::setVersion(float version)
|
||||
@ -52,3 +51,52 @@ void EsxModel::EsmFile::setDescription(const QString &description)
|
||||
{
|
||||
mDescription = description;
|
||||
}
|
||||
|
||||
QByteArray EsxModel::EsmFile::encodedData() const
|
||||
{
|
||||
QByteArray encodedData;
|
||||
QDataStream stream(&encodedData, QIODevice::WriteOnly);
|
||||
|
||||
stream << mFileName << mAuthor << QString::number(mVersion)
|
||||
<< mModified.toString() << mPath << mDescription
|
||||
<< mMasters;
|
||||
|
||||
return encodedData;
|
||||
}
|
||||
|
||||
void EsxModel::EsmFile::setProperty (const EsmFileProperty prop, const QString &value)
|
||||
{
|
||||
switch (prop)
|
||||
{
|
||||
case Property_FileName:
|
||||
mFileName = value;
|
||||
break;
|
||||
|
||||
case Property_Author:
|
||||
mAuthor = value;
|
||||
break;
|
||||
|
||||
case Property_Version:
|
||||
mVersion = value.toFloat();
|
||||
break;
|
||||
|
||||
case Property_DateModified:
|
||||
mModified = QDateTime::fromString(value);
|
||||
break;
|
||||
|
||||
case Property_Path:
|
||||
mPath = value;
|
||||
break;
|
||||
|
||||
case Property_Description:
|
||||
mDescription = value;
|
||||
break;
|
||||
|
||||
case Property_Master:
|
||||
mMasters << value;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,21 @@
|
||||
|
||||
#include "modelitem.hpp"
|
||||
|
||||
class QMimeData;
|
||||
|
||||
namespace EsxModel
|
||||
{
|
||||
enum EsmFileProperty
|
||||
{
|
||||
Property_FileName = 0,
|
||||
Property_Author = 1,
|
||||
Property_Version = 2,
|
||||
Property_DateModified = 3,
|
||||
Property_Path = 4,
|
||||
Property_Description = 5,
|
||||
Property_Master = 6
|
||||
};
|
||||
|
||||
class EsmFile : public ModelItem
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -21,10 +34,12 @@ namespace EsxModel
|
||||
~EsmFile()
|
||||
{}
|
||||
|
||||
void setProperty (const EsmFileProperty prop, const QString &value);
|
||||
|
||||
void setFileName(const QString &fileName);
|
||||
void setAuthor(const QString &author);
|
||||
void setSize(const int size);
|
||||
void setDates(const QDateTime &modified, const QDateTime &accessed);
|
||||
void setDate(const QDateTime &modified);
|
||||
void setVersion(const float version);
|
||||
void setPath(const QString &path);
|
||||
void setMasters(const QStringList &masters);
|
||||
@ -32,22 +47,23 @@ namespace EsxModel
|
||||
|
||||
inline QString fileName() const { return mFileName; }
|
||||
inline QString author() const { return mAuthor; }
|
||||
inline int size() const { return mSize; }
|
||||
inline QDateTime modified() const { return mModified; }
|
||||
inline QDateTime accessed() const { return mAccessed; }
|
||||
inline float version() const { return mVersion; }
|
||||
inline QString path() const { return mPath; }
|
||||
inline QStringList masters() const { return mMasters; }
|
||||
inline QString description() const { return mDescription; }
|
||||
|
||||
//inline ModelItem *parent() const { return ModelItem::parent(); this->}
|
||||
inline bool isMaster() const { return (mMasters.size() == 0); }
|
||||
QByteArray encodedData() const;
|
||||
|
||||
public:
|
||||
static int sPropertyCount;
|
||||
|
||||
private:
|
||||
|
||||
QString mFileName;
|
||||
QString mAuthor;
|
||||
int mSize;
|
||||
QDateTime mModified;
|
||||
QDateTime mAccessed;
|
||||
float mVersion;
|
||||
QString mPath;
|
||||
QStringList mMasters;
|
||||
|
@ -10,35 +10,4 @@ EsxModel::MasterProxyModel::MasterProxyModel(QObject *parent, QAbstractTableMode
|
||||
|
||||
if (model)
|
||||
setSourceModel (model);
|
||||
//connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(slotSourceModelChanged(QModelIndex, QModelIndex)));
|
||||
}
|
||||
/*
|
||||
QVariant EsxModel::MasterProxyModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (index.isValid())
|
||||
return QSortFilterProxyModel::data (index, role);
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
void EsxModel::MasterProxyModel::slotSourceModelChanged(QModelIndex topLeft, QModelIndex botRight)
|
||||
{
|
||||
qDebug() << "source data changed.. updating master proxy";
|
||||
emit dataChanged(index(0,0), index(rowCount()-1,0));
|
||||
|
||||
int curRow = -1;
|
||||
/*
|
||||
for (int i = 0; i < rowCount() - 1; ++i)
|
||||
{
|
||||
if (index(i,0).data(Qt::CheckState) == Qt::Checked)
|
||||
{
|
||||
curRow = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
reset();
|
||||
*/
|
||||
if (curRow != -1);
|
||||
// index(curRow, 0).setDataQt::CheckState)
|
||||
}
|
||||
|
@ -12,29 +12,3 @@ EsxModel::PluginsProxyModel::PluginsProxyModel(QObject *parent, ContentModel *mo
|
||||
if (model)
|
||||
setSourceModel (model);
|
||||
}
|
||||
|
||||
EsxModel::PluginsProxyModel::~PluginsProxyModel()
|
||||
{
|
||||
}
|
||||
|
||||
QVariant EsxModel::PluginsProxyModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
switch (role)
|
||||
{
|
||||
case Qt::CheckStateRole:
|
||||
{
|
||||
if (index.column() != 0)
|
||||
return QVariant();
|
||||
|
||||
return static_cast<ContentModel *>(sourceModel())->checkState(mapToSource(index));
|
||||
}
|
||||
}
|
||||
return QSortFilterProxyModel::data(index, role);
|
||||
}
|
||||
|
||||
bool EsxModel::PluginsProxyModel::removeRows(int position, int rows, const QModelIndex &parent)
|
||||
{
|
||||
bool success = QSortFilterProxyModel::removeRows(position, rows, parent);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include "contentselector.hpp"
|
||||
|
||||
#include "../model/datafilesmodel.hpp"
|
||||
#include "../model/masterproxymodel.hpp"
|
||||
#include "../model/pluginsproxymodel.hpp"
|
||||
#include "../model/contentmodel.hpp"
|
||||
#include "../model/esmfile.hpp"
|
||||
|
||||
@ -16,55 +14,73 @@ EsxView::ContentSelector::ContentSelector(QWidget *parent) :
|
||||
QDialog(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
// buildModelsAndViews();
|
||||
buildDragDropModelView();
|
||||
|
||||
buildSourceModel();
|
||||
buildMasterView();
|
||||
buildPluginsView();
|
||||
buildProfilesView();
|
||||
|
||||
updateViews();
|
||||
|
||||
}
|
||||
void EsxView::ContentSelector::buildDragDropModelView()
|
||||
|
||||
void EsxView::ContentSelector::buildSourceModel()
|
||||
{
|
||||
mContentModel = new EsxModel::ContentModel();
|
||||
connect(mContentModel, SIGNAL(layoutChanged()), this, SLOT(updateViews()));
|
||||
}
|
||||
|
||||
//mContentModel->addFiles("/home/joel/Projects/OpenMW/Data_Files");
|
||||
mMasterProxyModel = new EsxModel::MasterProxyModel(this, mContentModel);
|
||||
mPluginsProxyModel = new EsxModel::PluginsProxyModel(this, mContentModel);
|
||||
|
||||
tableView->setModel (mPluginsProxyModel);
|
||||
void EsxView::ContentSelector::buildMasterView()
|
||||
{
|
||||
mMasterProxyModel = new QSortFilterProxyModel(this);
|
||||
mMasterProxyModel->setFilterRegExp(QString("game"));
|
||||
mMasterProxyModel->setFilterRole (Qt::UserRole);
|
||||
mMasterProxyModel->setSourceModel (mContentModel);
|
||||
|
||||
masterView->setPlaceholderText(QString("Select a game file..."));
|
||||
masterView->setModel(mMasterProxyModel);
|
||||
|
||||
connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int)));
|
||||
|
||||
masterView->setCurrentIndex(-1);
|
||||
masterView->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
void EsxView::ContentSelector::buildPluginsView()
|
||||
{
|
||||
mPluginsProxyModel = new QSortFilterProxyModel(this);
|
||||
mPluginsProxyModel->setFilterRegExp (QString("addon"));
|
||||
mPluginsProxyModel->setFilterRole (Qt::UserRole);
|
||||
mPluginsProxyModel->setDynamicSortFilter (true);
|
||||
mPluginsProxyModel->setSourceModel (mContentModel);
|
||||
|
||||
tableView->setModel (mPluginsProxyModel);
|
||||
pluginView->setModel(mPluginsProxyModel);
|
||||
|
||||
profilesComboBox->setPlaceholderText(QString("Select a profile..."));
|
||||
|
||||
updateViews();
|
||||
connect(pluginView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &)));
|
||||
connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int)));
|
||||
connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int)));
|
||||
|
||||
|
||||
connect(mContentModel, SIGNAL(layoutChanged()), this, SLOT(updateViews()));
|
||||
connect(tableView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &)));
|
||||
}
|
||||
|
||||
void EsxView::ContentSelector::buildModelsAndViews()
|
||||
void EsxView::ContentSelector::buildProfilesView()
|
||||
{
|
||||
// Models
|
||||
mDataFilesModel = new EsxModel::DataFilesModel (this);
|
||||
|
||||
// mMasterProxyModel = new EsxModel::MasterProxyModel (this, mDataFilesModel);
|
||||
// mPluginsProxyModel = new EsxModel::PluginsProxyModel (this, mDataFilesModel);
|
||||
|
||||
masterView->setPlaceholderText(QString("Select a game file..."));
|
||||
masterView->setModel(mMasterProxyModel);
|
||||
pluginView->setModel(mPluginsProxyModel);
|
||||
profilesComboBox->setPlaceholderText(QString("Select a profile..."));
|
||||
|
||||
updateViews();
|
||||
connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews()));
|
||||
connect(pluginView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &)));
|
||||
connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int)));
|
||||
connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int)));
|
||||
}
|
||||
|
||||
void EsxView::ContentSelector::updateViews()
|
||||
{
|
||||
// Ensure the columns are hidden because sort() re-enables them
|
||||
pluginView->setColumnHidden(1, true);
|
||||
pluginView->setColumnHidden(2, true);
|
||||
pluginView->setColumnHidden(3, true);
|
||||
pluginView->setColumnHidden(4, true);
|
||||
pluginView->setColumnHidden(5, true);
|
||||
pluginView->setColumnHidden(6, true);
|
||||
pluginView->setColumnHidden(7, true);
|
||||
pluginView->setColumnHidden(8, true);
|
||||
pluginView->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
void EsxView::ContentSelector::addFiles(const QString &path)
|
||||
{
|
||||
mContentModel->addFiles(path);
|
||||
@ -78,24 +94,6 @@ void EsxView::ContentSelector::setEncoding(const QString &encoding)
|
||||
mContentModel->setEncoding(encoding);
|
||||
}
|
||||
|
||||
void EsxView::ContentSelector::setCheckState(QModelIndex index, QSortFilterProxyModel *model)
|
||||
{
|
||||
if (!index.isValid())
|
||||
return;
|
||||
|
||||
if (!model)
|
||||
return;
|
||||
|
||||
QModelIndex sourceIndex = model->mapToSource(index);
|
||||
|
||||
if (sourceIndex.isValid())
|
||||
{
|
||||
(mContentModel->checkState(sourceIndex) == Qt::Checked)
|
||||
? mContentModel->setCheckState(sourceIndex, Qt::Unchecked)
|
||||
: mContentModel->setCheckState(sourceIndex, Qt::Checked);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList EsxView::ContentSelector::checkedItemsPaths()
|
||||
{
|
||||
QStringList itemPaths;
|
||||
@ -106,21 +104,6 @@ QStringList EsxView::ContentSelector::checkedItemsPaths()
|
||||
return itemPaths;
|
||||
}
|
||||
|
||||
void EsxView::ContentSelector::updateViews()
|
||||
{
|
||||
// Ensure the columns are hidden because sort() re-enables them
|
||||
pluginView->setColumnHidden(1, true);
|
||||
pluginView->setColumnHidden(2, true);
|
||||
pluginView->setColumnHidden(3, true);
|
||||
pluginView->setColumnHidden(4, true);
|
||||
pluginView->setColumnHidden(5, true);
|
||||
pluginView->setColumnHidden(6, true);
|
||||
pluginView->setColumnHidden(7, true);
|
||||
pluginView->setColumnHidden(8, true);
|
||||
pluginView->resizeColumnsToContents();
|
||||
|
||||
}
|
||||
|
||||
void EsxView::ContentSelector::slotCurrentProfileIndexChanged(int index)
|
||||
{
|
||||
emit profileChanged(index);
|
||||
@ -128,17 +111,40 @@ void EsxView::ContentSelector::slotCurrentProfileIndexChanged(int index)
|
||||
|
||||
void EsxView::ContentSelector::slotCurrentMasterIndexChanged(int index)
|
||||
{
|
||||
QObject *object = QObject::sender();
|
||||
static int oldIndex = -1;
|
||||
|
||||
// Not a signal-slot call
|
||||
if (!object)
|
||||
return;
|
||||
QAbstractItemModel *const model = masterView->model();
|
||||
QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(model);
|
||||
|
||||
setCheckState(mMasterProxyModel->index(index, 0), mMasterProxyModel);
|
||||
if (proxy)
|
||||
proxy->setDynamicSortFilter(false);
|
||||
|
||||
if (oldIndex > -1)
|
||||
model->setData(model->index(oldIndex, 0), false, Qt::UserRole + 1);
|
||||
|
||||
oldIndex = index;
|
||||
|
||||
model->setData(model->index(index, 0), true, Qt::UserRole + 1);
|
||||
|
||||
if (proxy)
|
||||
proxy->setDynamicSortFilter(true);
|
||||
}
|
||||
|
||||
void EsxView::ContentSelector::slotPluginTableItemClicked(const QModelIndex &index)
|
||||
{
|
||||
qDebug() << "setting checkstate in plugin...";
|
||||
setCheckState(index, mPluginsProxyModel);
|
||||
|
||||
QAbstractItemModel *const model = pluginView->model();
|
||||
QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(model);
|
||||
|
||||
if (proxy)
|
||||
proxy->setDynamicSortFilter(false);
|
||||
|
||||
if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked)
|
||||
model->setData(index, Qt::Checked, Qt::CheckStateRole);
|
||||
else
|
||||
model->setData(index, Qt::Unchecked, Qt::CheckStateRole);
|
||||
|
||||
if (proxy)
|
||||
proxy->setDynamicSortFilter(true);
|
||||
}
|
||||
|
@ -9,8 +9,6 @@ namespace EsxModel
|
||||
{
|
||||
class ContentModel;
|
||||
class DataFilesModel;
|
||||
class PluginsProxyModel;
|
||||
class MasterProxyModel;
|
||||
}
|
||||
|
||||
class QSortFilterProxyModel;
|
||||
@ -25,8 +23,8 @@ namespace EsxView
|
||||
|
||||
EsxModel::DataFilesModel *mDataFilesModel;
|
||||
EsxModel::ContentModel *mContentModel;
|
||||
EsxModel::MasterProxyModel *mMasterProxyModel;
|
||||
EsxModel::PluginsProxyModel *mPluginsProxyModel;
|
||||
QSortFilterProxyModel *mMasterProxyModel;
|
||||
QSortFilterProxyModel *mPluginsProxyModel;
|
||||
|
||||
public:
|
||||
explicit ContentSelector(QWidget *parent = 0);
|
||||
@ -39,7 +37,12 @@ namespace EsxView
|
||||
void setCheckState(QModelIndex index, QSortFilterProxyModel *model);
|
||||
QStringList checkedItemsPaths();
|
||||
void on_checkAction_triggered();
|
||||
void buildDragDropModelView();
|
||||
|
||||
private:
|
||||
void buildSourceModel();
|
||||
void buildMasterView();
|
||||
void buildPluginsView();
|
||||
void buildProfilesView();
|
||||
|
||||
signals:
|
||||
void profileChanged(int index);
|
||||
|
Loading…
x
Reference in New Issue
Block a user