From 046832c821276cb07b86519ab3c0dae4ff68173d Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Mon, 14 Jun 2010 06:20:07 +0000 Subject: Theme Editor: Stripped out the sub-classes for ProjectModel and turned ProjectModel into a list model, also replaced the project tree view with a list view git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26839 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/editorwindow.cpp | 1 - utils/themeeditor/editorwindow.ui | 2 +- utils/themeeditor/projectfiles.cpp | 133 ---------------------------- utils/themeeditor/projectfiles.h | 73 --------------- utils/themeeditor/projectmodel.cpp | 161 ++++++++++------------------------ utils/themeeditor/projectmodel.h | 67 ++------------ utils/themeeditor/projectsettings.cpp | 120 ------------------------- utils/themeeditor/projectsettings.h | 71 --------------- utils/themeeditor/themeeditor.pro | 8 +- 9 files changed, 56 insertions(+), 580 deletions(-) delete mode 100644 utils/themeeditor/projectfiles.cpp delete mode 100644 utils/themeeditor/projectfiles.h delete mode 100644 utils/themeeditor/projectsettings.cpp delete mode 100644 utils/themeeditor/projectsettings.h (limited to 'utils') diff --git a/utils/themeeditor/editorwindow.cpp b/utils/themeeditor/editorwindow.cpp index d137897763..035fe57f2d 100644 --- a/utils/themeeditor/editorwindow.cpp +++ b/utils/themeeditor/editorwindow.cpp @@ -275,7 +275,6 @@ void EditorWindow::openProject() project = new ProjectModel(fileName, this); ui->projectTree->setModel(project); - ui->projectTree->expandAll(); QObject::connect(ui->projectTree, SIGNAL(activated(QModelIndex)), project, SLOT(activated(QModelIndex))); diff --git a/utils/themeeditor/editorwindow.ui b/utils/themeeditor/editorwindow.ui index a3ea666c78..61b5f222a5 100644 --- a/utils/themeeditor/editorwindow.ui +++ b/utils/themeeditor/editorwindow.ui @@ -111,7 +111,7 @@ - + diff --git a/utils/themeeditor/projectfiles.cpp b/utils/themeeditor/projectfiles.cpp deleted file mode 100644 index f687e23767..0000000000 --- a/utils/themeeditor/projectfiles.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2010 Robert Bieber - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include "projectfiles.h" - -ProjectFiles::ProjectFiles(QHash& settings, - ProjectModel* model, ProjectNode* parent) - : parentLink(parent) -{ - base = settings.value("themebase"); - - QList keys; - keys.append("wps"); - keys.append("rwps"); - keys.append("sbs"); - keys.append("rsbs"); - keys.append("fms"); - keys.append("rfms"); - - for(int i = 0; i < keys.count(); i++) - { - QString file = settings.value(keys[i], ""); - if(file != "" && file != "-") - { - file.replace("/.rockbox/", ""); - children.append(new ProjectFile(file, model, this)); - } - } -} - -ProjectFiles::~ProjectFiles() -{ - for(int i = 0; i < children.count(); i++) - delete children[i]; -} - -ProjectNode* ProjectFiles::parent() const -{ - return parentLink; -} - -ProjectNode* ProjectFiles::child(int row) const -{ - if(row >= 0 && row < children.count()) - return children[row]; - - return 0; -} - -int ProjectFiles::numChildren() const -{ - return children.count(); -} - -int ProjectFiles::row() const -{ - return parentLink->indexOf(const_cast(this)); -} - -QVariant ProjectFiles::data(int column) const -{ - if(column == 0) - return QObject::tr("Project Files"); - else - return QVariant(); -} - -Qt::ItemFlags ProjectFiles::flags(int column) const -{ - if(column == 0) - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; - else - return 0; -} - -void ProjectFiles::activated() -{ - -} - -/* Project File functions */ -ProjectFile::ProjectFile(QString file, ProjectModel* model, - ProjectNode* parent) - :parentLink(parent), file(file) -{ - this->model = model; -} - -ProjectFile::~ProjectFile() -{ - -} - -QVariant ProjectFile::data(int column) const -{ - if(column == 0) - return file; - else - return QVariant(); -} - -Qt::ItemFlags ProjectFile::flags(int column) const -{ - if(column == 0) - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; - else - return 0; -} - -void ProjectFile::activated() -{ - QString base = dynamic_cast(parentLink)->getBase(); - model->loadFile(base + "/" + file); -} - diff --git a/utils/themeeditor/projectfiles.h b/utils/themeeditor/projectfiles.h deleted file mode 100644 index 6fec62882c..0000000000 --- a/utils/themeeditor/projectfiles.h +++ /dev/null @@ -1,73 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2010 Robert Bieber - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#ifndef PROJECTFILES_H -#define PROJECTFILES_H - -#include "projectmodel.h" -#include - -class ProjectFiles : public ProjectNode -{ -public: - ProjectFiles(QHash& settings, ProjectModel* model, - ProjectNode* parent); - virtual ~ProjectFiles(); - - virtual ProjectNode* parent() const; - virtual ProjectNode* child(int row) const; - virtual int numChildren() const; - virtual int row() const; - virtual QVariant data(int column) const; - virtual Qt::ItemFlags flags(int column) const; - virtual void activated(); - - QString getBase(){ return base; } - -private: - ProjectNode* parentLink; - QString base; - -}; - -/* A class to enumerate a single file */ -class ProjectFile: public ProjectNode -{ -public: - ProjectFile(QString file, ProjectModel* model, ProjectNode* parent); - virtual ~ProjectFile(); - - virtual ProjectNode* parent() const{ return parentLink; } - virtual ProjectNode* child(int row) const{ return 0; } - virtual int numChildren() const{ return 0; } - virtual int row() const{ - return parentLink->indexOf(const_cast(this)); - } - virtual QVariant data(int column) const; - virtual Qt::ItemFlags flags(int column) const; - virtual void activated(); - -private: - ProjectNode* parentLink; - QString file; -}; - -#endif // PROJECTFILES_H diff --git a/utils/themeeditor/projectmodel.cpp b/utils/themeeditor/projectmodel.cpp index da810d4906..925be81950 100644 --- a/utils/themeeditor/projectmodel.cpp +++ b/utils/themeeditor/projectmodel.cpp @@ -21,124 +21,18 @@ #include "projectmodel.h" -#include "projectfiles.h" -#include "projectsettings.h" #include "editorwindow.h" #include #include -#include +#include #include ProjectModel::ProjectModel(QString config, EditorWindow* mainWindow, QObject *parent) - : QAbstractItemModel(parent), + : QAbstractListModel(parent), mainWindow(mainWindow) { - root = new ProjectRoot(config, this); -} - -ProjectModel::~ProjectModel() -{ - if(root) - delete root; -} - -QModelIndex ProjectModel::index(int row, int column, - const QModelIndex& parent) const -{ - - if(!hasIndex(row, column, parent)) - return QModelIndex(); - - ProjectNode* foundParent = root; - if(parent.isValid()) - foundParent = static_cast(parent.internalPointer()); - - if(row < foundParent->numChildren() && row >= 0) - return createIndex(row, column, foundParent->child(row)); - else - return QModelIndex(); -} - -QModelIndex ProjectModel::parent(const QModelIndex &child) const -{ - if(!child.isValid()) - return QModelIndex(); - - ProjectNode* foundParent = static_cast - (child.internalPointer())->parent(); - - if(foundParent == root) - return QModelIndex(); - - return createIndex(foundParent->row(), 0, foundParent); -} - -int ProjectModel::rowCount(const QModelIndex &parent) const -{ - if(!root) - return 0; - - if(!parent.isValid()) - return root->numChildren(); - - if(parent.column() != 0) - return 0; - - return static_cast(parent.internalPointer())->numChildren(); -} - -int ProjectModel::columnCount(const QModelIndex &parent) const -{ - return numColumns; -} - -QVariant ProjectModel::data(const QModelIndex &index, int role) const -{ - if(!index.isValid()) - return QVariant(); - - if(role != Qt::DisplayRole) - return QVariant(); - - return static_cast - (index.internalPointer())->data(index.column()); -} - -QVariant ProjectModel::headerData(int col, Qt::Orientation orientation, - int role) const -{ - return QVariant(); -} - -Qt::ItemFlags ProjectModel::flags(const QModelIndex &index) const -{ - return static_cast - (index.internalPointer())->flags(index.column()); -} - -bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, - int role) -{ - return true; -} - -void ProjectModel::loadFile(QString file) -{ - mainWindow->loadTabFromFile(file); -} - -void ProjectModel::activated(const QModelIndex &index) -{ - static_cast(index.internalPointer())->activated(); -} - -/* Constructor and destructor for the root class */ -ProjectRoot::ProjectRoot(QString config, ProjectModel* model) -{ - this->model = model; - /* Reading the config file */ QFile cfg(config); cfg.open(QFile::ReadOnly | QFile::Text); @@ -172,14 +66,53 @@ ProjectRoot::ProjectRoot(QString config, ProjectModel* model) cfg.close(); - /* Showing the files */ - children.append(new ProjectFiles(settings, model, this)); - children.append(new ProjectSettings(settings, model, this)); + /* Adding the files, starting with the .cfg */ + config.replace(base.canonicalPath() + "/", ""); + files.append(config); + + QList keys; + keys.append("wps"); + keys.append("rwps"); + keys.append("sbs"); + keys.append("rsbs"); + keys.append("fms"); + keys.append("rfms"); + + for(int i = 0; i < keys.count(); i++) + { + QString file = settings.value(keys[i], ""); + if(file != "" && file != "-") + { + file.replace("/.rockbox/", ""); + files.append(file); + } + } + +} + +ProjectModel::~ProjectModel() +{ } -ProjectRoot::~ProjectRoot() +int ProjectModel::rowCount(const QModelIndex& parent) const +{ + return files.count(); +} + +QVariant ProjectModel::data(const QModelIndex &index, int role) const +{ + if(!index.isValid()) + return QVariant(); + + if(role != Qt::DisplayRole) + return QVariant(); + + return files[index.row()]; +} + +void ProjectModel::activated(const QModelIndex &index) { - for(int i = 0; i < children.count(); i++) - delete children[i]; + mainWindow->loadTabFromFile(settings.value("themebase", "") + + "/" + files[index.row()]); } diff --git a/utils/themeeditor/projectmodel.h b/utils/themeeditor/projectmodel.h index c7147fa83f..d577f00a69 100644 --- a/utils/themeeditor/projectmodel.h +++ b/utils/themeeditor/projectmodel.h @@ -22,13 +22,12 @@ #ifndef PROJECTMODEL_H #define PROJECTMODEL_H -#include -#include +#include +#include -class ProjectNode; class EditorWindow; -class ProjectModel : public QAbstractItemModel +class ProjectModel : public QAbstractListModel { Q_OBJECT public: @@ -42,16 +41,8 @@ public: ProjectModel(QString config, EditorWindow* mainWindow, QObject *parent = 0); virtual ~ProjectModel(); - QModelIndex index(int row, int column, const QModelIndex& parent) const; - QModelIndex parent(const QModelIndex &child) const; - int rowCount(const QModelIndex &parent) const; - int columnCount(const QModelIndex &parent) const; + int rowCount(const QModelIndex& parent) const; QVariant data(const QModelIndex &index, int role) const; - QVariant headerData(int col, Qt::Orientation orientation, int role) const; - Qt::ItemFlags flags(const QModelIndex &index) const; - bool setData(const QModelIndex &index, const QVariant &value, int role); - - void loadFile(QString file); signals: @@ -59,55 +50,9 @@ public slots: void activated(const QModelIndex& index); private: - ProjectNode* root; EditorWindow* mainWindow; + QMap settings; + QList files; }; -/* A simple abstract class required for categories */ -class ProjectNode -{ -public: - virtual ProjectNode* parent() const = 0; - virtual ProjectNode* child(int row) const = 0; - virtual int numChildren() const = 0; - virtual int row() const = 0; - virtual QVariant data(int column) const = 0; - virtual Qt::ItemFlags flags(int column) const = 0; - virtual void activated() = 0; - - int indexOf(ProjectNode* child){ return children.indexOf(child); } - -protected: - QList children; - ProjectModel* model; - -}; - -/* A simple implementation of ProjectNode for the root */ -class ProjectRoot : public ProjectNode -{ -public: - ProjectRoot(QString config, ProjectModel* model); - virtual ~ProjectRoot(); - - virtual ProjectNode* parent() const{ return 0; } - virtual ProjectNode* child(int row) const - { - if(row >= 0 && row < children.count()) - return children[row]; - else - return 0; - } - virtual int numChildren() const{ return children.count(); } - virtual int row() const{ return 0; } - virtual QVariant data(int column) const{ return QVariant(); } - virtual Qt::ItemFlags flags(int column) const{ return 0; } - virtual void activated(){ } - -private: - QHash settings; - -}; - - #endif // PROJECTMODEL_H diff --git a/utils/themeeditor/projectsettings.cpp b/utils/themeeditor/projectsettings.cpp deleted file mode 100644 index a477f2bdfc..0000000000 --- a/utils/themeeditor/projectsettings.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2010 Robert Bieber - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include "projectsettings.h" - -ProjectSettings::ProjectSettings(QHash& settings, - ProjectModel* model, ProjectNode* parent) - : parentLink(parent) -{ - QHash::iterator i; - for(i = settings.begin(); i != settings.end(); i++) - { - QPair value(i.key(), i.value()); - children.append(new ProjectSetting(value, model, this)); - } -} - -ProjectSettings::~ProjectSettings() -{ - for(int i = 0; i < children.count(); i++) - delete children[i]; -} - -ProjectNode* ProjectSettings::parent() const -{ - return parentLink; -} - -ProjectNode* ProjectSettings::child(int row) const -{ - if(row >= 0 && row < children.count()) - return children[row]; - - return 0; -} - -int ProjectSettings::numChildren() const -{ - return children.count(); -} - -int ProjectSettings::row() const -{ - return parentLink->indexOf(const_cast(this)); -} - -QVariant ProjectSettings::data(int column) const -{ - if(column == 0) - return QObject::tr("Project Settings"); - else - return QVariant(); -} - -Qt::ItemFlags ProjectSettings::flags(int column) const -{ - if(column == 0) - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; - else - return 0; -} - -void ProjectSettings::activated() -{ - -} - -/* Project File functions */ -ProjectSetting::ProjectSetting(QPair setting, - ProjectModel* model, ProjectNode* parent) - :parentLink(parent), setting(setting) -{ - this->model = model; -} - -ProjectSetting::~ProjectSetting() -{ - -} - -QVariant ProjectSetting::data(int column) const -{ - if(column == 0) - return setting.first; - else if(column == 1) - return setting.second; - else - return QVariant(); -} - -Qt::ItemFlags ProjectSetting::flags(int column) const -{ - if(column == 0 || column == 1) - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; - else - return 0; -} - -void ProjectSetting::activated() -{ -} - diff --git a/utils/themeeditor/projectsettings.h b/utils/themeeditor/projectsettings.h deleted file mode 100644 index ed785ac02c..0000000000 --- a/utils/themeeditor/projectsettings.h +++ /dev/null @@ -1,71 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2010 Robert Bieber - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#ifndef PROJCETSETTINGS_H -#define PROJECTSETTINGS_H - -#include "projectmodel.h" -#include - -class ProjectSettings : public ProjectNode -{ -public: - ProjectSettings(QHash& settings, ProjectModel* model, - ProjectNode* parent); - virtual ~ProjectSettings(); - - virtual ProjectNode* parent() const; - virtual ProjectNode* child(int row) const; - virtual int numChildren() const; - virtual int row() const; - virtual QVariant data(int column) const; - virtual Qt::ItemFlags flags(int column) const; - virtual void activated(); - -private: - ProjectNode* parentLink; - -}; - -/* A class to enumerate a single file */ -class ProjectSetting: public ProjectNode -{ -public: - ProjectSetting(QPair setting, ProjectModel* model, - ProjectNode* parent); - virtual ~ProjectSetting(); - - virtual ProjectNode* parent() const{ return parentLink; } - virtual ProjectNode* child(int row) const{ return 0; } - virtual int numChildren() const{ return 0; } - virtual int row() const{ - return parentLink->indexOf(const_cast(this)); - } - virtual QVariant data(int column) const; - virtual Qt::ItemFlags flags(int column) const; - virtual void activated(); - -private: - ProjectNode* parentLink; - QPair setting; -}; - -#endif // PROJECTSETTINGS_H diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index b86b4debb4..128f56996d 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro @@ -16,9 +16,7 @@ HEADERS += tag_table.h \ skindocument.h \ preferencesdialog.h \ codeeditor.h \ - projectmodel.h \ - projectfiles.h \ - projectsettings.h + projectmodel.h SOURCES += tag_table.c \ skin_parser.c \ skin_scan.c \ @@ -31,9 +29,7 @@ SOURCES += tag_table.c \ skindocument.cpp \ preferencesdialog.cpp \ codeeditor.cpp \ - projectmodel.cpp \ - projectfiles.cpp \ - projectsettings.cpp + projectmodel.cpp OTHER_FILES += README \ resources/windowicon.png \ resources/appicon.xcf \ -- cgit v1.2.3