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"
|
||||
|
||||
//DataFilesModel::DataFilesModel(const QString &data, 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) {
|
||||
if (index.column() == 2) {
|
||||
QFileIconProvider fip;
|
||||
QIcon fileIcon = fip.icon(fileInfo(index));
|
||||
return fileIcon;
|
||||
}
|
||||
else {
|
||||
return QIcon();
|
||||
}
|
||||
delete rootItem;
|
||||
}
|
||||
|
||||
}
|
||||
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) {
|
||||
if (index.column() == 2) {
|
||||
//qDebug() << index.data(Qt::DisplayRole);
|
||||
if (fileInfo(index).suffix().toLower() == "esp") {
|
||||
return QString("Plugin File");
|
||||
}
|
||||
else if (fileInfo(index).suffix().toLower() == "esm") {
|
||||
return QString("Master File");
|
||||
QVariant DataFilesModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
if (index.isValid() && role == Qt::CheckStateRole && index.column() == 0) {
|
||||
// Put a checkbox in the first column
|
||||
if (index.isValid())
|
||||
DataFilesItem *item = static_cast<DataFilesItem*>(index.internalPointer());
|
||||
|
||||
if (checkedItems.contains(filePath(index))) {
|
||||
// if (checkedItems.contains(index)) {
|
||||
return Qt::Checked;
|
||||
}
|
||||
else {
|
||||
return Qt::Unchecked;
|
||||
}
|
||||
}
|
||||
return QFileSystemModel::data(index, role);
|
||||
return item->data(index.column());
|
||||
}
|
||||
|
||||
bool DataFilesModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||
Qt::ItemFlags DataFilesModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
if (index.isValid() && role == Qt::CheckStateRole && index.column() == 0) {
|
||||
// QPersistentModelIndex pindex(index);
|
||||
|
||||
// qDebug() << pindex;
|
||||
|
||||
if (value == Qt::Checked) {
|
||||
//checkedItems.insert(pindex);
|
||||
checkedItems.append(filePath(index));
|
||||
} else {
|
||||
// checkedItems.remove(pindex);
|
||||
checkedItems.removeAll(filePath(index));
|
||||
}
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
QVariant DataFilesModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||
return rootItem->data(section);
|
||||
|
||||
return QFileSystemModel::setData(index, value, role);
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QModelIndex DataFilesModel::index(int row, int column, const QModelIndex &parent)
|
||||
const
|
||||
{
|
||||
if (!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
|
||||
DataFilesItem *parentItem;
|
||||
|
||||
Qt::ItemFlags DataFilesModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
return QFileSystemModel::flags(index) | Qt::ItemIsUserCheckable;
|
||||
if (!parent.isValid())
|
||||
parentItem = rootItem;
|
||||
else
|
||||
parentItem = static_cast<DataFilesItem*>(parent.internalPointer());
|
||||
|
||||
DataFilesItem *childItem = parentItem->child(row);
|
||||
if (childItem)
|
||||
return createIndex(row, column, childItem);
|
||||
else
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex DataFilesModel::parent(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
DataFilesItem *childItem = static_cast<DataFilesItem*>(index.internalPointer());
|
||||
DataFilesItem *parentItem = childItem->parent();
|
||||
|
||||
/*QVariant DataFilesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
switch (role) {
|
||||
case Qt::DecorationRole:
|
||||
if (section == 0) {
|
||||
// ### TODO oh man this is ugly and doesn't even work all the way!
|
||||
// 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 (parentItem == rootItem)
|
||||
return QModelIndex();
|
||||
|
||||
if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
|
||||
return QAbstractItemModel::headerData(section, orientation, role);
|
||||
|
||||
QString returnValue;
|
||||
switch (section) {
|
||||
case 0: returnValue = tr("TES3 File");
|
||||
break;
|
||||
case 1: returnValue = tr("Size");
|
||||
break;
|
||||
case 2: returnValue = tr("Status");
|
||||
break;
|
||||
case 3: returnValue = tr("Date Modified");
|
||||
break;
|
||||
default: return QVariant();
|
||||
}
|
||||
return returnValue;
|
||||
return createIndex(parentItem->row(), 0, parentItem);
|
||||
}
|
||||
*/
|
||||
|
||||
/*test
|
||||
void DataFilesModel::setCheckedItems(const QStringList &gameFiles)
|
||||
int DataFilesModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
qDebug() << "test";
|
||||
qDebug() << gameFiles.join("lol");
|
||||
|
||||
DataFilesItem *parentItem;
|
||||
if (parent.column() > 0)
|
||||
return 0;
|
||||
|
||||
}*/
|
||||
if (!parent.isValid())
|
||||
parentItem = rootItem;
|
||||
else
|
||||
parentItem = static_cast<DataFilesItem*>(parent.internalPointer());
|
||||
|
||||
/*void DataFilesModel::unCheckAll()
|
||||
{
|
||||
checkedItems.clear();
|
||||
// data();
|
||||
emit dataChanged(QModelIndex(), QModelIndex());
|
||||
submit();
|
||||
}*/
|
||||
|
||||
const QStringList DataFilesModel::getCheckedItems()
|
||||
//const QList<QPersistentModelIndex> DataFilesModel::getCheckedItems()
|
||||
//const QSet<QPersistentModelIndex> DataFilesModel::getCheckedItems()
|
||||
{
|
||||
return checkedItems;
|
||||
return parentItem->childCount();
|
||||
}
|
||||
|
||||
/*void DataFilesModel::sort(int column, Qt::SortOrder order)
|
||||
/*void DataFilesModel::setupModelData(const QStringList &lines, DataFilesItem *parent)
|
||||
{
|
||||
qDebug() << "Sort!";
|
||||
}*/
|
||||
QList<DataFilesItem*> parents;
|
||||
QList<int> indentations;
|
||||
parents << parent;
|
||||
indentations << 0;
|
||||
|
||||
int number = 0;
|
||||
|
||||
while (number < lines.count()) {
|
||||
int position = 0;
|
||||
while (position < lines[number].length()) {
|
||||
if (lines[number].mid(position, 1) != " ")
|
||||
break;
|
||||
position++;
|
||||
}
|
||||
|
||||
QString lineData = lines[number].mid(position).trimmed();
|
||||
|
||||
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.
|
||||
|
||||
if (parents.last()->childCount() > 0) {
|
||||
parents << parents.last()->child(parents.last()->childCount()-1);
|
||||
indentations << position;
|
||||
}
|
||||
} else {
|
||||
while (position < indentations.last() && parents.count() > 0) {
|
||||
parents.pop_back();
|
||||
indentations.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
// Append a new item to the current parent's list of children.
|
||||
parents.last()->appendChild(new DataFilesItem(columnData, parents.last()));
|
||||
}
|
||||
|
||||
number++;
|
||||
}
|
||||
}*/
|
@ -1,38 +1,35 @@
|
||||
#ifndef DATAFILESMODEL_H
|
||||
#define DATAFILESMODEL_H
|
||||
|
||||
#include <QFileSystemModel>
|
||||
#include <QFileIconProvider>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QModelIndex>
|
||||
#include <QVariant>
|
||||
|
||||
#include <QDebug>
|
||||
class DataFilesItem;
|
||||
|
||||
class DataFilesModel : public QFileSystemModel
|
||||
class DataFilesModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//DataFilesModel(const QString &data, QObject *parent = 0);
|
||||
DataFilesModel(QObject *parent = 0);
|
||||
~DataFilesModel() {};
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
~DataFilesModel();
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
|
||||
// void sort(int column, Qt::SortOrder order);
|
||||
//test
|
||||
// void setCheckedItems(const QStringList& files);
|
||||
// void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||
// void unCheckAll();
|
||||
|
||||
// const QSet<QPersistentModelIndex> getCheckedItems();
|
||||
// const QList<QPersistentModelIndex> getCheckedItems();
|
||||
const QStringList getCheckedItems();
|
||||
|
||||
// QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
|
||||
// QSet<QPersistentModelIndex> checkedItems;
|
||||
// QList<QPersistentModelIndex> checkedItems;
|
||||
QStringList checkedItems;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
private:
|
||||
//void setupModelData(const QStringList &lines, TreeItem *parent);
|
||||
|
||||
DataFilesItem *rootItem;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in New Issue