mirror of https://github.com/OpenMW/openmw.git
Messing around with a new datafilesdialog
parent
082902473b
commit
74eef82902
@ -1,145 +1,155 @@
|
|||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
#include "datafilesitem.h"
|
||||||
#include "datafilesmodel.h"
|
#include "datafilesmodel.h"
|
||||||
|
|
||||||
|
//DataFilesModel::DataFilesModel(const QString &data, QObject *parent)
|
||||||
DataFilesModel::DataFilesModel(QObject *parent)
|
DataFilesModel::DataFilesModel(QObject *parent)
|
||||||
: QFileSystemModel(parent)
|
: QAbstractItemModel(parent)
|
||||||
{
|
{
|
||||||
|
QList<QVariant> rootData;
|
||||||
|
rootData << " ";
|
||||||
|
//rootItem = new DataFilesItem(rootData);
|
||||||
|
rootItem = new DataFilesItem(rootData);
|
||||||
|
//setupModelData(data.split(QString("\n")), rootItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DataFilesModel::data(const QModelIndex &index, int role) const
|
DataFilesModel::~DataFilesModel()
|
||||||
{
|
{
|
||||||
if (index.isValid() && role == Qt::DecorationRole) {
|
delete rootItem;
|
||||||
if (index.column() == 2) {
|
|
||||||
QFileIconProvider fip;
|
|
||||||
QIcon fileIcon = fip.icon(fileInfo(index));
|
|
||||||
return fileIcon;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return QIcon();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int DataFilesModel::columnCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
if (parent.isValid())
|
||||||
|
return static_cast<DataFilesItem*>(parent.internalPointer())->columnCount();
|
||||||
|
else
|
||||||
|
return rootItem->columnCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index.isValid() && role == Qt::DisplayRole) {
|
QVariant DataFilesModel::data(const QModelIndex &index, int role) const
|
||||||
if (index.column() == 2) {
|
{
|
||||||
//qDebug() << index.data(Qt::DisplayRole);
|
if (!index.isValid())
|
||||||
if (fileInfo(index).suffix().toLower() == "esp") {
|
return QVariant();
|
||||||
return QString("Plugin File");
|
|
||||||
}
|
|
||||||
else if (fileInfo(index).suffix().toLower() == "esm") {
|
|
||||||
return QString("Master File");
|
|
||||||
|
|
||||||
}
|
if (role != Qt::DisplayRole)
|
||||||
}
|
return QVariant();
|
||||||
}
|
|
||||||
|
|
||||||
if (index.isValid() && role == Qt::CheckStateRole && index.column() == 0) {
|
DataFilesItem *item = static_cast<DataFilesItem*>(index.internalPointer());
|
||||||
// Put a checkbox in the first column
|
|
||||||
if (index.isValid())
|
|
||||||
|
|
||||||
if (checkedItems.contains(filePath(index))) {
|
return item->data(index.column());
|
||||||
// if (checkedItems.contains(index)) {
|
|
||||||
return Qt::Checked;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return Qt::Unchecked;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags DataFilesModel::flags(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
}
|
}
|
||||||
return QFileSystemModel::data(index, role);
|
|
||||||
|
QVariant DataFilesModel::headerData(int section, Qt::Orientation orientation,
|
||||||
|
int role) const
|
||||||
|
{
|
||||||
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||||
|
return rootItem->data(section);
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DataFilesModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
QModelIndex DataFilesModel::index(int row, int column, const QModelIndex &parent)
|
||||||
|
const
|
||||||
{
|
{
|
||||||
|
if (!hasIndex(row, column, parent))
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
if (index.isValid() && role == Qt::CheckStateRole && index.column() == 0) {
|
DataFilesItem *parentItem;
|
||||||
// QPersistentModelIndex pindex(index);
|
|
||||||
|
|
||||||
// qDebug() << pindex;
|
if (!parent.isValid())
|
||||||
|
parentItem = rootItem;
|
||||||
|
else
|
||||||
|
parentItem = static_cast<DataFilesItem*>(parent.internalPointer());
|
||||||
|
|
||||||
if (value == Qt::Checked) {
|
DataFilesItem *childItem = parentItem->child(row);
|
||||||
//checkedItems.insert(pindex);
|
if (childItem)
|
||||||
checkedItems.append(filePath(index));
|
return createIndex(row, column, childItem);
|
||||||
} else {
|
else
|
||||||
// checkedItems.remove(pindex);
|
return QModelIndex();
|
||||||
checkedItems.removeAll(filePath(index));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit dataChanged(index, index);
|
QModelIndex DataFilesModel::parent(const QModelIndex &index) const
|
||||||
return true;
|
{
|
||||||
}
|
if (!index.isValid())
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
return QFileSystemModel::setData(index, value, role);
|
DataFilesItem *childItem = static_cast<DataFilesItem*>(index.internalPointer());
|
||||||
}
|
DataFilesItem *parentItem = childItem->parent();
|
||||||
|
|
||||||
|
if (parentItem == rootItem)
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
|
return createIndex(parentItem->row(), 0, parentItem);
|
||||||
|
}
|
||||||
|
|
||||||
Qt::ItemFlags DataFilesModel::flags(const QModelIndex &index) const
|
int DataFilesModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
return QFileSystemModel::flags(index) | Qt::ItemIsUserCheckable;
|
DataFilesItem *parentItem;
|
||||||
}
|
if (parent.column() > 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!parent.isValid())
|
||||||
|
parentItem = rootItem;
|
||||||
|
else
|
||||||
|
parentItem = static_cast<DataFilesItem*>(parent.internalPointer());
|
||||||
|
|
||||||
|
return parentItem->childCount();
|
||||||
|
}
|
||||||
|
|
||||||
/*QVariant DataFilesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
/*void DataFilesModel::setupModelData(const QStringList &lines, DataFilesItem *parent)
|
||||||
{
|
{
|
||||||
switch (role) {
|
QList<DataFilesItem*> parents;
|
||||||
case Qt::DecorationRole:
|
QList<int> indentations;
|
||||||
if (section == 0) {
|
parents << parent;
|
||||||
// ### TODO oh man this is ugly and doesn't even work all the way!
|
indentations << 0;
|
||||||
// it is still 2 pixels off
|
|
||||||
QImage pixmap(16, 1, QImage::Format_Mono);
|
|
||||||
pixmap.fill(0);
|
|
||||||
pixmap.setAlphaChannel(pixmap.createAlphaMask());
|
|
||||||
return pixmap;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Qt::TextAlignmentRole:
|
|
||||||
return Qt::AlignLeft;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
|
int number = 0;
|
||||||
return QAbstractItemModel::headerData(section, orientation, role);
|
|
||||||
|
|
||||||
QString returnValue;
|
while (number < lines.count()) {
|
||||||
switch (section) {
|
int position = 0;
|
||||||
case 0: returnValue = tr("TES3 File");
|
while (position < lines[number].length()) {
|
||||||
break;
|
if (lines[number].mid(position, 1) != " ")
|
||||||
case 1: returnValue = tr("Size");
|
|
||||||
break;
|
|
||||||
case 2: returnValue = tr("Status");
|
|
||||||
break;
|
break;
|
||||||
case 3: returnValue = tr("Date Modified");
|
position++;
|
||||||
break;
|
|
||||||
default: return QVariant();
|
|
||||||
}
|
|
||||||
return returnValue;
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*test
|
QString lineData = lines[number].mid(position).trimmed();
|
||||||
void DataFilesModel::setCheckedItems(const QStringList &gameFiles)
|
|
||||||
{
|
|
||||||
qDebug() << "test";
|
|
||||||
qDebug() << gameFiles.join("lol");
|
|
||||||
|
|
||||||
|
if (!lineData.isEmpty()) {
|
||||||
|
// Read the column data from the rest of the line.
|
||||||
|
QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts);
|
||||||
|
QList<QVariant> columnData;
|
||||||
|
for (int column = 0; column < columnStrings.count(); ++column)
|
||||||
|
columnData << columnStrings[column];
|
||||||
|
|
||||||
}*/
|
if (position > indentations.last()) {
|
||||||
|
// The last child of the current parent is now the new parent
|
||||||
|
// unless the current parent has no children.
|
||||||
|
|
||||||
/*void DataFilesModel::unCheckAll()
|
if (parents.last()->childCount() > 0) {
|
||||||
{
|
parents << parents.last()->child(parents.last()->childCount()-1);
|
||||||
checkedItems.clear();
|
indentations << position;
|
||||||
// data();
|
}
|
||||||
emit dataChanged(QModelIndex(), QModelIndex());
|
} else {
|
||||||
submit();
|
while (position < indentations.last() && parents.count() > 0) {
|
||||||
}*/
|
parents.pop_back();
|
||||||
|
indentations.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const QStringList DataFilesModel::getCheckedItems()
|
// Append a new item to the current parent's list of children.
|
||||||
//const QList<QPersistentModelIndex> DataFilesModel::getCheckedItems()
|
parents.last()->appendChild(new DataFilesItem(columnData, parents.last()));
|
||||||
//const QSet<QPersistentModelIndex> DataFilesModel::getCheckedItems()
|
|
||||||
{
|
|
||||||
return checkedItems;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void DataFilesModel::sort(int column, Qt::SortOrder order)
|
number++;
|
||||||
{
|
}
|
||||||
qDebug() << "Sort!";
|
|
||||||
}*/
|
}*/
|
@ -1,38 +1,35 @@
|
|||||||
#ifndef DATAFILESMODEL_H
|
#ifndef DATAFILESMODEL_H
|
||||||
#define DATAFILESMODEL_H
|
#define DATAFILESMODEL_H
|
||||||
|
|
||||||
#include <QFileSystemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QFileIconProvider>
|
#include <QModelIndex>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
#include <QDebug>
|
class DataFilesItem;
|
||||||
|
|
||||||
class DataFilesModel : public QFileSystemModel
|
class DataFilesModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
//DataFilesModel(const QString &data, QObject *parent = 0);
|
||||||
DataFilesModel(QObject *parent = 0);
|
DataFilesModel(QObject *parent = 0);
|
||||||
~DataFilesModel() {};
|
~DataFilesModel();
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
||||||
|
|
||||||
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation,
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
int role = Qt::DisplayRole) const;
|
||||||
|
QModelIndex index(int row, int column,
|
||||||
// void sort(int column, Qt::SortOrder order);
|
const QModelIndex &parent = QModelIndex()) const;
|
||||||
//test
|
QModelIndex parent(const QModelIndex &index) const;
|
||||||
// void setCheckedItems(const QStringList& files);
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
// void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
// void unCheckAll();
|
|
||||||
|
private:
|
||||||
// const QSet<QPersistentModelIndex> getCheckedItems();
|
//void setupModelData(const QStringList &lines, TreeItem *parent);
|
||||||
// const QList<QPersistentModelIndex> getCheckedItems();
|
|
||||||
const QStringList getCheckedItems();
|
DataFilesItem *rootItem;
|
||||||
|
|
||||||
// QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
|
||||||
|
|
||||||
// QSet<QPersistentModelIndex> checkedItems;
|
|
||||||
// QList<QPersistentModelIndex> checkedItems;
|
|
||||||
QStringList checkedItems;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue