mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 16:09:41 +00:00
Messing around with a new datafilesdialog
This commit is contained in:
parent
082902473b
commit
74eef82902
6 changed files with 225 additions and 242 deletions
|
@ -1,12 +1,14 @@
|
||||||
set(LAUNCHER
|
set(LAUNCHER
|
||||||
datafilesdialog.cpp
|
datafilesdialog.cpp
|
||||||
datafilesmodel.cpp
|
datafilesmodel.cpp
|
||||||
|
datafilesitem.cpp
|
||||||
lineedit.cpp
|
lineedit.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
maindialog.cpp
|
maindialog.cpp
|
||||||
settingsdialog.cpp
|
settingsdialog.cpp
|
||||||
datafilesdialog.h
|
datafilesdialog.h
|
||||||
datafilesmodel.h
|
datafilesmodel.h
|
||||||
|
datafilesitem.h
|
||||||
lineedit.h
|
lineedit.h
|
||||||
maindialog.h
|
maindialog.h
|
||||||
settingsdialog.h
|
settingsdialog.h
|
||||||
|
@ -14,6 +16,8 @@ set(LAUNCHER
|
||||||
|
|
||||||
SET(MOC_HDRS
|
SET(MOC_HDRS
|
||||||
datafilesdialog.h
|
datafilesdialog.h
|
||||||
|
datafilesmodel.h
|
||||||
|
datafilesitem.h
|
||||||
lineedit.h
|
lineedit.h
|
||||||
maindialog.h
|
maindialog.h
|
||||||
settingsdialog.h
|
settingsdialog.h
|
||||||
|
|
|
@ -3,27 +3,34 @@
|
||||||
|
|
||||||
#include "datafilesdialog.h"
|
#include "datafilesdialog.h"
|
||||||
#include "datafilesmodel.h"
|
#include "datafilesmodel.h"
|
||||||
|
#include "datafilesitem.h"
|
||||||
|
|
||||||
using namespace ESM;
|
using namespace ESM;
|
||||||
|
|
||||||
//DataFilesDialog::DataFilesDialog(QWidget *parent)
|
|
||||||
// : QDialog(parent)
|
|
||||||
|
|
||||||
DataFilesDialog::DataFilesDialog()
|
DataFilesDialog::DataFilesDialog()
|
||||||
{
|
{
|
||||||
//QWidget *centralWidget = new QWidget;
|
//dataFilesModel = new DataFilesModel(this);
|
||||||
|
|
||||||
dataFilesModel = new DataFilesModel();
|
dataFilesModel = new DataFilesModel();
|
||||||
dataFilesModel->setReadOnly(true); // Prevent changes to files
|
|
||||||
dataFilesModel->setRootPath("data");
|
for (int row = 0; row < 4; ++row) {
|
||||||
|
for (int column = 0; column < 4; ++column) {
|
||||||
|
QList<QVariant> test;
|
||||||
|
test << QString("%0").arg(i);
|
||||||
|
DataFilesItem *item = new DataFilesItem(test);
|
||||||
|
dataFilesModel->setItem(row, column, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//dataFilesModel->setReadOnly(true); // Prevent changes to files
|
||||||
|
//dataFilesModel->setRootPath("data");
|
||||||
|
|
||||||
// sortModel = new QSortFilterProxyModel();
|
// sortModel = new QSortFilterProxyModel();
|
||||||
// sortModel->setSourceModel(dataFilesModel);
|
// sortModel->setSourceModel(dataFilesModel);
|
||||||
|
|
||||||
selectionModel = new QItemSelectionModel(dataFilesModel);
|
//selectionModel = new QItemSelectionModel(dataFilesModel);
|
||||||
// selectionModel = new QItemSelectionModel(sortModel);
|
// selectionModel = new QItemSelectionModel(sortModel);
|
||||||
|
|
||||||
// First, show only plugin files and sort them
|
/* First, show only plugin files and sort them
|
||||||
QStringList acceptedfiles = (QStringList() << "*.esp");
|
QStringList acceptedfiles = (QStringList() << "*.esp");
|
||||||
dataFilesModel->setNameFilters(acceptedfiles);
|
dataFilesModel->setNameFilters(acceptedfiles);
|
||||||
dataFilesModel->setNameFilterDisables(false); // Hide all other files
|
dataFilesModel->setNameFilterDisables(false); // Hide all other files
|
||||||
|
@ -35,58 +42,33 @@ DataFilesDialog::DataFilesDialog()
|
||||||
acceptedfiles = (QStringList() << "*.esm" << "*.esp");
|
acceptedfiles = (QStringList() << "*.esm" << "*.esp");
|
||||||
dataFilesModel->setNameFilters(acceptedfiles);
|
dataFilesModel->setNameFilters(acceptedfiles);
|
||||||
dataFilesModel->setFilter(QDir::Files);
|
dataFilesModel->setFilter(QDir::Files);
|
||||||
|
*/
|
||||||
// Column 1
|
// Column 1
|
||||||
QVBoxLayout *dialogLayout = new QVBoxLayout(this);
|
QVBoxLayout *dialogLayout = new QVBoxLayout(this);
|
||||||
QHBoxLayout *groupsLayout = new QHBoxLayout();
|
|
||||||
|
|
||||||
QGroupBox *groupFiles = new QGroupBox(tr("Morrowind Files"), this);
|
QGroupBox *groupFiles = new QGroupBox(tr("Morrowind Files"), this);
|
||||||
groupFiles->setMinimumWidth(450);
|
groupFiles->setMinimumWidth(450);
|
||||||
QVBoxLayout *groupFilesLayout = new QVBoxLayout(groupFiles);
|
QVBoxLayout *groupFilesLayout = new QVBoxLayout(groupFiles);
|
||||||
|
|
||||||
QSpacerItem *vSpacer1 = new QSpacerItem(20, 2, QSizePolicy::Minimum, QSizePolicy::Fixed);
|
//QSpacerItem *vSpacer1 = new QSpacerItem(20, 2, QSizePolicy::Minimum, QSizePolicy::Fixed);
|
||||||
|
|
||||||
QHBoxLayout *filterLayout = new QHBoxLayout();
|
/*QHBoxLayout *filterLayout = new QHBoxLayout();
|
||||||
QLabel *labelFilter = new QLabel(tr("Filter:"), groupFiles);
|
QLabel *labelFilter = new QLabel(tr("Filter:"), groupFiles);
|
||||||
lineFilter = new LineEdit(groupFiles);
|
lineFilter = new LineEdit(groupFiles);
|
||||||
|
|
||||||
filterLayout->addWidget(labelFilter);
|
filterLayout->addWidget(labelFilter);
|
||||||
filterLayout->addWidget(lineFilter);
|
filterLayout->addWidget(lineFilter);
|
||||||
|
*/
|
||||||
|
|
||||||
// View for the game files
|
// View for the game files
|
||||||
dataFilesView = new QTableView(groupFiles);
|
//dataFilesView = new QTreeView(groupFiles);
|
||||||
|
dataFilesView = new QTreeView(groupFiles);
|
||||||
|
dataFilesView->setModel(dataFilesModel);
|
||||||
|
|
||||||
// Put everything in the correct layouts
|
// Put everything in the correct layouts
|
||||||
groupFilesLayout->addLayout(filterLayout);
|
//groupFilesLayout->addLayout(filterLayout);
|
||||||
groupFilesLayout->addItem(vSpacer1);
|
//groupFilesLayout->addItem(vSpacer1);
|
||||||
groupFilesLayout->addWidget(dataFilesView);
|
groupFilesLayout->addWidget(dataFilesView);
|
||||||
groupsLayout->addWidget(groupFiles);
|
|
||||||
|
|
||||||
// Column 2
|
|
||||||
QGroupBox *groupInfo = new QGroupBox(tr("File Information"), this);
|
|
||||||
groupInfo->setFixedWidth(250);
|
|
||||||
QVBoxLayout *groupInfoLayout = new QVBoxLayout(groupInfo);
|
|
||||||
|
|
||||||
QSpacerItem *vSpacer2 = new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
||||||
|
|
||||||
QLabel *labelAuthor = new QLabel(tr("Author:"), groupInfo);
|
|
||||||
lineAuthor = new QLineEdit(groupInfo);
|
|
||||||
lineAuthor->setReadOnly(true);
|
|
||||||
|
|
||||||
QSpacerItem *vSpacer3 = new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
||||||
|
|
||||||
QLabel *labelDesc = new QLabel(tr("Description:"), groupInfo);
|
|
||||||
textDesc = new QPlainTextEdit(groupInfo);
|
|
||||||
textDesc->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
||||||
textDesc->setMinimumHeight(180);
|
|
||||||
textDesc->setReadOnly(true);
|
|
||||||
|
|
||||||
QSpacerItem *vSpacer4 = new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
||||||
|
|
||||||
QLabel *labelDepends = new QLabel(tr("Dependencies:"), groupInfo);
|
|
||||||
textDepends = new QPlainTextEdit(groupInfo);
|
|
||||||
textDepends->setFixedHeight(80);
|
|
||||||
textDepends->setReadOnly(true);
|
|
||||||
|
|
||||||
QHBoxLayout *buttonsLayout = new QHBoxLayout();
|
QHBoxLayout *buttonsLayout = new QHBoxLayout();
|
||||||
QSpacerItem *horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
QSpacerItem *horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||||
|
@ -97,28 +79,14 @@ DataFilesDialog::DataFilesDialog()
|
||||||
|
|
||||||
buttonsLayout->addItem(horizontalSpacer);
|
buttonsLayout->addItem(horizontalSpacer);
|
||||||
buttonsLayout->addWidget(buttonBox);
|
buttonsLayout->addWidget(buttonBox);
|
||||||
|
|
||||||
// Put everything in the correct layouts
|
dialogLayout->addWidget(groupFiles);
|
||||||
groupInfoLayout->addItem(vSpacer2);
|
|
||||||
groupInfoLayout->addWidget(labelAuthor);
|
|
||||||
groupInfoLayout->addWidget(lineAuthor);
|
|
||||||
groupInfoLayout->addItem(vSpacer3);
|
|
||||||
groupInfoLayout->addWidget(labelDesc);
|
|
||||||
groupInfoLayout->addWidget(textDesc);
|
|
||||||
groupInfoLayout->addItem(vSpacer4);
|
|
||||||
groupInfoLayout->addWidget(labelDepends);
|
|
||||||
groupInfoLayout->addWidget(textDepends);
|
|
||||||
|
|
||||||
groupsLayout->addWidget(groupInfo);
|
|
||||||
|
|
||||||
dialogLayout->addLayout(groupsLayout);
|
|
||||||
dialogLayout->addLayout(buttonsLayout);
|
dialogLayout->addLayout(buttonsLayout);
|
||||||
|
|
||||||
setWindowTitle(tr("Data Files"));
|
setWindowTitle(tr("Data Files"));
|
||||||
|
|
||||||
|
|
||||||
// Signals and slots
|
// Signals and slots
|
||||||
//connect(dataFilesModel, SIGNAL(directoryLoaded(const QString &)), this, SLOT(setupView()));
|
/*connect(dataFilesModel, SIGNAL(directoryLoaded(const QString &)), this, SLOT(setupView()));
|
||||||
|
|
||||||
connect(dataFilesView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckstate(QModelIndex)));
|
connect(dataFilesView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckstate(QModelIndex)));
|
||||||
connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(changeData(QModelIndex, QModelIndex)));
|
connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(changeData(QModelIndex, QModelIndex)));
|
||||||
|
@ -128,14 +96,14 @@ DataFilesDialog::DataFilesDialog()
|
||||||
connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), this, SLOT(restoreDefaults()));
|
connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), this, SLOT(restoreDefaults()));
|
||||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(writeConfig()));
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(writeConfig()));
|
||||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
|
||||||
|
*/
|
||||||
readConfig();
|
//readConfig();
|
||||||
setupView();
|
//setupView();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesDialog::changeData(QModelIndex index, QModelIndex bottom)
|
void DataFilesDialog::changeData(QModelIndex index, QModelIndex bottom)
|
||||||
{
|
{
|
||||||
if (!index.isValid()) {
|
/*if (!index.isValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +144,7 @@ void DataFilesDialog::changeData(QModelIndex index, QModelIndex bottom)
|
||||||
|
|
||||||
void DataFilesDialog::setupView()
|
void DataFilesDialog::setupView()
|
||||||
{
|
{
|
||||||
// The signal directoryLoaded is emitted after all files are in the model
|
/* The signal directoryLoaded is emitted after all files are in the model
|
||||||
dataFilesView->setModel(dataFilesModel);
|
dataFilesView->setModel(dataFilesModel);
|
||||||
// dataFilesView->setModel(sortModel);
|
// dataFilesView->setModel(sortModel);
|
||||||
|
|
||||||
|
@ -203,13 +171,13 @@ void DataFilesDialog::setupView()
|
||||||
dataFilesView->horizontalHeader()->setStretchLastSection(true);
|
dataFilesView->horizontalHeader()->setStretchLastSection(true);
|
||||||
|
|
||||||
|
|
||||||
//sortModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
//sortModel->setSortCaseSensitivity(Qt::CaseInsensitive);*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesDialog::readConfig()
|
void DataFilesDialog::readConfig()
|
||||||
{
|
{
|
||||||
QString filename;
|
/* QString filename;
|
||||||
QString path = "data/"; // TODO: Should be global
|
QString path = "data/"; // TODO: Should be global
|
||||||
|
|
||||||
QFile file("openmw.cfg"); // Specify filepath later
|
QFile file("openmw.cfg"); // Specify filepath later
|
||||||
|
@ -250,12 +218,12 @@ void DataFilesDialog::readConfig()
|
||||||
// File is found in model, set it to checked
|
// File is found in model, set it to checked
|
||||||
dataFilesModel->setData(index, Qt::Checked, Qt::CheckStateRole);
|
dataFilesModel->setData(index, Qt::Checked, Qt::CheckStateRole);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesDialog::writeConfig()
|
void DataFilesDialog::writeConfig()
|
||||||
{
|
{
|
||||||
// Custom write method: We cannot use QSettings because it does not accept spaces
|
/* Custom write method: We cannot use QSettings because it does not accept spaces
|
||||||
|
|
||||||
// QList<QPersistentModelIndex> checkeditems = dataFilesModel->getCheckedItems().toList();
|
// QList<QPersistentModelIndex> checkeditems = dataFilesModel->getCheckedItems().toList();
|
||||||
QStringList checkeditems = dataFilesModel->getCheckedItems();
|
QStringList checkeditems = dataFilesModel->getCheckedItems();
|
||||||
|
@ -318,12 +286,12 @@ void DataFilesDialog::writeConfig()
|
||||||
|
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
close(); // Exit dialog
|
close(); // Exit dialog*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesDialog::restoreDefaults()
|
void DataFilesDialog::restoreDefaults()
|
||||||
{
|
{
|
||||||
// Uncheck all checked items
|
/* // Uncheck all checked items
|
||||||
dataFilesModel->checkedItems.clear();
|
dataFilesModel->checkedItems.clear();
|
||||||
|
|
||||||
QModelIndexList indexlist; // Make a list of default master files
|
QModelIndexList indexlist; // Make a list of default master files
|
||||||
|
@ -337,12 +305,12 @@ void DataFilesDialog::restoreDefaults()
|
||||||
dataFilesModel->setData(index, Qt::Checked, Qt::CheckStateRole);
|
dataFilesModel->setData(index, Qt::Checked, Qt::CheckStateRole);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dataFilesModel->submit(); // Force refresh of view
|
dataFilesModel->submit(); // Force refresh of view*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesDialog::setCheckstate(QModelIndex index)
|
void DataFilesDialog::setCheckstate(QModelIndex index)
|
||||||
{
|
{
|
||||||
// No check if index is valid: doubleclicked() always returns
|
/* No check if index is valid: doubleclicked() always returns
|
||||||
// a valid index when emitted
|
// a valid index when emitted
|
||||||
|
|
||||||
//index = QModelIndex(sortModel->mapToSource(index)); // Get a valid index
|
//index = QModelIndex(sortModel->mapToSource(index)); // Get a valid index
|
||||||
|
@ -357,11 +325,12 @@ void DataFilesDialog::setCheckstate(QModelIndex index)
|
||||||
dataFilesModel->setData(index, Qt::Unchecked, Qt::CheckStateRole);
|
dataFilesModel->setData(index, Qt::Unchecked, Qt::CheckStateRole);
|
||||||
} else {
|
} else {
|
||||||
dataFilesModel->setData(index, Qt::Checked, Qt::CheckStateRole);
|
dataFilesModel->setData(index, Qt::Checked, Qt::CheckStateRole);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataFilesDialog::setFilter()
|
void DataFilesDialog::setFilter()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
QStringList filefilter = (QStringList() << "*.esm" << "*.esp");
|
QStringList filefilter = (QStringList() << "*.esm" << "*.esp");
|
||||||
QStringList currentfilefilter;
|
QStringList currentfilefilter;
|
||||||
|
|
||||||
|
@ -390,5 +359,5 @@ void DataFilesDialog::setFilter()
|
||||||
// readConfig();
|
// readConfig();
|
||||||
// dataFilesModel->submit();
|
// dataFilesModel->submit();
|
||||||
// dataFilesModel->setData();
|
// dataFilesModel->setData();
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
#ifndef DATAFILESDIALOG_H
|
#ifndef DATAFILESDIALOG_H
|
||||||
#define DATAFILESDIALOG_H
|
#define DATAFILESDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
|
||||||
#include <QModelIndex>
|
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QPlainTextEdit>
|
|
||||||
|
|
||||||
#include "lineedit.h"
|
#include "lineedit.h"
|
||||||
|
|
||||||
class DataFilesModel;
|
class DataFilesModel;
|
||||||
class QStringList;
|
|
||||||
class QTableView;
|
/*class QStringList;
|
||||||
|
class QTreeView;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class QPlainTextEdit;
|
class QPlainTextEdit;
|
||||||
class QItemSelectionModel;
|
class QItemSelectionModel;
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
|
*/
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QModelIndex>
|
||||||
|
|
||||||
|
class QTreeView;
|
||||||
|
|
||||||
class DataFilesDialog : public QDialog
|
class DataFilesDialog : public QDialog
|
||||||
{
|
{
|
||||||
|
@ -27,14 +28,14 @@ public:
|
||||||
private:
|
private:
|
||||||
DataFilesModel *dataFilesModel;
|
DataFilesModel *dataFilesModel;
|
||||||
|
|
||||||
QTableView *dataFilesView;
|
QTreeView *dataFilesView;
|
||||||
QItemSelectionModel *selectionModel;
|
//QItemSelectionModel *selectionModel;
|
||||||
QSortFilterProxyModel *sortModel;
|
//QSortFilterProxyModel *sortModel;
|
||||||
|
|
||||||
QLineEdit *lineAuthor;
|
//QLineEdit *lineAuthor;
|
||||||
LineEdit *lineFilter;
|
//LineEdit *lineFilter;
|
||||||
QPlainTextEdit *textDesc;
|
//QPlainTextEdit *textDesc;
|
||||||
QPlainTextEdit *textDepends;
|
//QPlainTextEdit *textDepends;
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataFilesModel::~DataFilesModel()
|
||||||
|
{
|
||||||
|
delete rootItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataFilesModel::columnCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
if (parent.isValid())
|
||||||
|
return static_cast<DataFilesItem*>(parent.internalPointer())->columnCount();
|
||||||
|
else
|
||||||
|
return rootItem->columnCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DataFilesModel::data(const QModelIndex &index, int role) const
|
QVariant DataFilesModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (index.isValid() && role == Qt::DecorationRole) {
|
if (!index.isValid())
|
||||||
if (index.column() == 2) {
|
return QVariant();
|
||||||
QFileIconProvider fip;
|
|
||||||
QIcon fileIcon = fip.icon(fileInfo(index));
|
|
||||||
return fileIcon;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return QIcon();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
if (role != Qt::DisplayRole)
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
if (index.isValid() && role == Qt::DisplayRole) {
|
DataFilesItem *item = static_cast<DataFilesItem*>(index.internalPointer());
|
||||||
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");
|
|
||||||
|
|
||||||
}
|
return item->data(index.column());
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index.isValid() && role == Qt::CheckStateRole && index.column() == 0) {
|
|
||||||
// Put a checkbox in the first column
|
|
||||||
if (index.isValid())
|
|
||||||
|
|
||||||
if (checkedItems.contains(filePath(index))) {
|
|
||||||
// if (checkedItems.contains(index)) {
|
|
||||||
return Qt::Checked;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return Qt::Unchecked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QFileSystemModel::data(index, role);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DataFilesModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
|
||||||
{
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
emit dataChanged(index, index);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QFileSystemModel::setData(index, value, role);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Qt::ItemFlags DataFilesModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags DataFilesModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
return QFileSystemModel::flags(index) | Qt::ItemIsUserCheckable;
|
if (!index.isValid())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant DataFilesModel::headerData(int section, Qt::Orientation orientation,
|
||||||
|
int role) const
|
||||||
/*QVariant DataFilesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
||||||
{
|
{
|
||||||
switch (role) {
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||||
case Qt::DecorationRole:
|
return rootItem->data(section);
|
||||||
if (section == 0) {
|
|
||||||
// ### TODO oh man this is ugly and doesn't even work all the way!
|
return QVariant();
|
||||||
// it is still 2 pixels off
|
}
|
||||||
QImage pixmap(16, 1, QImage::Format_Mono);
|
|
||||||
pixmap.fill(0);
|
QModelIndex DataFilesModel::index(int row, int column, const QModelIndex &parent)
|
||||||
pixmap.setAlphaChannel(pixmap.createAlphaMask());
|
const
|
||||||
return pixmap;
|
{
|
||||||
|
if (!hasIndex(row, column, parent))
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
|
DataFilesItem *parentItem;
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
if (parentItem == rootItem)
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
|
return createIndex(parentItem->row(), 0, parentItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataFilesModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
DataFilesItem *parentItem;
|
||||||
|
if (parent.column() > 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!parent.isValid())
|
||||||
|
parentItem = rootItem;
|
||||||
|
else
|
||||||
|
parentItem = static_cast<DataFilesItem*>(parent.internalPointer());
|
||||||
|
|
||||||
|
return parentItem->childCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*void DataFilesModel::setupModelData(const QStringList &lines, DataFilesItem *parent)
|
||||||
|
{
|
||||||
|
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++;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case Qt::TextAlignmentRole:
|
QString lineData = lines[number].mid(position).trimmed();
|
||||||
return Qt::AlignLeft;
|
|
||||||
|
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++;
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
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;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*test
|
|
||||||
void DataFilesModel::setCheckedItems(const QStringList &gameFiles)
|
|
||||||
{
|
|
||||||
qDebug() << "test";
|
|
||||||
qDebug() << gameFiles.join("lol");
|
|
||||||
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*void DataFilesModel::sort(int column, Qt::SortOrder order)
|
|
||||||
{
|
|
||||||
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,
|
||||||
|
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;
|
||||||
|
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
private:
|
||||||
|
//void setupModelData(const QStringList &lines, TreeItem *parent);
|
||||||
|
|
||||||
// void sort(int column, Qt::SortOrder order);
|
DataFilesItem *rootItem;
|
||||||
//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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,5 +1,5 @@
|
||||||
######################################################################
|
######################################################################
|
||||||
# Automatically generated by qmake (2.01a) Sun Mar 27 19:33:07 2011
|
# Automatically generated by qmake (2.01a) Tue Mar 29 22:56:27 2011
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
@ -9,15 +9,17 @@ INCLUDEPATH += .
|
||||||
|
|
||||||
# Input
|
# Input
|
||||||
HEADERS += datafilesdialog.h \
|
HEADERS += datafilesdialog.h \
|
||||||
|
datafilesitem.h \
|
||||||
datafilesmodel.h \
|
datafilesmodel.h \
|
||||||
lineedit.h \
|
lineedit.h \
|
||||||
maindialog.h \
|
maindialog.h \
|
||||||
settingsdialog.h
|
settingsdialog.h
|
||||||
SOURCES += datafilesdialog.cpp \
|
SOURCES += datafilesdialog.cpp \
|
||||||
|
datafilesitem.cpp \
|
||||||
datafilesmodel.cpp \
|
datafilesmodel.cpp \
|
||||||
lineedit.cpp \
|
lineedit.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
maindialog.cpp \
|
maindialog.cpp \
|
||||||
|
qrc_resources.cxx \
|
||||||
settingsdialog.cpp
|
settingsdialog.cpp
|
||||||
RESOURCES += resources.qrc
|
RESOURCES += resources.qrc
|
||||||
RC_FILE = launcher.rc
|
|
Loading…
Reference in a new issue