Skip to content

Commit

Permalink
GUI: Refactor for clarity
Browse files Browse the repository at this point in the history
- Remove FileInfo and SoundInfo structs
- Add ItemData struct to contain all non tree structure data
- Rename getData -> getName
- Remove getFileInfo method
  • Loading branch information
fdde authored and DrMcCoy committed Dec 27, 2017
1 parent 927757c commit 25bd5c7
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 147 deletions.
12 changes: 6 additions & 6 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void MainWindow::saveItem() {
if (fileName.isEmpty())
return;

_status->push(constructStatus("Saving", _currentItem->getData(), fileName));
_status->push(constructStatus("Saving", _currentItem->getName(), fileName));
BOOST_SCOPE_EXIT((&_status)) {
_status->pop();
} BOOST_SCOPE_EXIT_END
Expand Down Expand Up @@ -250,7 +250,7 @@ void MainWindow::exportTGA() {
if (fileName.isEmpty())
return;

_status->push(constructStatus("Exporting", _currentItem->getData(), fileName));
_status->push(constructStatus("Exporting", _currentItem->getName(), fileName));
BOOST_SCOPE_EXIT((&_status)) {
_status->pop();
} BOOST_SCOPE_EXIT_END
Expand Down Expand Up @@ -285,7 +285,7 @@ void MainWindow::exportBMUMP3() {

const QString title = "Save MP3 file";
const QString mask = "MP3 file (*.mp3)|*.mp3";
const QString def = TypeMan.setFileType(USTR(_currentItem->getData()), Aurora::kFileTypeMP3).toQString();
const QString def = TypeMan.setFileType(USTR(_currentItem->getName()), Aurora::kFileTypeMP3).toQString();

QString fileName = QFileDialog::getSaveFileName(this,
title, def,
Expand All @@ -294,7 +294,7 @@ void MainWindow::exportBMUMP3() {
if (fileName.isEmpty())
return;

_status->push(constructStatus("Exporting", _currentItem->getData(), fileName));
_status->push(constructStatus("Exporting", _currentItem->getName(), fileName));
BOOST_SCOPE_EXIT((&_status)) {
_status->pop();
} BOOST_SCOPE_EXIT_END
Expand Down Expand Up @@ -396,7 +396,7 @@ void MainWindow::exportWAV() {

const QString title = "Save PCM WAV file";
const QString mask = "WAV file (*.wav)|*.wav";
const QString def = TypeMan.setFileType(USTR(_currentItem->getData()), Aurora::kFileTypeWAV).toQString();
const QString def = TypeMan.setFileType(USTR(_currentItem->getName()), Aurora::kFileTypeWAV).toQString();

QString fileName = QFileDialog::getSaveFileName(this,
title, def,
Expand All @@ -405,7 +405,7 @@ void MainWindow::exportWAV() {
if (fileName.isEmpty())
return;

_status->push(constructStatus("Exporting", _currentItem->getData(), fileName));
_status->push(constructStatus("Exporting", _currentItem->getName(), fileName));
BOOST_SCOPE_EXIT((&_status)) {
_status->pop();
} BOOST_SCOPE_EXIT_END
Expand Down
2 changes: 1 addition & 1 deletion src/gui/panelpreviewtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void PanelPreviewText::setItem(const ResourceTreeItem *item) {

_currentItem = item;

QFile file(item->getFileInfo().canonicalFilePath());
QFile file(item->getPath());
file.open(QFile::ReadOnly | QFile::Text);
QTextStream textStream(&file);

Expand Down
2 changes: 1 addition & 1 deletion src/gui/panelresourceinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void PanelResourceInfo::setLabels(const ResourceTreeItem *item) {
QString labelFileType = "File type: ";
QString labelResType = "Resource type: ";

labelName += item->getData();
labelName += item->getName();

if (item->getSource() == Source::kSourceDirectory) {

Expand Down
26 changes: 13 additions & 13 deletions src/gui/resourcetree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,32 @@ void ResourceTree::fetchMore(const QModelIndex &index) {
ResourceTreeItem *item = getItem(index);

// We already added the archive members. Nothing to do
ArchiveInfo &archiveInfo = item->getArchive();
if (archiveInfo.addedArchiveMembers)
Archive &archive = item->getArchive();
if (archive.addedMembers)
return;

_mainWindow->status()->push(tr("Loading archive") + item->getData() + "...");
_mainWindow->status()->push(tr("Loading archive") + item->getName() + "...");
BOOST_SCOPE_EXIT((&_mainWindow)) {
_mainWindow->status()->pop();
} BOOST_SCOPE_EXIT_END

// Load the archive, if necessary
if (!archiveInfo.archive) {
if (!archive.data) {
try {
archiveInfo.archive = getArchive(item->getPath());
archive.data = getArchive(item->getPath());
} catch (Common::Exception &e) {
// If that fails, print the error and treat this archive as empty

e.add("Failed to load archive \"%s\"", getItem(index)->getData().toStdString().c_str());
e.add("Failed to load archive \"%s\"", getItem(index)->getName().toStdString().c_str());
Common::printException(e, "WARNING: ");

return;
}
}

insertItemsFromArchive(archiveInfo, index);
insertItemsFromArchive(archive, index);

archiveInfo.addedArchiveMembers = true;
archive.addedMembers = true;
}

bool ResourceTree::hasChildren(const QModelIndex &index) const {
Expand Down Expand Up @@ -183,7 +183,7 @@ QModelIndex ResourceTree::index(int row, int column, const QModelIndex &parent)

QVariant ResourceTree::headerData(int section, Qt::Orientation orientation, int role) const {
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return _root->getData();
return _root->getName();

return QVariant();
}
Expand Down Expand Up @@ -220,7 +220,7 @@ QVariant ResourceTree::data(const QModelIndex &index, int role) const {
}

if (role == Qt::DisplayRole)
return cur->getData();
return cur->getName();

return QVariant();
}
Expand All @@ -232,15 +232,15 @@ Qt::ItemFlags ResourceTree::flags(const QModelIndex &index) const {
return QAbstractItemModel::flags(index);
}

void ResourceTree::insertItemsFromArchive(ArchiveInfo &data, const QModelIndex &parentIndex) {
void ResourceTree::insertItemsFromArchive(Archive &archive, const QModelIndex &parentIndex) {
QList<ResourceTreeItem*> items;

ResourceTreeItem *parentItem = getItem(parentIndex);

auto resources = data.archive->getResources();
auto resources = archive.data->getResources();
for (auto r = resources.begin(); r != resources.end(); ++r)
{
items << new ResourceTreeItem(data.archive, *r, parentItem);
items << new ResourceTreeItem(archive.data, *r, parentItem);
}

insertItems(0, items, parentIndex);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/resourcetree.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Aurora {

namespace GUI {

struct ArchiveInfo;
struct Archive;
class MainWindow;
class ResourceTreeItem;

Expand Down Expand Up @@ -69,7 +69,7 @@ class ResourceTree : public QAbstractItemModel {
ResourceTreeItem *getItem(const QModelIndex &index) const;
bool canFetchMore(const QModelIndex &index) const override;
void fetchMore(const QModelIndex &index);
void insertItemsFromArchive(ArchiveInfo &data, const QModelIndex &parentIndex);
void insertItemsFromArchive(Archive &archive, const QModelIndex &parentIndex);
void insertItems(int position, QList<ResourceTreeItem*> &items, const QModelIndex &parentIndex);
bool hasChildren(const QModelIndex &index) const override;
Qt::ItemFlags flags(const QModelIndex &index) const;
Expand Down

0 comments on commit 25bd5c7

Please sign in to comment.