From ef1e1ac67110a44f776b8b98394ea063c8cf3c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Mon, 25 Jan 2016 22:39:26 +0100 Subject: [PATCH 01/72] ADDED: Settings - Recent projects. --- Project/Tome.pro | 6 +- README.md | 2 +- Source/Tome/Settings/tomesettings.cpp | 67 +++++ Source/Tome/Settings/tomesettings.h | 26 ++ Source/Tome/main.cpp | 5 +- Source/Tome/mainwindow.cpp | 381 ++++++++++++++------------ Source/Tome/mainwindow.h | 3 + Source/Tome/mainwindow.ui | 7 + 8 files changed, 325 insertions(+), 172 deletions(-) create mode 100644 Source/Tome/Settings/tomesettings.cpp create mode 100644 Source/Tome/Settings/tomesettings.h diff --git a/Project/Tome.pro b/Project/Tome.pro index 2a688db5..5f4acff2 100644 --- a/Project/Tome.pro +++ b/Project/Tome.pro @@ -59,7 +59,8 @@ SOURCES += ../Source/Tome/main.cpp \ ../Source/Tome/Types/customtypewindow.cpp \ ../Source/Tome/Types/customtypememberwindow.cpp \ ../Source/Tome/Types/customtype.cpp \ - ../Source/Tome/Types/customtypesitemmodel.cpp + ../Source/Tome/Types/customtypesitemmodel.cpp \ + ../Source/Tome/Settings/tomesettings.cpp HEADERS += ../Source/Tome/mainwindow.h \ ../Source/Tome/Types/builtintype.h \ @@ -93,7 +94,8 @@ HEADERS += ../Source/Tome/mainwindow.h \ ../Source/Tome/Types/customtypewindow.h \ ../Source/Tome/Types/customtypememberwindow.h \ ../Source/Tome/Types/customtype.h \ - ../Source/Tome/Types/customtypesitemmodel.h + ../Source/Tome/Types/customtypesitemmodel.h \ + ../Source/Tome/Settings/tomesettings.h FORMS += ../Source/Tome/mainwindow.ui \ ../Source/Tome/Help/aboutwindow.ui \ diff --git a/README.md b/README.md index 1ac4e8c9..59f7fbef 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Tome is developed using the [GitFlow branching model](http://nvie.com/posts/a-su ### Step 3: Implement your feature or bugfix -Tome is based on [Qt 5.5](http://www.qt.io/). +Tome is based on [Qt 5.4](http://www.qt.io/). You might also take a look at our [development wiki](https://github.com/npruehs/game-data-editor/wiki) in order to get a better understanding of how everything's tied together. diff --git a/Source/Tome/Settings/tomesettings.cpp b/Source/Tome/Settings/tomesettings.cpp new file mode 100644 index 00000000..1e2d3d72 --- /dev/null +++ b/Source/Tome/Settings/tomesettings.cpp @@ -0,0 +1,67 @@ +#include "tomesettings.h" + +#include + + +const QString TomeSettings::SettingsRecentProjects = "recentProjects"; +const QString TomeSettings::SettingsPath = "path"; + + +TomeSettings::TomeSettings() +{ + QSettings* s = new QSettings( + QSettings::IniFormat, + QSettings::UserScope, + QCoreApplication::organizationName(), + QCoreApplication::applicationName()); + + this->settings = QSharedPointer(s); +} + +void TomeSettings::addRecentProject(const QString& path) +{ + QStringList recentProjects = this->getRecentProjects(); + + if (recentProjects.contains(path)) + { + return; + } + + recentProjects.push_front(path); + + this->setRecentProjects(recentProjects); +} + +QStringList TomeSettings::getRecentProjects() +{ + QStringList recentProjects; + + int size = this->settings->beginReadArray(SettingsRecentProjects); + for (int i = 0; i < size; ++i) + { + this->settings->setArrayIndex(i); + QString path = this->settings->value(SettingsPath).toString(); + recentProjects.push_back(path); + } + this->settings->endArray(); + + return recentProjects; +} + +void TomeSettings::removeRecentProject(const QString& path) +{ + QStringList recentProjects = this->getRecentProjects(); + recentProjects.removeOne(path); + this->setRecentProjects(recentProjects); +} + +void TomeSettings::setRecentProjects(QStringList recentProjects) +{ + this->settings->beginWriteArray(SettingsRecentProjects); + for (int i = 0; i < recentProjects.size(); ++i) + { + this->settings->setArrayIndex(i); + this->settings->setValue(SettingsPath, recentProjects.at(i)); + } + this->settings->endArray(); +} diff --git a/Source/Tome/Settings/tomesettings.h b/Source/Tome/Settings/tomesettings.h new file mode 100644 index 00000000..0537f525 --- /dev/null +++ b/Source/Tome/Settings/tomesettings.h @@ -0,0 +1,26 @@ +#ifndef TOMESETTINGS_H +#define TOMESETTINGS_H + +#include +#include +#include + + +class TomeSettings +{ + public: + TomeSettings(); + + void addRecentProject(const QString& path); + QStringList getRecentProjects(); + void removeRecentProject(const QString& path); + void setRecentProjects(QStringList recentProjects); + + private: + static const QString SettingsRecentProjects; + static const QString SettingsPath; + + QSharedPointer settings; +}; + +#endif // TOMESETTINGS_H diff --git a/Source/Tome/main.cpp b/Source/Tome/main.cpp index b77de9e2..3795d513 100644 --- a/Source/Tome/main.cpp +++ b/Source/Tome/main.cpp @@ -5,8 +5,11 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - // Set application version. + // Set application data. a.setApplicationVersion(APP_VERSION); + a.setOrganizationName("Tome"); + a.setOrganizationDomain("tome-editor.org"); + a.setApplicationName("Tome"); MainWindow w; w.show(); diff --git a/Source/Tome/mainwindow.cpp b/Source/Tome/mainwindow.cpp index 8efcbd28..febd2975 100644 --- a/Source/Tome/mainwindow.cpp +++ b/Source/Tome/mainwindow.cpp @@ -17,6 +17,7 @@ #include "Projects/project.h" #include "Projects/projectserializer.h" #include "Records/recordsetserializer.h" +#include "Settings/tomesettings.h" #include "Types/builtintype.h" #include "Util/pathutils.h" @@ -53,6 +54,12 @@ MainWindow::MainWindow(QWidget *parent) : SLOT(exportRecords(QAction*)) ); + connect( + this->ui->menuRecent_Projects, + SIGNAL(triggered(QAction*)), + SLOT(openRecentProject(QAction*)) + ); + // Maximize window. this->showMaximized(); @@ -61,6 +68,7 @@ MainWindow::MainWindow(QWidget *parent) : // Can't access some functionality until project created or loaded. this->updateMenus(); + this->updateRecentProjects(); // Setup record field table model. RecordTableModel* model = new RecordTableModel(this); @@ -135,174 +143,7 @@ void MainWindow::on_actionOpen_Project_triggered() QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tome Project Files (*.tproj)"); - if (projectFileName.count() <= 0) - { - return; - } - - // Open project file. - QSharedPointer projectFile = QSharedPointer::create(projectFileName); - QSharedPointer projectFileInfo = QSharedPointer::create(projectFileName); - const QString projectPath = projectFileInfo->path(); - - if (projectFile->open(QIODevice::ReadOnly)) - { - // Load project from file. - QSharedPointer projectSerializer = - QSharedPointer::create(); - QSharedPointer project = QSharedPointer::create(); - project->path = projectPath; - - try - { - projectSerializer->deserialize(projectFile, project); - } - catch (const std::runtime_error& e) - { - QMessageBox::critical( - this, - tr("Unable to open project"), - tr("File could not be read: ") + projectFileName + "\r\n" + e.what(), - QMessageBox::Close, - QMessageBox::Close); - return; - } - - // Load field definition files. - QSharedPointer fieldDefinitionSerializer = - QSharedPointer::create(); - - for (QVector >::iterator it = project->fieldDefinitionSets.begin(); - it != project->fieldDefinitionSets.end(); - ++it) - { - QSharedPointer fieldDefinitionSet = *it; - - // Open field definition file. - const QString fullFieldDefinitionSetPath = combinePaths(projectPath, fieldDefinitionSet->name + FieldDefinitionFileExtension); - QSharedPointer fieldDefinitionFile = QSharedPointer::create(fullFieldDefinitionSetPath); - - if (fieldDefinitionFile->open(QIODevice::ReadOnly)) - { - try - { - fieldDefinitionSerializer->deserialize(fieldDefinitionFile, fieldDefinitionSet); - } - catch (const std::runtime_error& e) - { - QMessageBox::critical( - this, - tr("Unable to open project"), - tr("File could not be read: ") + fullFieldDefinitionSetPath + "\r\n" + e.what(), - QMessageBox::Close, - QMessageBox::Close); - return; - } - } - else - { - QMessageBox::critical( - this, - tr("Unable to open project"), - tr("File could not be read:\r\n") + fullFieldDefinitionSetPath, - QMessageBox::Close, - QMessageBox::Close); - return; - } - } - - // Load record files. - QSharedPointer recordSetSerializer = - QSharedPointer::create(); - - for (QVector >::iterator it = project->recordSets.begin(); - it != project->recordSets.end(); - ++it) - { - QSharedPointer recordSet = *it; - - // Open record file. - const QString fullRecordSetPath = combinePaths(projectPath, recordSet->name + RecordFileExtension); - QSharedPointer recordFile = QSharedPointer::create(fullRecordSetPath); - - if (recordFile->open(QIODevice::ReadOnly)) - { - try - { - recordSetSerializer->deserialize(recordFile, recordSet); - } - catch (const std::runtime_error& e) - { - QMessageBox::critical( - this, - tr("Unable to open project"), - tr("File could not be read: ") + fullRecordSetPath + "\r\n" + e.what(), - QMessageBox::Close, - QMessageBox::Close); - return; - } - } - else - { - QMessageBox::critical( - this, - tr("Unable to open project"), - tr("File could not be read:\r\n") + fullRecordSetPath, - QMessageBox::Close, - QMessageBox::Close); - return; - } - } - - // Load record export template files. - for (QMap >::iterator it = project->recordExportTemplates.begin(); - it != project->recordExportTemplates.end(); - ++it) - { - QSharedPointer exportTemplate = it.value(); - - try - { - exportTemplate->fieldValueDelimiter = - this->readProjectFile(projectPath, exportTemplate->name + RecordExportFieldValueDelimiterExtension); - exportTemplate->fieldValueTemplate = - this->readProjectFile(projectPath, exportTemplate->name + RecordExportFieldValueTemplateExtension); - exportTemplate->recordDelimiter = - this->readProjectFile(projectPath, exportTemplate->name + RecordExportRecordDelimiterExtension); - exportTemplate->recordFileTemplate = - this->readProjectFile(projectPath, exportTemplate->name + RecordExportRecordFileTemplateExtension); - exportTemplate->recordTemplate = - this->readProjectFile(projectPath, exportTemplate->name + RecordExportRecordTemplateExtension); - exportTemplate->componentDelimiter = - this->readProjectFile(projectPath, exportTemplate->name + RecordExportComponentDelimiterExtension); - exportTemplate->componentTemplate = - this->readProjectFile(projectPath, exportTemplate->name + RecordExportComponentTemplateExtension); - } - catch (const std::runtime_error& e) - { - QMessageBox::critical( - this, - tr("Unable to open project"), - tr("File could not be read:\r\n") + e.what(), - QMessageBox::Close, - QMessageBox::Close); - return; - } - } - - // Set project reference. - this->setProject(project); - } - else - { - QMessageBox::critical( - this, - tr("Unable to open project"), - tr("File could not be read:\r\n") + projectFileName, - QMessageBox::Close, - QMessageBox::Close); - return; - } + this->openProject(projectFileName); } void MainWindow::on_actionSave_Project_triggered() @@ -595,6 +436,12 @@ void MainWindow::exportRecords(QAction* exportAction) } } +void MainWindow::openRecentProject(QAction* recentProjectAction) +{ + QString path = recentProjectAction->text(); + this->openProject(path); +} + void MainWindow::treeViewSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected) { Q_UNUSED(deselected); @@ -693,6 +540,188 @@ QString MainWindow::getSelectedRecordDisplayName() const return currentIndex.data(Qt::DisplayRole).toString(); } +void MainWindow::openProject(QString projectFileName) +{ + if (projectFileName.count() <= 0) + { + return; + } + + // Open project file. + QSharedPointer projectFile = QSharedPointer::create(projectFileName); + QSharedPointer projectFileInfo = QSharedPointer::create(projectFileName); + const QString projectPath = projectFileInfo->path(); + + if (projectFile->open(QIODevice::ReadOnly)) + { + // Load project from file. + QSharedPointer projectSerializer = + QSharedPointer::create(); + QSharedPointer project = QSharedPointer::create(); + project->path = projectPath; + + try + { + projectSerializer->deserialize(projectFile, project); + } + catch (const std::runtime_error& e) + { + QMessageBox::critical( + this, + tr("Unable to open project"), + tr("File could not be read: ") + projectFileName + "\r\n" + e.what(), + QMessageBox::Close, + QMessageBox::Close); + return; + } + + // Load field definition files. + QSharedPointer fieldDefinitionSerializer = + QSharedPointer::create(); + + for (QVector >::iterator it = project->fieldDefinitionSets.begin(); + it != project->fieldDefinitionSets.end(); + ++it) + { + QSharedPointer fieldDefinitionSet = *it; + + // Open field definition file. + const QString fullFieldDefinitionSetPath = combinePaths(projectPath, fieldDefinitionSet->name + FieldDefinitionFileExtension); + QSharedPointer fieldDefinitionFile = QSharedPointer::create(fullFieldDefinitionSetPath); + + if (fieldDefinitionFile->open(QIODevice::ReadOnly)) + { + try + { + fieldDefinitionSerializer->deserialize(fieldDefinitionFile, fieldDefinitionSet); + } + catch (const std::runtime_error& e) + { + QMessageBox::critical( + this, + tr("Unable to open project"), + tr("File could not be read: ") + fullFieldDefinitionSetPath + "\r\n" + e.what(), + QMessageBox::Close, + QMessageBox::Close); + return; + } + } + else + { + QMessageBox::critical( + this, + tr("Unable to open project"), + tr("File could not be read:\r\n") + fullFieldDefinitionSetPath, + QMessageBox::Close, + QMessageBox::Close); + return; + } + } + + // Load record files. + QSharedPointer recordSetSerializer = + QSharedPointer::create(); + + for (QVector >::iterator it = project->recordSets.begin(); + it != project->recordSets.end(); + ++it) + { + QSharedPointer recordSet = *it; + + // Open record file. + const QString fullRecordSetPath = combinePaths(projectPath, recordSet->name + RecordFileExtension); + QSharedPointer recordFile = QSharedPointer::create(fullRecordSetPath); + + if (recordFile->open(QIODevice::ReadOnly)) + { + try + { + recordSetSerializer->deserialize(recordFile, recordSet); + } + catch (const std::runtime_error& e) + { + QMessageBox::critical( + this, + tr("Unable to open project"), + tr("File could not be read: ") + fullRecordSetPath + "\r\n" + e.what(), + QMessageBox::Close, + QMessageBox::Close); + return; + } + } + else + { + QMessageBox::critical( + this, + tr("Unable to open project"), + tr("File could not be read:\r\n") + fullRecordSetPath, + QMessageBox::Close, + QMessageBox::Close); + return; + } + } + + // Load record export template files. + for (QMap >::iterator it = project->recordExportTemplates.begin(); + it != project->recordExportTemplates.end(); + ++it) + { + QSharedPointer exportTemplate = it.value(); + + try + { + exportTemplate->fieldValueDelimiter = + this->readProjectFile(projectPath, exportTemplate->name + RecordExportFieldValueDelimiterExtension); + exportTemplate->fieldValueTemplate = + this->readProjectFile(projectPath, exportTemplate->name + RecordExportFieldValueTemplateExtension); + exportTemplate->recordDelimiter = + this->readProjectFile(projectPath, exportTemplate->name + RecordExportRecordDelimiterExtension); + exportTemplate->recordFileTemplate = + this->readProjectFile(projectPath, exportTemplate->name + RecordExportRecordFileTemplateExtension); + exportTemplate->recordTemplate = + this->readProjectFile(projectPath, exportTemplate->name + RecordExportRecordTemplateExtension); + exportTemplate->componentDelimiter = + this->readProjectFile(projectPath, exportTemplate->name + RecordExportComponentDelimiterExtension); + exportTemplate->componentTemplate = + this->readProjectFile(projectPath, exportTemplate->name + RecordExportComponentTemplateExtension); + } + catch (const std::runtime_error& e) + { + QMessageBox::critical( + this, + tr("Unable to open project"), + tr("File could not be read:\r\n") + e.what(), + QMessageBox::Close, + QMessageBox::Close); + return; + } + } + + // Add to recent projects. + TomeSettings settings; + settings.addRecentProject(projectFileName); + this->updateRecentProjects(); + + // Set project reference. + this->setProject(project); + } + else + { + // Remove from recent projects. + TomeSettings settings; + settings.removeRecentProject(projectFileName); + this->updateRecentProjects(); + + QMessageBox::critical( + this, + tr("Unable to open project"), + tr("File could not be read:\r\n") + projectFileName, + QMessageBox::Close, + QMessageBox::Close); + return; + } +} + QString MainWindow::readProjectFile(QString projectPath, QString fileName) { // Open export template file. @@ -866,6 +895,22 @@ void MainWindow::updateMenus() this->ui->actionRemove_Record->setEnabled(projectLoaded); } +void MainWindow::updateRecentProjects() +{ + // Clear menu. + this->ui->menuRecent_Projects->clear(); + + // Add recent projects. + TomeSettings settings; + QStringList recentProjects = settings.getRecentProjects(); + for (int i = 0; i < recentProjects.size(); ++i) + { + QString path = recentProjects.at(i); + QAction* action = new QAction(path, this); + this->ui->menuRecent_Projects->addAction(action); + } +} + void MainWindow::updateWindowTitle() { // Get application version. diff --git a/Source/Tome/mainwindow.h b/Source/Tome/mainwindow.h index f33a9a76..4f3f4e85 100644 --- a/Source/Tome/mainwindow.h +++ b/Source/Tome/mainwindow.h @@ -52,6 +52,7 @@ class MainWindow : public QMainWindow void on_tableView_doubleClicked(const QModelIndex &index); void exportRecords(QAction* exportAction); + void openRecentProject(QAction* recentProjectAction); void treeViewSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected); private: @@ -85,11 +86,13 @@ class MainWindow : public QMainWindow QString getFullProjectPath() const; QString getFullProjectPath(QSharedPointer project) const; QString getSelectedRecordDisplayName() const; + void openProject(QString path); QString readProjectFile(QString projectPath, QString fileName); bool saveProject(QSharedPointer project); void setProject(QSharedPointer project); void showWindow(QWidget* widget); void updateMenus(); + void updateRecentProjects(); void updateWindowTitle(); }; diff --git a/Source/Tome/mainwindow.ui b/Source/Tome/mainwindow.ui index b8807983..63a4f1dd 100644 --- a/Source/Tome/mainwindow.ui +++ b/Source/Tome/mainwindow.ui @@ -59,11 +59,18 @@ File + + + Recent Projects + + + + From 23bfa277706b47970347c0fb2822dddc04371d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Tue, 26 Jan 2016 20:55:22 +0100 Subject: [PATCH 02/72] CHANGED: Documentation - Removed roadmap from readme. --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index 59f7fbef..aacc6ce5 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,6 @@ The tool is pretty self-explanatory. However, to give you a headstart, feel free * Arbitrary output data formats through templates * Splitting data up into multiple files for improved collaboration -### In Development (subject to change) - -* Hierarchical record structure -* Data import from various sources such as Microsoft Excel -* Export and import of localization tables as CSV and TMX -* Command-line support for easy integration into CI and other tool chains - ## Development Cycle We know that using a tool like Tome in production requires you to be completely sure about stability and compatibility. Thus, new releases of Tome are created using [Semantic Versioning](http://semver.org/). In short: From 6ef4e8ea906f2aa0c4345a6eb8a8ce62ba02a1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Tue, 26 Jan 2016 21:45:07 +0100 Subject: [PATCH 03/72] CHANGED: Custom Types - Renamed custom type windows and references. --- Project/Tome.pro | 16 +++++----- Source/Tome/Types/customtypesitemmodel.cpp | 4 +-- Source/Tome/Types/customtypesitemmodel.h | 4 +-- Source/Tome/Types/customtypeswindow.cpp | 30 +++++++++---------- Source/Tome/Types/customtypeswindow.h | 4 +-- Source/Tome/Types/customtypeswindow.ui | 3 +- ...window.cpp => enumerationmemberwindow.cpp} | 12 ++++---- ...mberwindow.h => enumerationmemberwindow.h} | 6 ++-- ...erwindow.ui => enumerationmemberwindow.ui} | 0 ...omtypewindow.cpp => enumerationwindow.cpp} | 30 +++++++++---------- ...customtypewindow.h => enumerationwindow.h} | 10 +++---- ...stomtypewindow.ui => enumerationwindow.ui} | 0 12 files changed, 60 insertions(+), 59 deletions(-) rename Source/Tome/Types/{customtypememberwindow.cpp => enumerationmemberwindow.cpp} (78%) rename Source/Tome/Types/{customtypememberwindow.h => enumerationmemberwindow.h} (71%) rename Source/Tome/Types/{customtypememberwindow.ui => enumerationmemberwindow.ui} (100%) rename Source/Tome/Types/{customtypewindow.cpp => enumerationwindow.cpp} (63%) rename Source/Tome/Types/{customtypewindow.h => enumerationwindow.h} (72%) rename Source/Tome/Types/{customtypewindow.ui => enumerationwindow.ui} (100%) diff --git a/Project/Tome.pro b/Project/Tome.pro index 5f4acff2..c5359608 100644 --- a/Project/Tome.pro +++ b/Project/Tome.pro @@ -56,11 +56,11 @@ SOURCES += ../Source/Tome/main.cpp \ ../Source/Tome/Components/componentsitemmodel.cpp \ ../Source/Tome/Components/componentwindow.cpp \ ../Source/Tome/Types/customtypeswindow.cpp \ - ../Source/Tome/Types/customtypewindow.cpp \ - ../Source/Tome/Types/customtypememberwindow.cpp \ ../Source/Tome/Types/customtype.cpp \ ../Source/Tome/Types/customtypesitemmodel.cpp \ - ../Source/Tome/Settings/tomesettings.cpp + ../Source/Tome/Settings/tomesettings.cpp \ + ../Source/Tome/Types/enumerationwindow.cpp \ + ../Source/Tome/Types/enumerationmemberwindow.cpp HEADERS += ../Source/Tome/mainwindow.h \ ../Source/Tome/Types/builtintype.h \ @@ -91,11 +91,11 @@ HEADERS += ../Source/Tome/mainwindow.h \ ../Source/Tome/Components/componentsitemmodel.h \ ../Source/Tome/Components/componentwindow.h \ ../Source/Tome/Types/customtypeswindow.h \ - ../Source/Tome/Types/customtypewindow.h \ - ../Source/Tome/Types/customtypememberwindow.h \ ../Source/Tome/Types/customtype.h \ ../Source/Tome/Types/customtypesitemmodel.h \ - ../Source/Tome/Settings/tomesettings.h + ../Source/Tome/Settings/tomesettings.h \ + ../Source/Tome/Types/enumerationmemberwindow.h \ + ../Source/Tome/Types/enumerationwindow.h FORMS += ../Source/Tome/mainwindow.ui \ ../Source/Tome/Help/aboutwindow.ui \ @@ -107,8 +107,8 @@ FORMS += ../Source/Tome/mainwindow.ui \ ../Source/Tome/Components/componentswindow.ui \ ../Source/Tome/Components/componentwindow.ui \ ../Source/Tome/Types/customtypeswindow.ui \ - ../Source/Tome/Types/customtypewindow.ui \ - ../Source/Tome/Types/customtypememberwindow.ui + ../Source/Tome/Types/enumerationwindow.ui \ + ../Source/Tome/Types/enumerationmemberwindow.ui RESOURCES += \ tome.qrc diff --git a/Source/Tome/Types/customtypesitemmodel.cpp b/Source/Tome/Types/customtypesitemmodel.cpp index 1265a7b6..a3d3fb56 100644 --- a/Source/Tome/Types/customtypesitemmodel.cpp +++ b/Source/Tome/Types/customtypesitemmodel.cpp @@ -26,7 +26,7 @@ CustomTypesItemModel::CustomTypesItemModel(QSharedPointer project } } -void CustomTypesItemModel::addCustomType(const QString& name, const QStringList& enumeration) +void CustomTypesItemModel::addEnumeration(const QString& name, const QStringList& enumeration) { // Add type. QSharedPointer newType = QSharedPointer::create(); @@ -43,7 +43,7 @@ void CustomTypesItemModel::addCustomType(const QString& name, const QStringList& this->insertItem(newType->name); } -void CustomTypesItemModel::updateCustomType(const int index, const QString& name, const QStringList& enumeration) +void CustomTypesItemModel::updateEnumeration(const int index, const QString& name, const QStringList& enumeration) { // Get custom type. QSharedPointer type = this->project->types.at(index); diff --git a/Source/Tome/Types/customtypesitemmodel.h b/Source/Tome/Types/customtypesitemmodel.h index 6f4ec536..4a2bba29 100644 --- a/Source/Tome/Types/customtypesitemmodel.h +++ b/Source/Tome/Types/customtypesitemmodel.h @@ -12,8 +12,8 @@ namespace Tome public: CustomTypesItemModel(QSharedPointer project); - void addCustomType(const QString& name, const QStringList& enumeration); - void updateCustomType(const int index, const QString& name, const QStringList& enumeration); + void addEnumeration(const QString& name, const QStringList& enumeration); + void updateEnumeration(const int index, const QString& name, const QStringList& enumeration); void removeCustomType(const int index); private: diff --git a/Source/Tome/Types/customtypeswindow.cpp b/Source/Tome/Types/customtypeswindow.cpp index e9479400..daca29ca 100644 --- a/Source/Tome/Types/customtypeswindow.cpp +++ b/Source/Tome/Types/customtypeswindow.cpp @@ -7,7 +7,7 @@ using namespace Tome; CustomTypesWindow::CustomTypesWindow(QSharedPointer project, QWidget *parent) : QMainWindow(parent), ui(new Ui::CustomTypesWindow), - customTypeWindow(0), + enumerationWindow(0), project(project) { ui->setupUi(this); @@ -26,19 +26,19 @@ CustomTypesWindow::~CustomTypesWindow() void CustomTypesWindow::on_actionNew_Custom_Type_triggered() { // Show window. - if (!this->customTypeWindow) + if (!this->enumerationWindow) { - this->customTypeWindow = new CustomTypeWindow(this); + this->enumerationWindow = new EnumerationWindow(this); } - int result = this->customTypeWindow->exec(); + int result = this->enumerationWindow->exec(); if (result == QDialog::Accepted) { // Add new type. - this->viewModel->addCustomType( - this->customTypeWindow->getCustomTypeName(), - this->customTypeWindow->getCustomTypeEnumeration()); + this->viewModel->addEnumeration( + this->enumerationWindow->getCustomTypeName(), + this->enumerationWindow->getCustomTypeEnumeration()); } } @@ -56,24 +56,24 @@ void CustomTypesWindow::on_actionEdit_Custom_Type_triggered() QSharedPointer type = this->project->types[index]; // Show window. - if (!this->customTypeWindow) + if (!this->enumerationWindow) { - this->customTypeWindow = new CustomTypeWindow(this); + this->enumerationWindow = new EnumerationWindow(this); } // Update view. - this->customTypeWindow->setCustomTypeName(type->name); - this->customTypeWindow->setCustomTypeEnumeration(type->getEnumeration()); + this->enumerationWindow->setCustomTypeName(type->name); + this->enumerationWindow->setCustomTypeEnumeration(type->getEnumeration()); - int result = this->customTypeWindow->exec(); + int result = this->enumerationWindow->exec(); if (result == QDialog::Accepted) { // Update type. - this->viewModel->updateCustomType( + this->viewModel->updateEnumeration( index, - this->customTypeWindow->getCustomTypeName(), - this->customTypeWindow->getCustomTypeEnumeration()); + this->enumerationWindow->getCustomTypeName(), + this->enumerationWindow->getCustomTypeEnumeration()); } } diff --git a/Source/Tome/Types/customtypeswindow.h b/Source/Tome/Types/customtypeswindow.h index fce832a4..bd27515d 100644 --- a/Source/Tome/Types/customtypeswindow.h +++ b/Source/Tome/Types/customtypeswindow.h @@ -4,7 +4,7 @@ #include #include "customtypesitemmodel.h" -#include "customtypewindow.h" +#include "enumerationwindow.h" #include "../Projects/project.h" namespace Ui { @@ -29,7 +29,7 @@ class CustomTypesWindow : public QMainWindow private: Ui::CustomTypesWindow *ui; - CustomTypeWindow* customTypeWindow; + EnumerationWindow* enumerationWindow; QSharedPointer project; QSharedPointer viewModel; diff --git a/Source/Tome/Types/customtypeswindow.ui b/Source/Tome/Types/customtypeswindow.ui index 978e66ce..e0300064 100644 --- a/Source/Tome/Types/customtypeswindow.ui +++ b/Source/Tome/Types/customtypeswindow.ui @@ -38,6 +38,7 @@ Custom Types + @@ -66,7 +67,7 @@ - New Custom Type... + New Enumeration... Ctrl+N diff --git a/Source/Tome/Types/customtypememberwindow.cpp b/Source/Tome/Types/enumerationmemberwindow.cpp similarity index 78% rename from Source/Tome/Types/customtypememberwindow.cpp rename to Source/Tome/Types/enumerationmemberwindow.cpp index adaf9fb3..58336f04 100644 --- a/Source/Tome/Types/customtypememberwindow.cpp +++ b/Source/Tome/Types/enumerationmemberwindow.cpp @@ -1,27 +1,27 @@ -#include "customtypememberwindow.h" +#include "enumerationmemberwindow.h" #include "ui_customtypememberwindow.h" #include -CustomTypeMemberWindow::CustomTypeMemberWindow(QWidget *parent) : +EnumerationMemberWindow::EnumerationMemberWindow(QWidget *parent) : QDialog(parent), ui(new Ui::CustomTypeMemberWindow) { ui->setupUi(this); } -CustomTypeMemberWindow::~CustomTypeMemberWindow() +EnumerationMemberWindow::~EnumerationMemberWindow() { delete ui; } -QString CustomTypeMemberWindow::getText() const +QString EnumerationMemberWindow::getText() const { return this->ui->lineEdit->text(); } -void CustomTypeMemberWindow::accept() +void EnumerationMemberWindow::accept() { // Validate data. if (this->validate()) @@ -30,7 +30,7 @@ void CustomTypeMemberWindow::accept() } } -bool CustomTypeMemberWindow::validate() +bool EnumerationMemberWindow::validate() { // Name must not be empty. if (this->getText().isEmpty()) diff --git a/Source/Tome/Types/customtypememberwindow.h b/Source/Tome/Types/enumerationmemberwindow.h similarity index 71% rename from Source/Tome/Types/customtypememberwindow.h rename to Source/Tome/Types/enumerationmemberwindow.h index b3bf009d..f87559fe 100644 --- a/Source/Tome/Types/customtypememberwindow.h +++ b/Source/Tome/Types/enumerationmemberwindow.h @@ -7,13 +7,13 @@ namespace Ui { class CustomTypeMemberWindow; } -class CustomTypeMemberWindow : public QDialog +class EnumerationMemberWindow : public QDialog { Q_OBJECT public: - explicit CustomTypeMemberWindow(QWidget *parent = 0); - ~CustomTypeMemberWindow(); + explicit EnumerationMemberWindow(QWidget *parent = 0); + ~EnumerationMemberWindow(); QString getText() const; diff --git a/Source/Tome/Types/customtypememberwindow.ui b/Source/Tome/Types/enumerationmemberwindow.ui similarity index 100% rename from Source/Tome/Types/customtypememberwindow.ui rename to Source/Tome/Types/enumerationmemberwindow.ui diff --git a/Source/Tome/Types/customtypewindow.cpp b/Source/Tome/Types/enumerationwindow.cpp similarity index 63% rename from Source/Tome/Types/customtypewindow.cpp rename to Source/Tome/Types/enumerationwindow.cpp index d91565a9..ce712214 100644 --- a/Source/Tome/Types/customtypewindow.cpp +++ b/Source/Tome/Types/enumerationwindow.cpp @@ -1,15 +1,15 @@ -#include "customtypewindow.h" -#include "ui_customtypewindow.h" +#include "enumerationwindow.h" +#include "ui_enumerationwindow.h" #include using namespace Tome; -CustomTypeWindow::CustomTypeWindow(QWidget *parent) : +EnumerationWindow::EnumerationWindow(QWidget *parent) : QDialog(parent), ui(new Ui::CustomTypeWindow), - customTypeMemberWindow(0) + enumerationMemberWindow(0) { ui->setupUi(this); @@ -18,55 +18,55 @@ CustomTypeWindow::CustomTypeWindow(QWidget *parent) : this->ui->listView->setModel(model); } -CustomTypeWindow::~CustomTypeWindow() +EnumerationWindow::~EnumerationWindow() { delete ui; } -QString CustomTypeWindow::getCustomTypeName() const +QString EnumerationWindow::getCustomTypeName() const { return this->ui->lineEdit->text(); } -QStringList CustomTypeWindow::getCustomTypeEnumeration() const +QStringList EnumerationWindow::getCustomTypeEnumeration() const { QStringListModel* model = static_cast(this->ui->listView->model()); return model->stringList(); } -void CustomTypeWindow::setCustomTypeName(const QString& typeName) +void EnumerationWindow::setCustomTypeName(const QString& typeName) { this->ui->lineEdit->setText(typeName); } -void CustomTypeWindow::setCustomTypeEnumeration(const QStringList& enumeration) +void EnumerationWindow::setCustomTypeEnumeration(const QStringList& enumeration) { QStringListModel* model = static_cast(this->ui->listView->model()); model->setStringList(enumeration); } -void CustomTypeWindow::on_actionNew_Member_triggered() +void EnumerationWindow::on_actionNew_Member_triggered() { // Show window. - if (!this->customTypeMemberWindow) + if (!this->enumerationMemberWindow) { - this->customTypeMemberWindow = new CustomTypeMemberWindow(this); + this->enumerationMemberWindow = new EnumerationMemberWindow(this); } - int result = this->customTypeMemberWindow->exec(); + int result = this->enumerationMemberWindow->exec(); if (result == QDialog::Accepted) { // Add new type member. QStringListModel* model = static_cast(this->ui->listView->model()); QStringList stringList = model->stringList(); - stringList << this->customTypeMemberWindow->getText(); + stringList << this->enumerationMemberWindow->getText(); stringList.sort(); model->setStringList(stringList); } } -void CustomTypeWindow::on_actionDelete_Member_triggered() +void EnumerationWindow::on_actionDelete_Member_triggered() { QModelIndexList selectedIndexes = this->ui->listView->selectionModel()->selectedRows(); diff --git a/Source/Tome/Types/customtypewindow.h b/Source/Tome/Types/enumerationwindow.h similarity index 72% rename from Source/Tome/Types/customtypewindow.h rename to Source/Tome/Types/enumerationwindow.h index 05c083f4..9509a5c5 100644 --- a/Source/Tome/Types/customtypewindow.h +++ b/Source/Tome/Types/enumerationwindow.h @@ -4,19 +4,19 @@ #include #include "customtype.h" -#include "customtypememberwindow.h" +#include "enumerationmemberwindow.h" namespace Ui { class CustomTypeWindow; } -class CustomTypeWindow : public QDialog +class EnumerationWindow : public QDialog { Q_OBJECT public: - explicit CustomTypeWindow(QWidget *parent = 0); - ~CustomTypeWindow(); + explicit EnumerationWindow(QWidget *parent = 0); + ~EnumerationWindow(); QString getCustomTypeName() const; QStringList getCustomTypeEnumeration() const; @@ -31,7 +31,7 @@ class CustomTypeWindow : public QDialog private: Ui::CustomTypeWindow *ui; - CustomTypeMemberWindow* customTypeMemberWindow; + EnumerationMemberWindow* enumerationMemberWindow; }; #endif // CUSTOMTYPEWINDOW_H diff --git a/Source/Tome/Types/customtypewindow.ui b/Source/Tome/Types/enumerationwindow.ui similarity index 100% rename from Source/Tome/Types/customtypewindow.ui rename to Source/Tome/Types/enumerationwindow.ui From e8f937764fb5dd494dc393b6d4e3a170a8332fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Tue, 26 Jan 2016 22:27:52 +0100 Subject: [PATCH 04/72] ADDED: Custom Types - Adding list types. --- Project/Tome.pro | 9 +- Source/Tome/Fields/fielddefinitionwindow.cpp | 17 ++-- Source/Tome/Projects/project.cpp | 24 ++++++ Source/Tome/Projects/project.h | 6 ++ Source/Tome/Types/customtype.cpp | 8 +- Source/Tome/Types/customtype.h | 9 +- Source/Tome/Types/customtypesitemmodel.cpp | 17 ++++ Source/Tome/Types/customtypesitemmodel.h | 2 + Source/Tome/Types/customtypeswindow.cpp | 35 ++++++-- Source/Tome/Types/customtypeswindow.h | 4 + Source/Tome/Types/customtypeswindow.ui | 15 ++-- Source/Tome/Types/enumerationmemberwindow.cpp | 4 +- Source/Tome/Types/enumerationmemberwindow.h | 10 +-- Source/Tome/Types/enumerationmemberwindow.ui | 8 +- Source/Tome/Types/enumerationwindow.cpp | 10 +-- Source/Tome/Types/enumerationwindow.h | 18 ++-- Source/Tome/Types/enumerationwindow.ui | 8 +- Source/Tome/Types/listwindow.cpp | 49 +++++++++++ Source/Tome/Types/listwindow.h | 35 ++++++++ Source/Tome/Types/listwindow.ui | 84 +++++++++++++++++++ 20 files changed, 311 insertions(+), 61 deletions(-) create mode 100644 Source/Tome/Types/listwindow.cpp create mode 100644 Source/Tome/Types/listwindow.h create mode 100644 Source/Tome/Types/listwindow.ui diff --git a/Project/Tome.pro b/Project/Tome.pro index c5359608..2e2688ff 100644 --- a/Project/Tome.pro +++ b/Project/Tome.pro @@ -60,7 +60,8 @@ SOURCES += ../Source/Tome/main.cpp \ ../Source/Tome/Types/customtypesitemmodel.cpp \ ../Source/Tome/Settings/tomesettings.cpp \ ../Source/Tome/Types/enumerationwindow.cpp \ - ../Source/Tome/Types/enumerationmemberwindow.cpp + ../Source/Tome/Types/enumerationmemberwindow.cpp \ + ../Source/Tome/Types/listwindow.cpp HEADERS += ../Source/Tome/mainwindow.h \ ../Source/Tome/Types/builtintype.h \ @@ -95,7 +96,8 @@ HEADERS += ../Source/Tome/mainwindow.h \ ../Source/Tome/Types/customtypesitemmodel.h \ ../Source/Tome/Settings/tomesettings.h \ ../Source/Tome/Types/enumerationmemberwindow.h \ - ../Source/Tome/Types/enumerationwindow.h + ../Source/Tome/Types/enumerationwindow.h \ + ../Source/Tome/Types/listwindow.h FORMS += ../Source/Tome/mainwindow.ui \ ../Source/Tome/Help/aboutwindow.ui \ @@ -108,7 +110,8 @@ FORMS += ../Source/Tome/mainwindow.ui \ ../Source/Tome/Components/componentwindow.ui \ ../Source/Tome/Types/customtypeswindow.ui \ ../Source/Tome/Types/enumerationwindow.ui \ - ../Source/Tome/Types/enumerationmemberwindow.ui + ../Source/Tome/Types/enumerationmemberwindow.ui \ + ../Source/Tome/Types/listwindow.ui RESOURCES += \ tome.qrc diff --git a/Source/Tome/Fields/fielddefinitionwindow.cpp b/Source/Tome/Fields/fielddefinitionwindow.cpp index dd8a9081..b4bcf59d 100644 --- a/Source/Tome/Fields/fielddefinitionwindow.cpp +++ b/Source/Tome/Fields/fielddefinitionwindow.cpp @@ -106,19 +106,12 @@ void FieldDefinitionWindow::setProject(QSharedPointer project) // Set type names. this->ui->comboBoxType->clear(); - this->ui->comboBoxType->addItem(BuiltInType::Boolean); - this->ui->comboBoxType->addItem(BuiltInType::Color); - this->ui->comboBoxType->addItem(BuiltInType::Integer); - this->ui->comboBoxType->addItem(BuiltInType::Real); - this->ui->comboBoxType->addItem(BuiltInType::Reference); - this->ui->comboBoxType->addItem(BuiltInType::String); - - for (QVector >::iterator it = this->project->types.begin(); - it != this->project->types.end(); - ++it) + + QStringList typeNames = this->project->getTypeNames(); + + for (int i = 0; i < typeNames.length(); ++i) { - QSharedPointer type = *it; - this->ui->comboBoxType->addItem(type->name); + this->ui->comboBoxType->addItem(typeNames.at(i)); } } diff --git a/Source/Tome/Projects/project.cpp b/Source/Tome/Projects/project.cpp index 5d1b4b60..feaf1191 100644 --- a/Source/Tome/Projects/project.cpp +++ b/Source/Tome/Projects/project.cpp @@ -2,6 +2,9 @@ using namespace Tome; +#include "../Types/builtintype.h" + + Project::Project() { } @@ -130,3 +133,24 @@ QStringList Project::getRecordNames() const return names; } + +QStringList Project::getTypeNames() const +{ + QStringList typeNames; + typeNames.push_back(BuiltInType::Boolean); + typeNames.push_back(BuiltInType::Color); + typeNames.push_back(BuiltInType::Integer); + typeNames.push_back(BuiltInType::Real); + typeNames.push_back(BuiltInType::Reference); + typeNames.push_back(BuiltInType::String); + + for (QVector >::const_iterator it = this->types.begin(); + it != this->types.end(); + ++it) + { + QSharedPointer type = *it; + typeNames.push_back(type->name); + } + + return typeNames; +} diff --git a/Source/Tome/Projects/project.h b/Source/Tome/Projects/project.h index 606e502e..b43f7947 100644 --- a/Source/Tome/Projects/project.h +++ b/Source/Tome/Projects/project.h @@ -67,6 +67,12 @@ namespace Tome * @return List containing the names of all records of this project. */ QStringList getRecordNames() const; + + /** + * @brief getTypeNames Returns a list of all type names of this project, including built-in types. + * @return List containing the names of all types avaialable in this project. + */ + QStringList getTypeNames() const; }; } diff --git a/Source/Tome/Types/customtype.cpp b/Source/Tome/Types/customtype.cpp index fa477ded..b91f0f7c 100644 --- a/Source/Tome/Types/customtype.cpp +++ b/Source/Tome/Types/customtype.cpp @@ -4,6 +4,7 @@ using namespace Tome; const QString CustomType::RestrictionEnumeration = "Enumeration"; +const QString CustomType::RestrictionItemType = "ItemType"; CustomType::CustomType() @@ -21,8 +22,13 @@ QStringList CustomType::getEnumeration() return enumerationString.split(";"); } -void CustomType::setEnumeration(QStringList enumeration) +void CustomType::setEnumeration(const QStringList& enumeration) { QString enumerationString = enumeration.join(";"); this->restrictions[RestrictionEnumeration] = enumerationString; } + +void CustomType::setItemType(const QString& itemType) +{ + this->restrictions[RestrictionItemType] = itemType; +} diff --git a/Source/Tome/Types/customtype.h b/Source/Tome/Types/customtype.h index 437ceb6b..dea79c95 100644 --- a/Source/Tome/Types/customtype.h +++ b/Source/Tome/Types/customtype.h @@ -26,10 +26,17 @@ namespace Tome * @brief setEnumeration Sets the Enumeration restriction of this type. * @param enumeration Allowed field values. */ - void setEnumeration(QStringList enumeration); + void setEnumeration(const QStringList& enumeration); + + /** + * @brief setItemType Sets the Item Type restriction of this type. + * @param itemType Type of the list items. + */ + void setItemType(const QString& itemType); private: static const QString RestrictionEnumeration; + static const QString RestrictionItemType; }; } diff --git a/Source/Tome/Types/customtypesitemmodel.cpp b/Source/Tome/Types/customtypesitemmodel.cpp index a3d3fb56..de887068 100644 --- a/Source/Tome/Types/customtypesitemmodel.cpp +++ b/Source/Tome/Types/customtypesitemmodel.cpp @@ -43,6 +43,23 @@ void CustomTypesItemModel::addEnumeration(const QString& name, const QStringList this->insertItem(newType->name); } +void CustomTypesItemModel::addList(const QString& name, const QString& itemType) +{ + // Add type. + QSharedPointer newType = QSharedPointer::create(); + newType->name = name; + newType->baseType = BuiltInType::String; + newType->setItemType(itemType); + + this->project->types.push_back(newType); + + // Sort by name. + std::sort(this->project->types.begin(), this->project->types.end(), lessThanCustomTypes); + + // Insert item. + this->insertItem(newType->name); +} + void CustomTypesItemModel::updateEnumeration(const int index, const QString& name, const QStringList& enumeration) { // Get custom type. diff --git a/Source/Tome/Types/customtypesitemmodel.h b/Source/Tome/Types/customtypesitemmodel.h index 4a2bba29..8ffea211 100644 --- a/Source/Tome/Types/customtypesitemmodel.h +++ b/Source/Tome/Types/customtypesitemmodel.h @@ -13,6 +13,8 @@ namespace Tome CustomTypesItemModel(QSharedPointer project); void addEnumeration(const QString& name, const QStringList& enumeration); + void addList(const QString& name, const QString& itemType); + void updateEnumeration(const int index, const QString& name, const QStringList& enumeration); void removeCustomType(const int index); diff --git a/Source/Tome/Types/customtypeswindow.cpp b/Source/Tome/Types/customtypeswindow.cpp index daca29ca..a079e5cc 100644 --- a/Source/Tome/Types/customtypeswindow.cpp +++ b/Source/Tome/Types/customtypeswindow.cpp @@ -8,6 +8,7 @@ CustomTypesWindow::CustomTypesWindow(QSharedPointer project, QWid QMainWindow(parent), ui(new Ui::CustomTypesWindow), enumerationWindow(0), + listWindow(0), project(project) { ui->setupUi(this); @@ -37,8 +38,30 @@ void CustomTypesWindow::on_actionNew_Custom_Type_triggered() { // Add new type. this->viewModel->addEnumeration( - this->enumerationWindow->getCustomTypeName(), - this->enumerationWindow->getCustomTypeEnumeration()); + this->enumerationWindow->getEnumerationName(), + this->enumerationWindow->getEnumerationMembers()); + } +} + +void CustomTypesWindow::on_actionNew_List_triggered() +{ + // Show window. + if (!this->listWindow) + { + this->listWindow = new ListWindow(this); + } + + // Update type selection. + this->listWindow->setProject(this->project); + + int result = this->listWindow->exec(); + + if (result == QDialog::Accepted) + { + // Add new type. + this->viewModel->addList( + this->listWindow->getListName(), + this->listWindow->getListItemType()); } } @@ -62,8 +85,8 @@ void CustomTypesWindow::on_actionEdit_Custom_Type_triggered() } // Update view. - this->enumerationWindow->setCustomTypeName(type->name); - this->enumerationWindow->setCustomTypeEnumeration(type->getEnumeration()); + this->enumerationWindow->setEnumerationName(type->name); + this->enumerationWindow->setEnumerationMembers(type->getEnumeration()); int result = this->enumerationWindow->exec(); @@ -72,8 +95,8 @@ void CustomTypesWindow::on_actionEdit_Custom_Type_triggered() // Update type. this->viewModel->updateEnumeration( index, - this->enumerationWindow->getCustomTypeName(), - this->enumerationWindow->getCustomTypeEnumeration()); + this->enumerationWindow->getEnumerationName(), + this->enumerationWindow->getEnumerationMembers()); } } diff --git a/Source/Tome/Types/customtypeswindow.h b/Source/Tome/Types/customtypeswindow.h index bd27515d..ddad56cd 100644 --- a/Source/Tome/Types/customtypeswindow.h +++ b/Source/Tome/Types/customtypeswindow.h @@ -5,6 +5,7 @@ #include "customtypesitemmodel.h" #include "enumerationwindow.h" +#include "listwindow.h" #include "../Projects/project.h" namespace Ui { @@ -21,6 +22,8 @@ class CustomTypesWindow : public QMainWindow private slots: void on_actionNew_Custom_Type_triggered(); + void on_actionNew_List_triggered(); + void on_actionEdit_Custom_Type_triggered(); void on_actionDelete_Custom_Type_triggered(); @@ -30,6 +33,7 @@ class CustomTypesWindow : public QMainWindow Ui::CustomTypesWindow *ui; EnumerationWindow* enumerationWindow; + ListWindow* listWindow; QSharedPointer project; QSharedPointer viewModel; diff --git a/Source/Tome/Types/customtypeswindow.ui b/Source/Tome/Types/customtypeswindow.ui index e0300064..822abef6 100644 --- a/Source/Tome/Types/customtypeswindow.ui +++ b/Source/Tome/Types/customtypeswindow.ui @@ -38,6 +38,7 @@ Custom Types + @@ -57,21 +58,12 @@ false - - - - :/Media/Icons/AddUsingNamespace_6782.png - - New Enumeration... - - Ctrl+N - @@ -102,6 +94,11 @@ Esc + + + New List... + + diff --git a/Source/Tome/Types/enumerationmemberwindow.cpp b/Source/Tome/Types/enumerationmemberwindow.cpp index 58336f04..2d966269 100644 --- a/Source/Tome/Types/enumerationmemberwindow.cpp +++ b/Source/Tome/Types/enumerationmemberwindow.cpp @@ -1,12 +1,12 @@ #include "enumerationmemberwindow.h" -#include "ui_customtypememberwindow.h" +#include "ui_enumerationmemberwindow.h" #include EnumerationMemberWindow::EnumerationMemberWindow(QWidget *parent) : QDialog(parent), - ui(new Ui::CustomTypeMemberWindow) + ui(new Ui::EnumerationMemberWindow) { ui->setupUi(this); } diff --git a/Source/Tome/Types/enumerationmemberwindow.h b/Source/Tome/Types/enumerationmemberwindow.h index f87559fe..4530a299 100644 --- a/Source/Tome/Types/enumerationmemberwindow.h +++ b/Source/Tome/Types/enumerationmemberwindow.h @@ -1,10 +1,10 @@ -#ifndef CUSTOMTYPEMEMBERWINDOW_H -#define CUSTOMTYPEMEMBERWINDOW_H +#ifndef ENUMERATIONMEMBERWINDOW_H +#define ENUMERATIONMEMBERWINDOW_H #include namespace Ui { - class CustomTypeMemberWindow; + class EnumerationMemberWindow; } class EnumerationMemberWindow : public QDialog @@ -21,9 +21,9 @@ class EnumerationMemberWindow : public QDialog void accept(); private: - Ui::CustomTypeMemberWindow *ui; + Ui::EnumerationMemberWindow *ui; bool validate(); }; -#endif // CUSTOMTYPEMEMBERWINDOW_H +#endif // ENUMERATIONMEMBERWINDOW_H diff --git a/Source/Tome/Types/enumerationmemberwindow.ui b/Source/Tome/Types/enumerationmemberwindow.ui index b405797b..9f01fb18 100644 --- a/Source/Tome/Types/enumerationmemberwindow.ui +++ b/Source/Tome/Types/enumerationmemberwindow.ui @@ -1,7 +1,7 @@ - CustomTypeMemberWindow - + EnumerationMemberWindow + 0 @@ -41,7 +41,7 @@ buttonBox accepted() - CustomTypeMemberWindow + EnumerationMemberWindow accept() @@ -57,7 +57,7 @@ buttonBox rejected() - CustomTypeMemberWindow + EnumerationMemberWindow reject() diff --git a/Source/Tome/Types/enumerationwindow.cpp b/Source/Tome/Types/enumerationwindow.cpp index ce712214..d8c53756 100644 --- a/Source/Tome/Types/enumerationwindow.cpp +++ b/Source/Tome/Types/enumerationwindow.cpp @@ -8,7 +8,7 @@ using namespace Tome; EnumerationWindow::EnumerationWindow(QWidget *parent) : QDialog(parent), - ui(new Ui::CustomTypeWindow), + ui(new Ui::EnumerationWindow), enumerationMemberWindow(0) { ui->setupUi(this); @@ -23,23 +23,23 @@ EnumerationWindow::~EnumerationWindow() delete ui; } -QString EnumerationWindow::getCustomTypeName() const +QString EnumerationWindow::getEnumerationName() const { return this->ui->lineEdit->text(); } -QStringList EnumerationWindow::getCustomTypeEnumeration() const +QStringList EnumerationWindow::getEnumerationMembers() const { QStringListModel* model = static_cast(this->ui->listView->model()); return model->stringList(); } -void EnumerationWindow::setCustomTypeName(const QString& typeName) +void EnumerationWindow::setEnumerationName(const QString& typeName) { this->ui->lineEdit->setText(typeName); } -void EnumerationWindow::setCustomTypeEnumeration(const QStringList& enumeration) +void EnumerationWindow::setEnumerationMembers(const QStringList& enumeration) { QStringListModel* model = static_cast(this->ui->listView->model()); model->setStringList(enumeration); diff --git a/Source/Tome/Types/enumerationwindow.h b/Source/Tome/Types/enumerationwindow.h index 9509a5c5..42874cff 100644 --- a/Source/Tome/Types/enumerationwindow.h +++ b/Source/Tome/Types/enumerationwindow.h @@ -1,5 +1,5 @@ -#ifndef CUSTOMTYPEWINDOW_H -#define CUSTOMTYPEWINDOW_H +#ifndef ENUMERATIONWINDOW_H +#define ENUMERATIONWINDOW_H #include @@ -7,7 +7,7 @@ #include "enumerationmemberwindow.h" namespace Ui { - class CustomTypeWindow; + class EnumerationWindow; } class EnumerationWindow : public QDialog @@ -18,20 +18,20 @@ class EnumerationWindow : public QDialog explicit EnumerationWindow(QWidget *parent = 0); ~EnumerationWindow(); - QString getCustomTypeName() const; - QStringList getCustomTypeEnumeration() const; + QString getEnumerationName() const; + QStringList getEnumerationMembers() const; - void setCustomTypeName(const QString& typeName); - void setCustomTypeEnumeration(const QStringList& enumeration); + void setEnumerationName(const QString& typeName); + void setEnumerationMembers(const QStringList& enumeration); private slots: void on_actionNew_Member_triggered(); void on_actionDelete_Member_triggered(); private: - Ui::CustomTypeWindow *ui; + Ui::EnumerationWindow *ui; EnumerationMemberWindow* enumerationMemberWindow; }; -#endif // CUSTOMTYPEWINDOW_H +#endif // ENUMERATIONWINDOW_H diff --git a/Source/Tome/Types/enumerationwindow.ui b/Source/Tome/Types/enumerationwindow.ui index bbd2d2ed..60f76fa1 100644 --- a/Source/Tome/Types/enumerationwindow.ui +++ b/Source/Tome/Types/enumerationwindow.ui @@ -1,7 +1,7 @@ - CustomTypeWindow - + EnumerationWindow + 0 @@ -92,7 +92,7 @@ buttonBox accepted() - CustomTypeWindow + EnumerationWindow accept() @@ -108,7 +108,7 @@ buttonBox rejected() - CustomTypeWindow + EnumerationWindow reject() diff --git a/Source/Tome/Types/listwindow.cpp b/Source/Tome/Types/listwindow.cpp new file mode 100644 index 00000000..5cd52899 --- /dev/null +++ b/Source/Tome/Types/listwindow.cpp @@ -0,0 +1,49 @@ +#include "listwindow.h" +#include "ui_listwindow.h" + +ListWindow::ListWindow(QWidget *parent) : + QDialog(parent), + ui(new Ui::ListWindow) +{ + ui->setupUi(this); +} + +ListWindow::~ListWindow() +{ + delete ui; +} + +QString ListWindow::getListName() const +{ + return this->ui->lineEdit->text(); +} + +QString ListWindow::getListItemType() const +{ + return this->ui->comboBox->currentText(); +} + +void ListWindow::setListName(const QString& listName) +{ + this->ui->lineEdit->setText(listName); +} + +void ListWindow::setListItemType(const QString& itemType) +{ + this->ui->comboBox->setCurrentText(itemType); +} + +void ListWindow::setProject(QSharedPointer project) +{ + this->project = project; + + // Set type names. + this->ui->comboBox->clear(); + + QStringList typeNames = this->project->getTypeNames(); + + for (int i = 0; i < typeNames.length(); ++i) + { + this->ui->comboBox->addItem(typeNames.at(i)); + } +} diff --git a/Source/Tome/Types/listwindow.h b/Source/Tome/Types/listwindow.h new file mode 100644 index 00000000..6c3da0c1 --- /dev/null +++ b/Source/Tome/Types/listwindow.h @@ -0,0 +1,35 @@ +#ifndef LISTWINDOW_H +#define LISTWINDOW_H + +#include + +#include "../Projects/project.h" + + +namespace Ui { + class ListWindow; +} + +class ListWindow : public QDialog +{ + Q_OBJECT + + public: + explicit ListWindow(QWidget *parent = 0); + ~ListWindow(); + + QString getListName() const; + QString getListItemType() const; + + void setListName(const QString& listName); + void setListItemType(const QString& itemType); + + void setProject(QSharedPointer project); + + private: + Ui::ListWindow *ui; + + QSharedPointer project; +}; + +#endif // LISTWINDOW_H diff --git a/Source/Tome/Types/listwindow.ui b/Source/Tome/Types/listwindow.ui new file mode 100644 index 00000000..86c51b99 --- /dev/null +++ b/Source/Tome/Types/listwindow.ui @@ -0,0 +1,84 @@ + + + ListWindow + + + + 0 + 0 + 400 + 93 + + + + List + + + + + + Name: + + + + + + + + + + Item Type: + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + ListWindow + accept() + + + 286 + 75 + + + 157 + 92 + + + + + buttonBox + rejected() + ListWindow + reject() + + + 354 + 81 + + + 286 + 92 + + + + + From fa7b1781d2262ca9e7d58a601e895a19f115b961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Tue, 26 Jan 2016 22:30:56 +0100 Subject: [PATCH 05/72] ADDED: Custom Types - Validating list type data. --- Source/Tome/Types/listwindow.cpp | 41 ++++++++++++++++++++++++++++++++ Source/Tome/Types/listwindow.h | 5 ++++ 2 files changed, 46 insertions(+) diff --git a/Source/Tome/Types/listwindow.cpp b/Source/Tome/Types/listwindow.cpp index 5cd52899..3402a4d3 100644 --- a/Source/Tome/Types/listwindow.cpp +++ b/Source/Tome/Types/listwindow.cpp @@ -1,6 +1,9 @@ #include "listwindow.h" #include "ui_listwindow.h" +#include + + ListWindow::ListWindow(QWidget *parent) : QDialog(parent), ui(new Ui::ListWindow) @@ -47,3 +50,41 @@ void ListWindow::setProject(QSharedPointer project) this->ui->comboBox->addItem(typeNames.at(i)); } } + +void ListWindow::accept() +{ + // Validate data. + if (this->validate()) + { + this->done(Accepted); + } +} + +bool ListWindow::validate() +{ + // Name must not be empty. + if (this->getListName().isEmpty()) + { + QMessageBox::information( + this, + tr("Missing data"), + tr("Please specify a name for the list."), + QMessageBox::Close, + QMessageBox::Close); + return false; + } + + // Item type must not be empty. + if (this->getListItemType().isEmpty()) + { + QMessageBox::information( + this, + tr("Missing data"), + tr("Please specify a type for the items of the list."), + QMessageBox::Close, + QMessageBox::Close); + return false; + } + + return true; +} diff --git a/Source/Tome/Types/listwindow.h b/Source/Tome/Types/listwindow.h index 6c3da0c1..5c310ea0 100644 --- a/Source/Tome/Types/listwindow.h +++ b/Source/Tome/Types/listwindow.h @@ -26,10 +26,15 @@ class ListWindow : public QDialog void setProject(QSharedPointer project); + public slots: + void accept(); + private: Ui::ListWindow *ui; QSharedPointer project; + + bool validate(); }; #endif // LISTWINDOW_H From 4208fe37275423329369feda749d2f51216449a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Tue, 26 Jan 2016 22:40:50 +0100 Subject: [PATCH 06/72] ADDED: Custom Types - Editing list types. --- Source/Tome/Types/customtype.cpp | 22 ++++++- Source/Tome/Types/customtype.h | 9 +++ Source/Tome/Types/customtypesitemmodel.cpp | 14 +++++ Source/Tome/Types/customtypesitemmodel.h | 2 + Source/Tome/Types/customtypeswindow.cpp | 68 +++++++++++++++++----- Source/Tome/Types/customtypeswindow.h | 3 + 6 files changed, 103 insertions(+), 15 deletions(-) diff --git a/Source/Tome/Types/customtype.cpp b/Source/Tome/Types/customtype.cpp index b91f0f7c..f53969f9 100644 --- a/Source/Tome/Types/customtype.cpp +++ b/Source/Tome/Types/customtype.cpp @@ -13,7 +13,7 @@ CustomType::CustomType() QStringList CustomType::getEnumeration() { - if (!this->restrictions.contains(RestrictionEnumeration)) + if (!this->isEnumeration()) { return QStringList(); } @@ -22,6 +22,26 @@ QStringList CustomType::getEnumeration() return enumerationString.split(";"); } +QString CustomType::getItemType() +{ + if (!this->isList()) + { + return QString(); + } + + return this->restrictions[RestrictionItemType]; +} + +bool CustomType::isEnumeration() +{ + return this->restrictions.contains(RestrictionEnumeration); +} + +bool CustomType::isList() +{ + return this->restrictions.contains(RestrictionItemType); +} + void CustomType::setEnumeration(const QStringList& enumeration) { QString enumerationString = enumeration.join(";"); diff --git a/Source/Tome/Types/customtype.h b/Source/Tome/Types/customtype.h index dea79c95..1f0ed214 100644 --- a/Source/Tome/Types/customtype.h +++ b/Source/Tome/Types/customtype.h @@ -22,6 +22,15 @@ namespace Tome */ QStringList getEnumeration(); + /** + * @brief getItemType Convenience function for retrieving the Item Type restriction of this type, if available. Returns an empty string, if not. + * @return Item Type of this list, if available, and an empty string otherwise. + */ + QString getItemType(); + + bool isEnumeration(); + bool isList(); + /** * @brief setEnumeration Sets the Enumeration restriction of this type. * @param enumeration Allowed field values. diff --git a/Source/Tome/Types/customtypesitemmodel.cpp b/Source/Tome/Types/customtypesitemmodel.cpp index de887068..de59f424 100644 --- a/Source/Tome/Types/customtypesitemmodel.cpp +++ b/Source/Tome/Types/customtypesitemmodel.cpp @@ -74,6 +74,20 @@ void CustomTypesItemModel::updateEnumeration(const int index, const QString& nam this->updateItem(oldName, name); } +void CustomTypesItemModel::updateList(const int index, const QString& name, const QString& itemType) +{ + // Get custom type. + QSharedPointer type = this->project->types.at(index); + QString oldName = type->name; + + // Update type. + type->name = name; + type->setItemType(itemType); + + // Update item. + this->updateItem(oldName, name); +} + void CustomTypesItemModel::removeCustomType(const int index) { // Remove type. diff --git a/Source/Tome/Types/customtypesitemmodel.h b/Source/Tome/Types/customtypesitemmodel.h index 8ffea211..aa646b64 100644 --- a/Source/Tome/Types/customtypesitemmodel.h +++ b/Source/Tome/Types/customtypesitemmodel.h @@ -16,6 +16,8 @@ namespace Tome void addList(const QString& name, const QString& itemType); void updateEnumeration(const int index, const QString& name, const QStringList& enumeration); + void updateList(const int index, const QString& name, const QString& itemType); + void removeCustomType(const int index); private: diff --git a/Source/Tome/Types/customtypeswindow.cpp b/Source/Tome/Types/customtypeswindow.cpp index a079e5cc..ee1908fb 100644 --- a/Source/Tome/Types/customtypeswindow.cpp +++ b/Source/Tome/Types/customtypeswindow.cpp @@ -78,6 +78,41 @@ void CustomTypesWindow::on_actionEdit_Custom_Type_triggered() int index = selectedIndexes.first().row(); QSharedPointer type = this->project->types[index]; + // Check type. + if (type->isEnumeration()) + { + this->editEnumeration(index, type); + } + else if (type->isList()) + { + this->editList(index, type); + } +} + +void CustomTypesWindow::on_actionDelete_Custom_Type_triggered() +{ + // Get selected type. + QModelIndexList selectedIndexes = this->ui->listView->selectionModel()->selectedRows(); + + if (selectedIndexes.isEmpty()) + { + return; + } + + int index = selectedIndexes.first().row(); + + // Delete type. + this->viewModel->removeCustomType(index); +} + +void CustomTypesWindow::on_listView_doubleClicked(const QModelIndex &index) +{ + Q_UNUSED(index); + this->on_actionEdit_Custom_Type_triggered(); +} + +void CustomTypesWindow::editEnumeration(int index, QSharedPointer type) +{ // Show window. if (!this->enumerationWindow) { @@ -100,24 +135,29 @@ void CustomTypesWindow::on_actionEdit_Custom_Type_triggered() } } -void CustomTypesWindow::on_actionDelete_Custom_Type_triggered() +void CustomTypesWindow::editList(int index, QSharedPointer type) { - // Get selected type. - QModelIndexList selectedIndexes = this->ui->listView->selectionModel()->selectedRows(); - - if (selectedIndexes.isEmpty()) + // Show window. + if (!this->listWindow) { - return; + this->listWindow = new ListWindow(this); } - int index = selectedIndexes.first().row(); + // Update type selection. + this->listWindow->setProject(this->project); - // Delete type. - this->viewModel->removeCustomType(index); -} + // Update view. + this->listWindow->setListName(type->name); + this->listWindow->setListItemType(type->getItemType()); -void CustomTypesWindow::on_listView_doubleClicked(const QModelIndex &index) -{ - Q_UNUSED(index); - this->on_actionEdit_Custom_Type_triggered(); + int result = this->listWindow->exec(); + + if (result == QDialog::Accepted) + { + // Update type. + this->viewModel->updateList( + index, + this->listWindow->getListName(), + this->listWindow->getListItemType()); + } } diff --git a/Source/Tome/Types/customtypeswindow.h b/Source/Tome/Types/customtypeswindow.h index ddad56cd..64ac3fdd 100644 --- a/Source/Tome/Types/customtypeswindow.h +++ b/Source/Tome/Types/customtypeswindow.h @@ -37,6 +37,9 @@ class CustomTypesWindow : public QMainWindow QSharedPointer project; QSharedPointer viewModel; + + void editEnumeration(int index, QSharedPointer type); + void editList(int index, QSharedPointer type); }; #endif // CUSTOMTYPESWINDOW_H From a156b1891c875b752c83fb00d15cec177ad54ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Tue, 26 Jan 2016 23:06:30 +0100 Subject: [PATCH 07/72] ADDED: Custom Types - Showing name, type and details in the custom type overview window. --- Project/Tome.pro | 8 +- Source/Tome/Types/customtypesitemmodel.cpp | 112 ----------- Source/Tome/Types/customtypesitemmodel.h | 31 --- Source/Tome/Types/customtypestablemodel.cpp | 206 ++++++++++++++++++++ Source/Tome/Types/customtypestablemodel.h | 36 ++++ Source/Tome/Types/customtypeswindow.cpp | 25 +-- Source/Tome/Types/customtypeswindow.h | 8 +- Source/Tome/Types/customtypeswindow.ui | 15 +- 8 files changed, 277 insertions(+), 164 deletions(-) delete mode 100644 Source/Tome/Types/customtypesitemmodel.cpp delete mode 100644 Source/Tome/Types/customtypesitemmodel.h create mode 100644 Source/Tome/Types/customtypestablemodel.cpp create mode 100644 Source/Tome/Types/customtypestablemodel.h diff --git a/Project/Tome.pro b/Project/Tome.pro index 2e2688ff..5b74856a 100644 --- a/Project/Tome.pro +++ b/Project/Tome.pro @@ -57,11 +57,11 @@ SOURCES += ../Source/Tome/main.cpp \ ../Source/Tome/Components/componentwindow.cpp \ ../Source/Tome/Types/customtypeswindow.cpp \ ../Source/Tome/Types/customtype.cpp \ - ../Source/Tome/Types/customtypesitemmodel.cpp \ ../Source/Tome/Settings/tomesettings.cpp \ ../Source/Tome/Types/enumerationwindow.cpp \ ../Source/Tome/Types/enumerationmemberwindow.cpp \ - ../Source/Tome/Types/listwindow.cpp + ../Source/Tome/Types/listwindow.cpp \ + ../Source/Tome/Types/customtypestablemodel.cpp HEADERS += ../Source/Tome/mainwindow.h \ ../Source/Tome/Types/builtintype.h \ @@ -93,11 +93,11 @@ HEADERS += ../Source/Tome/mainwindow.h \ ../Source/Tome/Components/componentwindow.h \ ../Source/Tome/Types/customtypeswindow.h \ ../Source/Tome/Types/customtype.h \ - ../Source/Tome/Types/customtypesitemmodel.h \ ../Source/Tome/Settings/tomesettings.h \ ../Source/Tome/Types/enumerationmemberwindow.h \ ../Source/Tome/Types/enumerationwindow.h \ - ../Source/Tome/Types/listwindow.h + ../Source/Tome/Types/listwindow.h \ + ../Source/Tome/Types/customtypestablemodel.h FORMS += ../Source/Tome/mainwindow.ui \ ../Source/Tome/Help/aboutwindow.ui \ diff --git a/Source/Tome/Types/customtypesitemmodel.cpp b/Source/Tome/Types/customtypesitemmodel.cpp deleted file mode 100644 index de59f424..00000000 --- a/Source/Tome/Types/customtypesitemmodel.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "customtypesitemmodel.h" - -#include "../Types/builtintype.h" - -using namespace Tome; - - -bool lessThanCustomTypes(QSharedPointer e1, QSharedPointer e2) -{ - return e1->name.toLower() < e2->name.toLower(); -} - - -CustomTypesItemModel::CustomTypesItemModel(QSharedPointer project) - : QStandardItemModel(), - project(project) -{ - QVector >& types = this->project->types; - - for (QVector >::iterator it = types.begin(); - it != types.end(); - ++it) - { - QSharedPointer type = *it; - this->insertItem(type->name); - } -} - -void CustomTypesItemModel::addEnumeration(const QString& name, const QStringList& enumeration) -{ - // Add type. - QSharedPointer newType = QSharedPointer::create(); - newType->name = name; - newType->baseType = BuiltInType::String; - newType->setEnumeration(enumeration); - - this->project->types.push_back(newType); - - // Sort by name. - std::sort(this->project->types.begin(), this->project->types.end(), lessThanCustomTypes); - - // Insert item. - this->insertItem(newType->name); -} - -void CustomTypesItemModel::addList(const QString& name, const QString& itemType) -{ - // Add type. - QSharedPointer newType = QSharedPointer::create(); - newType->name = name; - newType->baseType = BuiltInType::String; - newType->setItemType(itemType); - - this->project->types.push_back(newType); - - // Sort by name. - std::sort(this->project->types.begin(), this->project->types.end(), lessThanCustomTypes); - - // Insert item. - this->insertItem(newType->name); -} - -void CustomTypesItemModel::updateEnumeration(const int index, const QString& name, const QStringList& enumeration) -{ - // Get custom type. - QSharedPointer type = this->project->types.at(index); - QString oldName = type->name; - - // Update type. - type->name = name; - type->setEnumeration(enumeration); - - // Update item. - this->updateItem(oldName, name); -} - -void CustomTypesItemModel::updateList(const int index, const QString& name, const QString& itemType) -{ - // Get custom type. - QSharedPointer type = this->project->types.at(index); - QString oldName = type->name; - - // Update type. - type->name = name; - type->setItemType(itemType); - - // Update item. - this->updateItem(oldName, name); -} - -void CustomTypesItemModel::removeCustomType(const int index) -{ - // Remove type. - this->project->types.removeAt(index); - - // Remove item. - this->removeRow(index); -} - -void CustomTypesItemModel::insertItem(const QString& text) -{ - QStandardItem* rootItem = this->invisibleRootItem(); - rootItem->appendRow(new QStandardItem(text)); - rootItem->sortChildren(0); -} - -void CustomTypesItemModel::updateItem(const QString& oldText, const QString& newText) -{ - QStandardItem* item = this->findItems(oldText).first(); - QModelIndex index = this->indexFromItem(item); - this->setData(index, newText, Qt::DisplayRole); -} diff --git a/Source/Tome/Types/customtypesitemmodel.h b/Source/Tome/Types/customtypesitemmodel.h deleted file mode 100644 index aa646b64..00000000 --- a/Source/Tome/Types/customtypesitemmodel.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef CUSTOMFIELDTYPESITEMMODEL_H -#define CUSTOMFIELDTYPESITEMMODEL_H - -#include - -#include "../Projects/project.h" - -namespace Tome -{ - class CustomTypesItemModel : public QStandardItemModel - { - public: - CustomTypesItemModel(QSharedPointer project); - - void addEnumeration(const QString& name, const QStringList& enumeration); - void addList(const QString& name, const QString& itemType); - - void updateEnumeration(const int index, const QString& name, const QStringList& enumeration); - void updateList(const int index, const QString& name, const QString& itemType); - - void removeCustomType(const int index); - - private: - QSharedPointer project; - - void insertItem(const QString& text); - void updateItem(const QString& oldText, const QString& newText); - }; -} - -#endif // CUSTOMFIELDTYPESITEMMODEL_H diff --git a/Source/Tome/Types/customtypestablemodel.cpp b/Source/Tome/Types/customtypestablemodel.cpp new file mode 100644 index 00000000..0dad5142 --- /dev/null +++ b/Source/Tome/Types/customtypestablemodel.cpp @@ -0,0 +1,206 @@ +#include "customtypestablemodel.h" + +#include "../Types/builtintype.h" + +using namespace Tome; + + +bool lessThanCustomTypes(QSharedPointer e1, QSharedPointer e2) +{ + return e1->name.toLower() < e2->name.toLower(); +} + + +CustomTypesTableModel::CustomTypesTableModel(QObject *parent, QSharedPointer project) + : QAbstractTableModel(parent), + project(project) +{ +} + +int CustomTypesTableModel::rowCount(const QModelIndex& parent) const +{ + Q_UNUSED(parent); + return this->project->types.length(); +} + +int CustomTypesTableModel::columnCount(const QModelIndex& parent) const +{ + Q_UNUSED(parent); + return 3; +} + +QVariant CustomTypesTableModel::data(const QModelIndex& index, int role) const +{ + // Validate index. + if (!index.isValid()) + { + return QVariant(); + } + + if (index.row() >= this->rowCount()) + { + return QVariant(); + } + + // Select type. + QSharedPointer type = this->project->types[index.row()]; + + if (role == Qt::DisplayRole) + { + switch (index.column()) + { + case 0: + return type->name; + + case 1: + if (type->isEnumeration()) + { + return "Enumeration"; + } + else if (type->isList()) + { + return "List"; + } + else + { + return QVariant(); + } + + case 2: + if (type->isEnumeration()) + { + return type->getEnumeration().join(", "); + } + else if (type->isList()) + { + return type->getItemType(); + } + else + { + return QVariant(); + } + } + + return QVariant(); + } + + return QVariant(); +} + +QVariant CustomTypesTableModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::DisplayRole) + { + if (orientation == Qt::Horizontal) { + switch (section) + { + case 0: + return QString("Id"); + case 1: + return QString("Type"); + case 2: + return QString("Details"); + } + } + } + return QVariant(); +} + +bool CustomTypesTableModel::insertRows(int position, int rows, const QModelIndex& index) +{ + Q_UNUSED(index); + beginInsertRows(QModelIndex(), position, position + rows - 1); + + // Add new custom types. + for (int row = 0; row < rows; ++row) + { + QSharedPointer type = QSharedPointer::create(); + this->project->types.insert(position, type); + } + + endInsertRows(); + return true; +} + +bool CustomTypesTableModel::removeRows(int position, int rows, const QModelIndex& index) +{ + Q_UNUSED(index); + beginRemoveRows(QModelIndex(), position, position + rows - 1); + + // Remove field definitions. + for (int row = 0; row < rows; ++row) + { + this->project->types.removeAt(position); + } + + endRemoveRows(); + return true; +} + +void CustomTypesTableModel::addEnumeration(const QString& name, const QStringList& enumeration) +{ + int index = this->rowCount(); + + // Insert row at the end. + this->insertRows(index, 1, QModelIndex()); + + // Update type. + this->updateEnumeration(index, name, enumeration); +} + +void CustomTypesTableModel::addList(const QString& name, const QString& itemType) +{ + int index = this->rowCount(); + + // Insert row at the end. + this->insertRows(index, 1, QModelIndex()); + + // Update type. + this->updateList(index, name, itemType); +} + +void CustomTypesTableModel::updateEnumeration(const int index, const QString& name, const QStringList& enumeration) +{ + // Get custom type. + QSharedPointer type = this->project->types.at(index); + + // Set data. + type->name = name; + type->baseType = BuiltInType::String; + type->setEnumeration(enumeration); + + // Sort by display name. + std::sort(this->project->types.begin(), this->project->types.end(), lessThanCustomTypes); + + // Update view. + QModelIndex first = this->index(0, 0, QModelIndex()); + QModelIndex last = this->index(this->rowCount() - 1, 3, QModelIndex()); + + emit(dataChanged(first, last)); +} + +void CustomTypesTableModel::updateList(const int index, const QString& name, const QString& itemType) +{ + // Get custom type. + QSharedPointer type = this->project->types.at(index); + + // Set data. + type->name = name; + type->baseType = BuiltInType::None; + type->setItemType(itemType); + + // Sort by display name. + std::sort(this->project->types.begin(), this->project->types.end(), lessThanCustomTypes); + + // Update view. + QModelIndex first = this->index(0, 0, QModelIndex()); + QModelIndex last = this->index(this->rowCount() - 1, 3, QModelIndex()); + + emit(dataChanged(first, last)); +} + +void CustomTypesTableModel::removeCustomType(const int index) +{ + // Remove row. + this->removeRows(index, 1, QModelIndex()); +} diff --git a/Source/Tome/Types/customtypestablemodel.h b/Source/Tome/Types/customtypestablemodel.h new file mode 100644 index 00000000..f789173d --- /dev/null +++ b/Source/Tome/Types/customtypestablemodel.h @@ -0,0 +1,36 @@ +#ifndef CUSTOMFIELDTYPESITEMMODEL_H +#define CUSTOMFIELDTYPESITEMMODEL_H + +#include + +#include "../Projects/project.h" + +namespace Tome +{ + class CustomTypesTableModel : public QAbstractTableModel + { + public: + CustomTypesTableModel(QObject *parent, QSharedPointer project); + + int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE ; + int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + + bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()) Q_DECL_OVERRIDE; + bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()) Q_DECL_OVERRIDE; + + void addEnumeration(const QString& name, const QStringList& enumeration); + void addList(const QString& name, const QString& itemType); + + void updateEnumeration(const int index, const QString& name, const QStringList& enumeration); + void updateList(const int index, const QString& name, const QString& itemType); + + void removeCustomType(const int index); + + private: + QSharedPointer project; + }; +} + +#endif // CUSTOMFIELDTYPESITEMMODEL_H diff --git a/Source/Tome/Types/customtypeswindow.cpp b/Source/Tome/Types/customtypeswindow.cpp index ee1908fb..720efdf8 100644 --- a/Source/Tome/Types/customtypeswindow.cpp +++ b/Source/Tome/Types/customtypeswindow.cpp @@ -13,10 +13,10 @@ CustomTypesWindow::CustomTypesWindow(QSharedPointer project, QWid { ui->setupUi(this); - CustomTypesItemModel* model = new CustomTypesItemModel(project); - this->viewModel = QSharedPointer(model); + CustomTypesTableModel* model = new CustomTypesTableModel(this, project); + this->viewModel = QSharedPointer(model); - this->ui->listView->setModel(model); + this->ui->tableView->setModel(model); } CustomTypesWindow::~CustomTypesWindow() @@ -68,14 +68,13 @@ void CustomTypesWindow::on_actionNew_List_triggered() void CustomTypesWindow::on_actionEdit_Custom_Type_triggered() { // Get selected type. - QModelIndexList selectedIndexes = this->ui->listView->selectionModel()->selectedRows(); + int index = getSelectedTypeIndex(); - if (selectedIndexes.isEmpty()) + if (index < 0) { return; } - int index = selectedIndexes.first().row(); QSharedPointer type = this->project->types[index]; // Check type. @@ -92,25 +91,29 @@ void CustomTypesWindow::on_actionEdit_Custom_Type_triggered() void CustomTypesWindow::on_actionDelete_Custom_Type_triggered() { // Get selected type. - QModelIndexList selectedIndexes = this->ui->listView->selectionModel()->selectedRows(); + int index = getSelectedTypeIndex(); - if (selectedIndexes.isEmpty()) + if (index < 0) { return; } - int index = selectedIndexes.first().row(); - // Delete type. this->viewModel->removeCustomType(index); } -void CustomTypesWindow::on_listView_doubleClicked(const QModelIndex &index) +void CustomTypesWindow::on_tableView_doubleClicked(const QModelIndex &index) { Q_UNUSED(index); this->on_actionEdit_Custom_Type_triggered(); } +int CustomTypesWindow::getSelectedTypeIndex() const +{ + QModelIndexList selectedIndexes = this->ui->tableView->selectionModel()->selectedRows(); + return selectedIndexes.count() > 0 ? selectedIndexes.first().row() : -1; +} + void CustomTypesWindow::editEnumeration(int index, QSharedPointer type) { // Show window. diff --git a/Source/Tome/Types/customtypeswindow.h b/Source/Tome/Types/customtypeswindow.h index 64ac3fdd..8ed8d6ef 100644 --- a/Source/Tome/Types/customtypeswindow.h +++ b/Source/Tome/Types/customtypeswindow.h @@ -3,7 +3,7 @@ #include -#include "customtypesitemmodel.h" +#include "customtypestablemodel.h" #include "enumerationwindow.h" #include "listwindow.h" #include "../Projects/project.h" @@ -27,7 +27,7 @@ class CustomTypesWindow : public QMainWindow void on_actionEdit_Custom_Type_triggered(); void on_actionDelete_Custom_Type_triggered(); - void on_listView_doubleClicked(const QModelIndex &index); + void on_tableView_doubleClicked(const QModelIndex &index); private: Ui::CustomTypesWindow *ui; @@ -36,7 +36,9 @@ class CustomTypesWindow : public QMainWindow ListWindow* listWindow; QSharedPointer project; - QSharedPointer viewModel; + QSharedPointer viewModel; + + int getSelectedTypeIndex() const; void editEnumeration(int index, QSharedPointer type); void editList(int index, QSharedPointer type); diff --git a/Source/Tome/Types/customtypeswindow.ui b/Source/Tome/Types/customtypeswindow.ui index 822abef6..c800619e 100644 --- a/Source/Tome/Types/customtypeswindow.ui +++ b/Source/Tome/Types/customtypeswindow.ui @@ -16,10 +16,19 @@ - - - QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SingleSelection + + QAbstractItemView::SelectRows + + + true + + + false + From e40373edad465a31aa67500866977f900cad8806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 27 Jan 2016 21:26:48 +0100 Subject: [PATCH 08/72] ADDED: Custom Types - Allowing both enumerations and lists in field definition windows and field value windows. --- Source/Tome/Fields/fielddefinitionwindow.cpp | 10 ++++-- Source/Tome/Fields/fieldvaluewidget.cpp | 20 ++++++++++-- Source/Tome/Fields/fieldvaluewidget.h | 8 ++++- Source/Tome/Fields/fieldvaluewindow.cpp | 6 ++++ Source/Tome/Fields/fieldvaluewindow.h | 2 ++ Source/Tome/Fields/listwidget.cpp | 33 +++++++++++++++++++ Source/Tome/Fields/listwidget.h | 34 ++++++++++++++++++++ Source/Tome/mainwindow.cpp | 9 ++++-- 8 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 Source/Tome/Fields/listwidget.cpp create mode 100644 Source/Tome/Fields/listwidget.h diff --git a/Source/Tome/Fields/fielddefinitionwindow.cpp b/Source/Tome/Fields/fielddefinitionwindow.cpp index b4bcf59d..f738f1c0 100644 --- a/Source/Tome/Fields/fielddefinitionwindow.cpp +++ b/Source/Tome/Fields/fielddefinitionwindow.cpp @@ -125,6 +125,7 @@ void FieldDefinitionWindow::on_comboBoxType_currentIndexChanged(const QString &f recordNames << QString(); this->fieldValueWidget->setEnumeration(recordNames); + this->fieldValueWidget->setFieldType(fieldType); } else { @@ -132,11 +133,14 @@ void FieldDefinitionWindow::on_comboBoxType_currentIndexChanged(const QString &f if (type != 0) { - this->fieldValueWidget->setEnumeration(type->getEnumeration()); + this->fieldValueWidget->setCustomFieldType(type); + } + else + { + // Default built-in type. + this->fieldValueWidget->setFieldType(fieldType); } } - - this->fieldValueWidget->setFieldType(fieldType); } void FieldDefinitionWindow::on_lineEditDisplayName_textEdited(const QString &displayName) diff --git a/Source/Tome/Fields/fieldvaluewidget.cpp b/Source/Tome/Fields/fieldvaluewidget.cpp index e42f57a7..5d594a3a 100644 --- a/Source/Tome/Fields/fieldvaluewidget.cpp +++ b/Source/Tome/Fields/fieldvaluewidget.cpp @@ -40,6 +40,10 @@ FieldValueWidget::FieldValueWidget(QWidget *parent) : this->comboBox = new QComboBox(); this->addWidget(this->comboBox); + this->listWidget = new ListWidget(); + this->addWidget(this->listWidget); + + // Set layout. this->setLayout(this->layout); this->layout->setContentsMargins(0, 0, 0, 0); @@ -125,9 +129,21 @@ void FieldValueWidget::setFieldType(const QString& fieldType) this->setCurrentWidget(this->lineEdit); return; } +} - // Custom datatype. - this->setCurrentWidget(this->comboBox); +void FieldValueWidget::setCustomFieldType(QSharedPointer fieldType) +{ + this->fieldType = fieldType->name; + + if (fieldType->isEnumeration()) + { + this->setEnumeration(fieldType->getEnumeration()); + this->setCurrentWidget(this->comboBox); + } + else if (fieldType->isList()) + { + this->setCurrentWidget(this->listWidget); + } } void FieldValueWidget::setFieldValue(const QString& fieldValue) diff --git a/Source/Tome/Fields/fieldvaluewidget.h b/Source/Tome/Fields/fieldvaluewidget.h index dac2e739..a83dce75 100644 --- a/Source/Tome/Fields/fieldvaluewidget.h +++ b/Source/Tome/Fields/fieldvaluewidget.h @@ -12,10 +12,14 @@ #include #include +#include "listwidget.h" +#include "../Types/customtype.h" + + namespace Tome { /** - * @brief Widget that changes its appearance depending on the specified type. + * @brief Changes its appearance depending on the specified type. */ class FieldValueWidget : public QWidget { @@ -29,6 +33,7 @@ namespace Tome QString getFieldValue() const; void setFieldType(const QString& fieldType); + void setCustomFieldType(QSharedPointer fieldType); void setFieldValue(const QString& fieldValue); void setEnumeration(const QStringList& enumeration); @@ -46,6 +51,7 @@ namespace Tome QLineEdit* lineEdit; QComboBox* comboBox; QSpinBox* spinBox; + ListWidget* listWidget; void addWidget(QWidget* widget); void setCurrentWidget(QWidget* widget); diff --git a/Source/Tome/Fields/fieldvaluewindow.cpp b/Source/Tome/Fields/fieldvaluewindow.cpp index 1d531ef4..235189aa 100644 --- a/Source/Tome/Fields/fieldvaluewindow.cpp +++ b/Source/Tome/Fields/fieldvaluewindow.cpp @@ -43,6 +43,12 @@ void FieldValueWindow::setFieldValue(const QString& fieldValue) this->fieldValueWidget->setFieldValue(fieldValue); } +void FieldValueWindow::setCustomFieldType(QSharedPointer fieldType) +{ + this->ui->labelTypeValue->setText(fieldType->name); + this->fieldValueWidget->setCustomFieldType(fieldType); +} + void FieldValueWindow::setFieldType(const QString& fieldType) const { this->ui->labelTypeValue->setText(fieldType); diff --git a/Source/Tome/Fields/fieldvaluewindow.h b/Source/Tome/Fields/fieldvaluewindow.h index 1734fa15..68adbfdd 100644 --- a/Source/Tome/Fields/fieldvaluewindow.h +++ b/Source/Tome/Fields/fieldvaluewindow.h @@ -4,6 +4,7 @@ #include #include "../Fields/fieldvaluewidget.h" +#include "../Types/customtype.h" namespace Ui { @@ -23,6 +24,7 @@ class FieldValueWindow : public QDialog void setFieldDescription(const QString& description); void setFieldDisplayName(const QString& displayName); void setFieldValue(const QString& fieldValue); + void setCustomFieldType(QSharedPointer fieldType); void setFieldType(const QString& fieldType) const; void setEnumeration(const QStringList& recordNames); diff --git a/Source/Tome/Fields/listwidget.cpp b/Source/Tome/Fields/listwidget.cpp new file mode 100644 index 00000000..9356221b --- /dev/null +++ b/Source/Tome/Fields/listwidget.cpp @@ -0,0 +1,33 @@ +#include "listwidget.h" + +using namespace Tome; + + +ListWidget::ListWidget(QWidget *parent) : + QWidget(parent) +{ + // Create layout. + this->layout = new QHBoxLayout(this); + + // Add list view. + this->listView = new QListView(this); + this->layout->addWidget(this->listView); + + // Set layout. + this->setLayout(this->layout); + this->layout->setContentsMargins(0, 0, 0, 0); +} + +ListWidget::~ListWidget() +{ +} + +QString ListWidget::getFieldType() const +{ + return this->fieldType; +} + +void ListWidget::setFieldType(const QString& fieldType) +{ + this->fieldType = fieldType; +} diff --git a/Source/Tome/Fields/listwidget.h b/Source/Tome/Fields/listwidget.h new file mode 100644 index 00000000..8e670969 --- /dev/null +++ b/Source/Tome/Fields/listwidget.h @@ -0,0 +1,34 @@ +#ifndef LISTWIDGET_H +#define LISTWIDGET_H + +#include +#include +#include +#include + + +namespace Tome +{ + /** + * @brief Allows adding, editing, re-ordering and removing list items. + */ + class ListWidget : public QWidget + { + Q_OBJECT + + public: + explicit ListWidget(QWidget *parent = 0); + ~ListWidget(); + + QString getFieldType() const; + + void setFieldType(const QString& fieldType); + + private: + QString fieldType; + + QHBoxLayout* layout; + QListView* listView; + }; +} +#endif // LISTWIDGET_H diff --git a/Source/Tome/mainwindow.cpp b/Source/Tome/mainwindow.cpp index febd2975..abd193b6 100644 --- a/Source/Tome/mainwindow.cpp +++ b/Source/Tome/mainwindow.cpp @@ -359,7 +359,6 @@ void MainWindow::on_tableView_doubleClicked(const QModelIndex &index) // Update view. this->fieldValueWindow->setFieldDisplayName(fieldDefinition->displayName); - this->fieldValueWindow->setFieldType(fieldDefinition->fieldType); this->fieldValueWindow->setFieldDescription(fieldDefinition->description); if (fieldDefinition->fieldType == BuiltInType::Reference) @@ -369,6 +368,7 @@ void MainWindow::on_tableView_doubleClicked(const QModelIndex &index) // Allow clearing the field. recordNames << QString(); + this->fieldValueWindow->setFieldType(fieldDefinition->fieldType); this->fieldValueWindow->setEnumeration(recordNames); } else @@ -377,7 +377,12 @@ void MainWindow::on_tableView_doubleClicked(const QModelIndex &index) if (type != 0) { - this->fieldValueWindow->setEnumeration(type->getEnumeration()); + this->fieldValueWindow->setCustomFieldType(type); + } + else + { + // Default built-in type. + this->fieldValueWindow->setFieldType(fieldDefinition->fieldType); } } From 4721c82e294e0afd95dc32d5f676596eaa1031f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 27 Jan 2016 21:27:15 +0100 Subject: [PATCH 09/72] ADDED: Custom Types - Missing changes to project file. --- Project/Tome.pro | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Project/Tome.pro b/Project/Tome.pro index 5b74856a..368cb7f8 100644 --- a/Project/Tome.pro +++ b/Project/Tome.pro @@ -61,7 +61,8 @@ SOURCES += ../Source/Tome/main.cpp \ ../Source/Tome/Types/enumerationwindow.cpp \ ../Source/Tome/Types/enumerationmemberwindow.cpp \ ../Source/Tome/Types/listwindow.cpp \ - ../Source/Tome/Types/customtypestablemodel.cpp + ../Source/Tome/Types/customtypestablemodel.cpp \ + ../Source/Tome/Fields/listwidget.cpp HEADERS += ../Source/Tome/mainwindow.h \ ../Source/Tome/Types/builtintype.h \ @@ -97,7 +98,8 @@ HEADERS += ../Source/Tome/mainwindow.h \ ../Source/Tome/Types/enumerationmemberwindow.h \ ../Source/Tome/Types/enumerationwindow.h \ ../Source/Tome/Types/listwindow.h \ - ../Source/Tome/Types/customtypestablemodel.h + ../Source/Tome/Types/customtypestablemodel.h \ + ../Source/Tome/Fields/listwidget.h FORMS += ../Source/Tome/mainwindow.ui \ ../Source/Tome/Help/aboutwindow.ui \ From 460328b33d0247ac6cb972354d5b6999b633b3d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 27 Jan 2016 22:15:59 +0100 Subject: [PATCH 10/72] ADDED: Custom Types - Adding list items. --- Doc/Example/Tome Example Project.tfields | 2 +- Doc/Example/Tome Example Project.tproj | 9 +++- Project/Tome.pro | 11 ++-- Source/Tome/Fields/fieldvaluewidget.cpp | 1 + Source/Tome/Fields/listitemmodel.cpp | 25 +++++++++ Source/Tome/Fields/listitemmodel.h | 22 ++++++++ Source/Tome/Fields/listitemwindow.cpp | 50 ++++++++++++++++++ Source/Tome/Fields/listitemwindow.h | 39 +++++++++++++++ Source/Tome/Fields/listitemwindow.ui | 64 ++++++++++++++++++++++++ Source/Tome/Fields/listwidget.cpp | 55 +++++++++++++++++++- Source/Tome/Fields/listwidget.h | 12 +++++ 11 files changed, 283 insertions(+), 7 deletions(-) create mode 100644 Source/Tome/Fields/listitemmodel.cpp create mode 100644 Source/Tome/Fields/listitemmodel.h create mode 100644 Source/Tome/Fields/listitemwindow.cpp create mode 100644 Source/Tome/Fields/listitemwindow.h create mode 100644 Source/Tome/Fields/listitemwindow.ui diff --git a/Doc/Example/Tome Example Project.tfields b/Doc/Example/Tome Example Project.tfields index 9f80af8e..85b84a6b 100644 --- a/Doc/Example/Tome Example Project.tfields +++ b/Doc/Example/Tome Example Project.tfields @@ -1,7 +1,7 @@ - + diff --git a/Doc/Example/Tome Example Project.tproj b/Doc/Example/Tome Example Project.tproj index b2f8e0ff..255ed843 100644 --- a/Doc/Example/Tome Example Project.tproj +++ b/Doc/Example/Tome Example Project.tproj @@ -34,14 +34,14 @@ Slash XML .blueprints.xml + + - - - + - + - + - + - + + + + + + From 0add593c40bdd68b1551d79a6908cd35b0c60a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 09:44:01 +0100 Subject: [PATCH 49/72] ADDED: Projects - Adding new projects to Recent Projects list. --- Source/Tome/Core/controller.cpp | 7 ++++--- Source/Tome/Core/mainwindow.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Source/Tome/Core/controller.cpp b/Source/Tome/Core/controller.cpp index 53f58e28..15c85680 100644 --- a/Source/Tome/Core/controller.cpp +++ b/Source/Tome/Core/controller.cpp @@ -252,9 +252,6 @@ void Controller::openProject(const QString& projectFileName) } } - // Add to recent projects. - this->settingsController->addRecentProject(projectFileName); - // Set project reference. this->setProject(project); } @@ -371,6 +368,10 @@ void Controller::setProject(QSharedPointer project) this->fieldDefinitionsController->setFieldDefinitionSets(project->fieldDefinitionSets); this->recordsController->setRecordSets(project->recordSets); this->typesController->setCustomTypes(project->types); + + // Add to recent projects. + const QString& fullPath = this->getFullProjectPath(); + this->settingsController->addRecentProject(fullPath); } const QString Controller::getFullProjectPath() const diff --git a/Source/Tome/Core/mainwindow.cpp b/Source/Tome/Core/mainwindow.cpp index 4d5db008..b1a16f40 100644 --- a/Source/Tome/Core/mainwindow.cpp +++ b/Source/Tome/Core/mainwindow.cpp @@ -165,7 +165,7 @@ void MainWindow::on_actionOpen_Project_triggered() QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tome Project Files (*.tproj)"); - this->controller->openProject(projectFileName); + this->openProject(projectFileName); } void MainWindow::on_actionSave_Project_triggered() @@ -542,7 +542,6 @@ void MainWindow::openProject(QString path) try { this->controller->openProject(path); - this->updateRecentProjects(); this->onProjectChanged(); } catch (std::runtime_error& e) @@ -621,6 +620,9 @@ void MainWindow::onProjectChanged() // Update title. this->updateWindowTitle(); + + // Update recent projects. + this->updateRecentProjects(); } void MainWindow::showWindow(QWidget* widget) From 364971ecb97f00e25b75c57aea33affb125767cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 09:45:28 +0100 Subject: [PATCH 50/72] CHANGED: Projects - Keeping list of recent projects in order of last access time. --- .../Features/Settings/Controller/settingscontroller.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/Tome/Features/Settings/Controller/settingscontroller.cpp b/Source/Tome/Features/Settings/Controller/settingscontroller.cpp index 284a4123..afef7295 100644 --- a/Source/Tome/Features/Settings/Controller/settingscontroller.cpp +++ b/Source/Tome/Features/Settings/Controller/settingscontroller.cpp @@ -27,11 +27,7 @@ void SettingsController::addRecentProject(const QString& path) { QStringList recentProjects = this->getRecentProjects(); - if (recentProjects.contains(path)) - { - return; - } - + recentProjects.removeOne(path); recentProjects.push_front(path); this->setRecentProjects(recentProjects); From 4febedec2b06e22c526c894cfa2fb6b7427c06b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 09:47:19 +0100 Subject: [PATCH 51/72] CHANGED: Fields - Moved "empty" record reference from bottom of combo box to top. --- Source/Tome/Features/Fields/View/fieldvaluewidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Tome/Features/Fields/View/fieldvaluewidget.cpp b/Source/Tome/Features/Fields/View/fieldvaluewidget.cpp index 61e3f668..11779737 100644 --- a/Source/Tome/Features/Fields/View/fieldvaluewidget.cpp +++ b/Source/Tome/Features/Fields/View/fieldvaluewidget.cpp @@ -160,7 +160,7 @@ void FieldValueWidget::setFieldType(const QString& fieldType) QStringList recordNames = this->recordsController.getRecordNames(); // Allow clearing the field. - recordNames << QString(); + recordNames.push_front(QString()); this->setEnumeration(recordNames); this->setCurrentWidget(this->comboBox); From ad4b22e24b95c550932202593a949c8110bb0d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 09:57:41 +0100 Subject: [PATCH 52/72] CHANGED: Project - Properly resetting records and fields views when opening another project. --- Source/Tome/Core/mainwindow.cpp | 34 +++++++++++++++++++++++++-------- Source/Tome/Core/mainwindow.h | 2 ++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Source/Tome/Core/mainwindow.cpp b/Source/Tome/Core/mainwindow.cpp index b1a16f40..0c9a87e0 100644 --- a/Source/Tome/Core/mainwindow.cpp +++ b/Source/Tome/Core/mainwindow.cpp @@ -63,12 +63,7 @@ MainWindow::MainWindow(QWidget *parent) : this->updateRecentProjects(); // Setup view. - this->ui->tableWidget->setColumnCount(2); - - QStringList headers; - headers << tr("Field"); - headers << tr("Value"); - this->ui->tableWidget->setHorizontalHeaderLabels(headers); + this->resetFields(); } MainWindow::~MainWindow() @@ -471,7 +466,7 @@ void MainWindow::treeViewSelectionChanged(const QItemSelection& selected, const if (selected.empty()) { - this->ui->tableWidget->clear(); + this->resetFields(); return; } @@ -518,6 +513,16 @@ void MainWindow::addRecordField(const QString& fieldId) this->updateRecordRow(index); } +void MainWindow::resetRecords() +{ + this->ui->treeWidget->setColumnCount(1); + + while (this->ui->treeWidget->topLevelItemCount() > 0) + { + this->ui->treeWidget->takeTopLevelItem(0); + } +} + QString MainWindow::getSelectedRecordDisplayName() const { QModelIndexList selectedIndexes = this->ui->treeWidget->selectionModel()->selectedIndexes(); @@ -577,7 +582,7 @@ void MainWindow::onProjectChanged() this->updateMenus(); // Setup tree view. - this->ui->treeWidget->setColumnCount(1); + this->resetRecords(); QList items; @@ -625,6 +630,19 @@ void MainWindow::onProjectChanged() this->updateRecentProjects(); } +void MainWindow::resetFields() +{ + this->ui->tableWidget->clear(); + + this->ui->tableWidget->setRowCount(0); + this->ui->tableWidget->setColumnCount(2); + + QStringList headers; + headers << tr("Field"); + headers << tr("Value"); + this->ui->tableWidget->setHorizontalHeaderLabels(headers); +} + void MainWindow::showWindow(QWidget* widget) { widget->show(); diff --git a/Source/Tome/Core/mainwindow.h b/Source/Tome/Core/mainwindow.h index 68c94629..03dc9c9f 100644 --- a/Source/Tome/Core/mainwindow.h +++ b/Source/Tome/Core/mainwindow.h @@ -71,6 +71,8 @@ class MainWindow : public QMainWindow void openProject(QString path); void removeRecordField(const QString& fieldId); void onProjectChanged(); + void resetFields(); + void resetRecords(); void showWindow(QWidget* widget); void updateMenus(); void updateRecentProjects(); From b68e10fc23b84cc5a0064a9656898fea1dcb2dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 21:16:06 +0100 Subject: [PATCH 53/72] FIXED: Records - Correctly showing current record fields after adding or editing a record. --- Source/Tome/Core/mainwindow.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/Tome/Core/mainwindow.cpp b/Source/Tome/Core/mainwindow.cpp index 0c9a87e0..e567b1d6 100644 --- a/Source/Tome/Core/mainwindow.cpp +++ b/Source/Tome/Core/mainwindow.cpp @@ -237,6 +237,12 @@ void MainWindow::on_actionNew_Record_triggered() this->addRecordField(fieldId); } } + + // Update view. + for (int i = 0; i < record.fieldValues.size(); ++i) + { + this->updateRecordRow(i); + } } } @@ -315,6 +321,12 @@ void MainWindow::on_actionEdit_Record_triggered() this->removeRecordField(fieldId); } } + + // Update view. + for (int i = 0; i < record.fieldValues.size(); ++i) + { + this->updateRecordRow(i); + } } } @@ -510,7 +522,6 @@ void MainWindow::addRecordField(const QString& fieldId) // Update view. this->ui->tableWidget->insertRow(index); - this->updateRecordRow(index); } void MainWindow::resetRecords() From 964e106a741cef747def75a748bea1ee073b5cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 21:29:03 +0100 Subject: [PATCH 54/72] CHANGED: Fields - Preventing whitespaces in field ids. --- .../Controller/fielddefinitionscontroller.cpp | 6 +++--- .../Fields/View/fielddefinitionwindow.cpp | 15 ++++++++++++++- Source/Tome/Util/stringutils.h | 10 ++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Source/Tome/Features/Fields/Controller/fielddefinitionscontroller.cpp b/Source/Tome/Features/Fields/Controller/fielddefinitionscontroller.cpp index bf782ed5..ceed1f89 100644 --- a/Source/Tome/Features/Fields/Controller/fielddefinitionscontroller.cpp +++ b/Source/Tome/Features/Fields/Controller/fielddefinitionscontroller.cpp @@ -3,7 +3,7 @@ #include #include "../../../Util/listutils.h" - +#include "../../../Util/stringutils.h" using namespace Tome; @@ -15,7 +15,7 @@ FieldDefinitionsController::FieldDefinitionsController() const FieldDefinition FieldDefinitionsController::addFieldDefinition(const QString& id, const QString& displayName, const QString& fieldType, const QVariant& defaultValue, const QString& component, const QString& description) { FieldDefinition fieldDefinition = FieldDefinition(); - fieldDefinition.id = id; + fieldDefinition.id = stripWhitespaces(id); fieldDefinition.displayName = displayName; fieldDefinition.fieldType = fieldType; fieldDefinition.defaultValue = defaultValue; @@ -61,7 +61,7 @@ void FieldDefinitionsController::updateFieldDefinition(const QString& oldId, con bool needsSorting = fieldDefinition.displayName != displayName; // Update model. - fieldDefinition.id = newId; + fieldDefinition.id = stripWhitespaces(newId); fieldDefinition.displayName = displayName; fieldDefinition.fieldType = fieldType; fieldDefinition.defaultValue = defaultValue; diff --git a/Source/Tome/Features/Fields/View/fielddefinitionwindow.cpp b/Source/Tome/Features/Fields/View/fielddefinitionwindow.cpp index 3d298aab..eac2516b 100644 --- a/Source/Tome/Features/Fields/View/fielddefinitionwindow.cpp +++ b/Source/Tome/Features/Fields/View/fielddefinitionwindow.cpp @@ -4,6 +4,7 @@ #include #include "../../Types/Model/builtintype.h" +#include "../../../Util/stringutils.h" using namespace Tome; @@ -130,7 +131,7 @@ void FieldDefinitionWindow::on_comboBoxType_currentIndexChanged(const QString &f void FieldDefinitionWindow::on_lineEditDisplayName_textEdited(const QString &displayName) { - this->setFieldId(displayName); + this->setFieldId(stripWhitespaces(displayName)); } bool FieldDefinitionWindow::validate() @@ -147,6 +148,18 @@ bool FieldDefinitionWindow::validate() return false; } + // Id must not contain any whitespaces. + if (containsWhitespaces(this->getFieldId())) + { + QMessageBox::information( + this, + tr("Incorrect id"), + tr("Please specify an id without whitespaces."), + QMessageBox::Close, + QMessageBox::Close); + return false; + } + // Display name must not be empty. if (this->getFieldDisplayName().isEmpty()) { diff --git a/Source/Tome/Util/stringutils.h b/Source/Tome/Util/stringutils.h index bafa767d..33bc3095 100644 --- a/Source/Tome/Util/stringutils.h +++ b/Source/Tome/Util/stringutils.h @@ -5,10 +5,20 @@ namespace Tome { + inline bool containsWhitespaces(const QString& s) + { + return s.simplified().contains(" "); + } + inline bool qStringLessThanLowerCase(const QString& e1, const QString& e2) { return e1.toLower() < e2.toLower(); } + + inline QString stripWhitespaces(const QString& s) + { + return s.simplified().replace(" ", ""); + } } #endif // STRINGUTILS From 3f94140b4cb7d94120862a9326658cc5c35871d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 21:37:38 +0100 Subject: [PATCH 55/72] ADDED: Fields - Enforcing unique ids. --- .../Controller/fielddefinitionscontroller.cpp | 28 +++++++++ .../Controller/fielddefinitionscontroller.h | 1 + .../Fields/View/fielddefinitionswindow.cpp | 62 ++++++++++++------- 3 files changed, 69 insertions(+), 22 deletions(-) diff --git a/Source/Tome/Features/Fields/Controller/fielddefinitionscontroller.cpp b/Source/Tome/Features/Fields/Controller/fielddefinitionscontroller.cpp index ceed1f89..7d4ec48d 100644 --- a/Source/Tome/Features/Fields/Controller/fielddefinitionscontroller.cpp +++ b/Source/Tome/Features/Fields/Controller/fielddefinitionscontroller.cpp @@ -14,6 +14,14 @@ FieldDefinitionsController::FieldDefinitionsController() const FieldDefinition FieldDefinitionsController::addFieldDefinition(const QString& id, const QString& displayName, const QString& fieldType, const QVariant& defaultValue, const QString& component, const QString& description) { + // Check if already exists. + if (this->hasFieldDefinition(id)) + { + const QString errorMessage = "Field with the specified id already exists: " + id; + throw std::out_of_range(errorMessage.toStdString()); + } + + // Add new field. FieldDefinition fieldDefinition = FieldDefinition(); fieldDefinition.id = stripWhitespaces(id); fieldDefinition.displayName = displayName; @@ -39,6 +47,26 @@ const FieldDefinitionSetList& FieldDefinitionsController::getFieldDefinitionSets return *this->model; } +bool FieldDefinitionsController::hasFieldDefinition(const QString& id) const +{ + for (int i = 0; i < this->model->size(); ++i) + { + FieldDefinitionSet& fieldDefinitionSet = (*this->model)[i]; + + for (int j = 0; j < fieldDefinitionSet.fieldDefinitions.size(); ++j) + { + FieldDefinition& fieldDefinition = fieldDefinitionSet.fieldDefinitions[j]; + + if (fieldDefinition.id == id) + { + return true; + } + } + } + + return false; +} + int FieldDefinitionsController::indexOf(const FieldDefinition& fieldDefinition) const { return this->model->at(0).fieldDefinitions.indexOf(fieldDefinition); diff --git a/Source/Tome/Features/Fields/Controller/fielddefinitionscontroller.h b/Source/Tome/Features/Fields/Controller/fielddefinitionscontroller.h index ca125dd0..d2f5bc70 100644 --- a/Source/Tome/Features/Fields/Controller/fielddefinitionscontroller.h +++ b/Source/Tome/Features/Fields/Controller/fielddefinitionscontroller.h @@ -14,6 +14,7 @@ namespace Tome const FieldDefinition addFieldDefinition(const QString& id, const QString& displayName, const QString& fieldType, const QVariant& defaultValue, const QString& component, const QString& description); const FieldDefinition& getFieldDefinition(const QString& id) const; const FieldDefinitionSetList& getFieldDefinitionSets() const; + bool hasFieldDefinition(const QString& id) const; int indexOf(const FieldDefinition& fieldDefinition) const; void removeFieldDefinitionAt(const int index); void setFieldDefinitionSets(FieldDefinitionSetList& model); diff --git a/Source/Tome/Features/Fields/View/fielddefinitionswindow.cpp b/Source/Tome/Features/Fields/View/fielddefinitionswindow.cpp index 74f265df..a04ac1df 100644 --- a/Source/Tome/Features/Fields/View/fielddefinitionswindow.cpp +++ b/Source/Tome/Features/Fields/View/fielddefinitionswindow.cpp @@ -1,6 +1,10 @@ #include "fielddefinitionswindow.h" #include "ui_fielddefinitionswindow.h" +#include + +#include + #include "../../Types/Model/builtintype.h" #include "../../../Util/listutils.h" @@ -79,28 +83,42 @@ void FieldDefinitionsWindow::on_actionNew_Field_triggered() if (result == QDialog::Accepted) { - // Update model. - FieldDefinition fieldDefinition = - this->fieldDefinitionsController.addFieldDefinition( - this->fieldDefinitionWindow->getFieldId(), - this->fieldDefinitionWindow->getFieldDisplayName(), - this->fieldDefinitionWindow->getFieldType(), - this->fieldDefinitionWindow->getDefaultValue(), - this->fieldDefinitionWindow->getFieldComponent(), - this->fieldDefinitionWindow->getFieldDescription()); - - // Update view. - int index = this->fieldDefinitionsController.indexOf(fieldDefinition); - - this->ui->tableWidget->insertRow(index); - this->updateFieldDefinition( - fieldDefinition.id, - fieldDefinition.id, - fieldDefinition.displayName, - fieldDefinition.fieldType, - fieldDefinition.defaultValue, - fieldDefinition.description, - fieldDefinition.component); + try + { + // Update model. + FieldDefinition fieldDefinition = + this->fieldDefinitionsController.addFieldDefinition( + this->fieldDefinitionWindow->getFieldId(), + this->fieldDefinitionWindow->getFieldDisplayName(), + this->fieldDefinitionWindow->getFieldType(), + this->fieldDefinitionWindow->getDefaultValue(), + this->fieldDefinitionWindow->getFieldComponent(), + this->fieldDefinitionWindow->getFieldDescription()); + + // Update view. + int index = this->fieldDefinitionsController.indexOf(fieldDefinition); + + this->ui->tableWidget->insertRow(index); + this->updateFieldDefinition( + fieldDefinition.id, + fieldDefinition.id, + fieldDefinition.displayName, + fieldDefinition.fieldType, + fieldDefinition.defaultValue, + fieldDefinition.description, + fieldDefinition.component); + } + catch (std::out_of_range& e) + { + QMessageBox::critical( + this, + tr("Unable to add field"), + e.what(), + QMessageBox::Close, + QMessageBox::Close); + + this->on_actionNew_Field_triggered(); + } } } From 9a1cf5f0ec256ac70ec8e19013f1b0bc9ac0810d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 22:03:11 +0100 Subject: [PATCH 56/72] CHANGED: Records - Showing record display names in tree view, but accessing model through id. --- Project/Tome.pro | 6 +- Source/Tome/Core/mainwindow.cpp | 68 +++++++------------ Source/Tome/Core/mainwindow.h | 3 +- .../Records/Controller/recordscontroller.cpp | 6 +- .../Records/Controller/recordscontroller.h | 8 +-- .../Records/View/recordtreewidgetitem.cpp | 32 +++++++++ .../Records/View/recordtreewidgetitem.h | 25 +++++++ 7 files changed, 96 insertions(+), 52 deletions(-) create mode 100644 Source/Tome/Features/Records/View/recordtreewidgetitem.cpp create mode 100644 Source/Tome/Features/Records/View/recordtreewidgetitem.h diff --git a/Project/Tome.pro b/Project/Tome.pro index bf4428e9..754fa4ce 100644 --- a/Project/Tome.pro +++ b/Project/Tome.pro @@ -62,7 +62,8 @@ SOURCES += ../Source/Tome/main.cpp \ ../Source/Tome/Features/Records/Controller/recordscontroller.cpp \ ../Source/Tome/Features/Fields/Controller/fielddefinitionscontroller.cpp \ ../Source/Tome/Features/Types/Controller/typescontroller.cpp \ - ../Source/Tome/Features/Settings/Controller/settingscontroller.cpp + ../Source/Tome/Features/Settings/Controller/settingscontroller.cpp \ + ../Source/Tome/Features/Records/View/recordtreewidgetitem.cpp HEADERS += ../Source/Tome/Core/mainwindow.h \ ../Source/Tome/Features/Types/Model/builtintype.h \ @@ -110,7 +111,8 @@ HEADERS += ../Source/Tome/Core/mainwindow.h \ ../Source/Tome/Util/listutils.h \ ../Source/Tome/Features/Export/Model/recordexporttemplatemap.h \ ../Source/Tome/Util/memoryutils.h \ - ../Source/Tome/Util/stringutils.h + ../Source/Tome/Util/stringutils.h \ + ../Source/Tome/Features/Records/View/recordtreewidgetitem.h FORMS += ../Source/Tome/Core/mainwindow.ui \ ../Source/Tome/Features/Help/View/aboutwindow.ui \ diff --git a/Source/Tome/Core/mainwindow.cpp b/Source/Tome/Core/mainwindow.cpp index e567b1d6..e5c656e7 100644 --- a/Source/Tome/Core/mainwindow.cpp +++ b/Source/Tome/Core/mainwindow.cpp @@ -248,16 +248,16 @@ void MainWindow::on_actionNew_Record_triggered() void MainWindow::on_actionEdit_Record_triggered() { - const QString& displayName = getSelectedRecordDisplayName(); + const QString& id = getSelectedRecordId(); - if (displayName.isEmpty()) + if (id.isEmpty()) { return; } // Get selected record. const Record& record = - this->controller->getRecordsController().getRecordByDisplayName(displayName); + this->controller->getRecordsController().getRecord(id); // Show window. if (!this->recordWindow) @@ -388,9 +388,9 @@ void MainWindow::on_treeWidget_doubleClicked(const QModelIndex &index) void MainWindow::on_tableWidget_doubleClicked(const QModelIndex &index) { - QString recordDisplayName = this->getSelectedRecordDisplayName(); + QString id = this->getSelectedRecordId(); const Record& record = - this->controller->getRecordsController().getRecordByDisplayName(recordDisplayName); + this->controller->getRecordsController().getRecord(id); // Get current field data. const QString fieldId = record.fieldValues.keys()[index.row()]; @@ -474,31 +474,19 @@ void MainWindow::openRecentProject(QAction* recentProjectAction) void MainWindow::treeViewSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected) { + Q_UNUSED(selected); Q_UNUSED(deselected); - if (selected.empty()) - { - this->resetFields(); - return; - } - - QModelIndex selectedIndex = selected.first().indexes().first(); - - if (!selectedIndex.isValid()) - { - return; - } - - const QString& displayName = selectedIndex.data(Qt::DisplayRole).toString(); + const QString& id = this->getSelectedRecordId(); - if (displayName.isEmpty()) + if (id.isEmpty()) { return; } // Get selected record. const Record& record = - this->controller->getRecordsController().getRecordByDisplayName(displayName); + this->controller->getRecordsController().getRecord(id); // Update field table. this->ui->tableWidget->setRowCount(record.fieldValues.size()); @@ -511,9 +499,9 @@ void MainWindow::treeViewSelectionChanged(const QItemSelection& selected, const void MainWindow::addRecordField(const QString& fieldId) { - QString recordDisplayName = this->getSelectedRecordDisplayName(); + QString id = this->getSelectedRecordId(); const Record& record = - this->controller->getRecordsController().getRecordByDisplayName(recordDisplayName); + this->controller->getRecordsController().getRecord(id); int index = findInsertionIndex(record.fieldValues.keys(), fieldId, qStringLessThanLowerCase); @@ -534,23 +522,17 @@ void MainWindow::resetRecords() } } -QString MainWindow::getSelectedRecordDisplayName() const +QString MainWindow::getSelectedRecordId() const { - QModelIndexList selectedIndexes = this->ui->treeWidget->selectionModel()->selectedIndexes(); + QList selectedItems = this->ui->treeWidget->selectedItems(); - if (selectedIndexes.empty()) - { - return QString(); - } - - QModelIndex currentIndex = selectedIndexes.first(); - - if (!currentIndex.isValid()) + if (selectedItems.empty()) { return QString(); } - return currentIndex.data(Qt::DisplayRole).toString(); + RecordTreeWidgetItem* recordTreeItem = static_cast(selectedItems.first()); + return recordTreeItem->getId(); } void MainWindow::openProject(QString path) @@ -575,9 +557,9 @@ void MainWindow::openProject(QString path) void MainWindow::removeRecordField(const QString& fieldId) { - QString recordDisplayName = this->getSelectedRecordDisplayName(); + QString id = this->getSelectedRecordId(); const Record& record = - this->controller->getRecordsController().getRecordByDisplayName(recordDisplayName); + this->controller->getRecordsController().getRecord(id); // Update model. this->controller->getRecordsController().removeRecordField(record.id, fieldId); @@ -606,7 +588,7 @@ void MainWindow::onProjectChanged() for (int j = 0; j < recordSet.records.size(); ++j) { const Record& record = recordSet.records[j]; - items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(record.displayName))); + items.append(new RecordTreeWidgetItem(record.id, record.displayName)); } } @@ -693,9 +675,9 @@ void MainWindow::updateRecentProjects() void MainWindow::updateRecord(const QString& id, const QString& displayName) { - QString recordDisplayName = this->getSelectedRecordDisplayName(); + QString selectedRecordId = this->getSelectedRecordId(); const Record& record = - this->controller->getRecordsController().getRecordByDisplayName(recordDisplayName); + this->controller->getRecordsController().getRecord(selectedRecordId); bool needsSorting = record.displayName != displayName; @@ -718,7 +700,9 @@ void MainWindow::updateRecord(const QString& id, const QString& displayName) } QTreeWidgetItem* item = this->ui->treeWidget->topLevelItem(currentIndex.row()); - item->setText(0, displayName); + RecordTreeWidgetItem* recordItem = static_cast(item); + recordItem->setId(id); + recordItem->setDisplayName(displayName); // Sort by display name. if (needsSorting) @@ -730,9 +714,9 @@ void MainWindow::updateRecord(const QString& id, const QString& displayName) void MainWindow::updateRecordRow(int i) { // Get selected record. - QString selectedRecordDisplayName = this->getSelectedRecordDisplayName(); + QString id = this->getSelectedRecordId(); const Record& record = - this->controller->getRecordsController().getRecordByDisplayName(selectedRecordDisplayName); + this->controller->getRecordsController().getRecord(id); // Get selected record field key and value. QString key = record.fieldValues.keys()[i]; diff --git a/Source/Tome/Core/mainwindow.h b/Source/Tome/Core/mainwindow.h index 03dc9c9f..0bba5400 100644 --- a/Source/Tome/Core/mainwindow.h +++ b/Source/Tome/Core/mainwindow.h @@ -10,6 +10,7 @@ #include "../Features/Help/View/aboutwindow.h" #include "../Features/Projects/View/newprojectwindow.h" #include "../Features/Projects/Model/project.h" +#include "../Features/Records/View/recordtreewidgetitem.h" #include "../Features/Records/View/recordwindow.h" #include "../Features/Types/View/customtypeswindow.h" @@ -67,7 +68,7 @@ class MainWindow : public QMainWindow RecordWindow* recordWindow; void addRecordField(const QString& fieldId); - QString getSelectedRecordDisplayName() const; + QString getSelectedRecordId() const; void openProject(QString path); void removeRecordField(const QString& fieldId); void onProjectChanged(); diff --git a/Source/Tome/Features/Records/Controller/recordscontroller.cpp b/Source/Tome/Features/Records/Controller/recordscontroller.cpp index e54bbd55..2d1d4e75 100644 --- a/Source/Tome/Features/Records/Controller/recordscontroller.cpp +++ b/Source/Tome/Features/Records/Controller/recordscontroller.cpp @@ -39,7 +39,7 @@ const RecordSetList& RecordsController::getRecordSets() const return *this->model; } -const Record&RecordsController::getRecordByDisplayName(const QString& displayName) const +const Record& RecordsController::getRecord(const QString& id) const { for (int i = 0; i < this->model->size(); ++i) { @@ -49,14 +49,14 @@ const Record&RecordsController::getRecordByDisplayName(const QString& displayNam { const Record& record = recordSet.records[j]; - if (record.displayName == displayName) + if (record.id == id) { return record; } } } - const QString errorMessage = "Record not found: " + displayName; + const QString errorMessage = "Record not found: " + id; throw std::out_of_range(errorMessage.toStdString()); } diff --git a/Source/Tome/Features/Records/Controller/recordscontroller.h b/Source/Tome/Features/Records/Controller/recordscontroller.h index ae8c6e2a..b8c87e98 100644 --- a/Source/Tome/Features/Records/Controller/recordscontroller.h +++ b/Source/Tome/Features/Records/Controller/recordscontroller.h @@ -18,11 +18,11 @@ namespace Tome const RecordSetList& getRecordSets() const; /** - * @brief getRecordByDisplayName Returns the record with the specified display name. - * @param displayName Display name of the record to get. - * @return Record with the specified display name. + * @brief getRecord Returns the record with the specified id. + * @param id Id of the record to get. + * @return Record with the specified id. */ - const Record& getRecordByDisplayName(const QString& displayName) const; + const Record& getRecord(const QString& id) const; /** * @brief getRecordNames Returns the list of the names of all records of this project. diff --git a/Source/Tome/Features/Records/View/recordtreewidgetitem.cpp b/Source/Tome/Features/Records/View/recordtreewidgetitem.cpp new file mode 100644 index 00000000..d0414145 --- /dev/null +++ b/Source/Tome/Features/Records/View/recordtreewidgetitem.cpp @@ -0,0 +1,32 @@ +#include "recordtreewidgetitem.h" + +using namespace Tome; + + +RecordTreeWidgetItem::RecordTreeWidgetItem(const QString& id, const QString& displayName) + : QTreeWidgetItem((QTreeWidget*)0, QStringList(displayName)), + id(id), + displayName(displayName) +{ +} + +QString RecordTreeWidgetItem::getId() const +{ + return this->id; +} + +QString RecordTreeWidgetItem::getDisplayName() const +{ + return this->displayName; +} + +void RecordTreeWidgetItem::setId(const QString& id) +{ + this->id = id; +} + +void RecordTreeWidgetItem::setDisplayName(const QString& displayName) +{ + this->displayName = displayName; + this->setText(0, displayName); +} diff --git a/Source/Tome/Features/Records/View/recordtreewidgetitem.h b/Source/Tome/Features/Records/View/recordtreewidgetitem.h new file mode 100644 index 00000000..cf89417f --- /dev/null +++ b/Source/Tome/Features/Records/View/recordtreewidgetitem.h @@ -0,0 +1,25 @@ +#ifndef RECORDTREEWIDGETITEM_H +#define RECORDTREEWIDGETITEM_H + +#include + +namespace Tome +{ + class RecordTreeWidgetItem : public QTreeWidgetItem + { + public: + RecordTreeWidgetItem(const QString& id, const QString& displayName); + + QString getId() const; + QString getDisplayName() const; + + void setId(const QString& id); + void setDisplayName(const QString& displayName); + + private: + QString id; + QString displayName; + }; +} + +#endif // RECORDTREEWIDGETITEM_H From 1160227ee25ca93ec06df70513f43040c5e9a813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 22:05:34 +0100 Subject: [PATCH 57/72] CHANGED: Records - Showing field display names in table view, but accessing model through id. --- Source/Tome/Core/mainwindow.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Tome/Core/mainwindow.cpp b/Source/Tome/Core/mainwindow.cpp index e5c656e7..77ee3d1c 100644 --- a/Source/Tome/Core/mainwindow.cpp +++ b/Source/Tome/Core/mainwindow.cpp @@ -722,12 +722,13 @@ void MainWindow::updateRecordRow(int i) QString key = record.fieldValues.keys()[i]; QVariant value = record.fieldValues[key]; - QString valueString = value.toString(); - // Get selected record field type. const FieldDefinition& field = this->controller->getFieldDefinitionsController().getFieldDefinition(key); + QString keyString = field.displayName; + QString valueString = value.toString(); + if (this->controller->getTypesController().isCustomType(field.fieldType)) { const CustomType& customType = this->controller->getTypesController().getCustomType(field.fieldType); @@ -739,7 +740,7 @@ void MainWindow::updateRecordRow(int i) } // Show field and value. - this->ui->tableWidget->setItem(i, 0, new QTableWidgetItem(key)); + this->ui->tableWidget->setItem(i, 0, new QTableWidgetItem(keyString)); this->ui->tableWidget->setItem(i, 1, new QTableWidgetItem(valueString)); // Show field description as tooltip. From 5aba8d5e2fd24203acd7c341f2e500c73a0646f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 22:06:38 +0100 Subject: [PATCH 58/72] CHANGED: Documentation - Added whitespace to sprite color field display name. --- Doc/Example/Tome Example Project.tfields | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Example/Tome Example Project.tfields b/Doc/Example/Tome Example Project.tfields index 5826a8e4..bcd63b6f 100644 --- a/Doc/Example/Tome Example Project.tfields +++ b/Doc/Example/Tome Example Project.tfields @@ -21,5 +21,5 @@ - + From 175bd35cae60e627e5ff12af5ebfe3088b04da1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 22:13:15 +0100 Subject: [PATCH 59/72] ADDED #57 Project Version Number --- Doc/Example/Tome Example Project.tproj | 2 +- .../Tome/Features/Projects/Controller/projectserializer.cpp | 6 ++++++ .../Tome/Features/Projects/Controller/projectserializer.h | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Doc/Example/Tome Example Project.tproj b/Doc/Example/Tome Example Project.tproj index 072a6b59..aba1117e 100644 --- a/Doc/Example/Tome Example Project.tproj +++ b/Doc/Example/Tome Example Project.tproj @@ -1,5 +1,5 @@ - + Tome Example Project ArmorComponent diff --git a/Source/Tome/Features/Projects/Controller/projectserializer.cpp b/Source/Tome/Features/Projects/Controller/projectserializer.cpp index f15c8f5f..4bffd21c 100644 --- a/Source/Tome/Features/Projects/Controller/projectserializer.cpp +++ b/Source/Tome/Features/Projects/Controller/projectserializer.cpp @@ -12,6 +12,7 @@ const QString ProjectSerializer::AttributeExportedType = "ExportedType"; const QString ProjectSerializer::AttributeKey = "Key"; const QString ProjectSerializer::AttributeTomeType = "TomeType"; const QString ProjectSerializer::AttributeValue = "Value"; +const QString ProjectSerializer::AttributeVersion = "Version"; const QString ProjectSerializer::ElementComponents = "Components"; const QString ProjectSerializer::ElementFieldDefinitions = "FieldDefinitions"; const QString ProjectSerializer::ElementFileExtension = "FileExtension"; @@ -28,6 +29,8 @@ const QString ProjectSerializer::ElementType = "Type"; const QString ProjectSerializer::ElementTypes = "Types"; const QString ProjectSerializer::ElementTypeMap = "TypeMap"; +const int ProjectSerializer::Version = 1; + ProjectSerializer::ProjectSerializer() { @@ -45,6 +48,9 @@ void ProjectSerializer::serialize(QIODevice& device, QSharedPointer pro // Begin project. writer.writeStartElement(ElementTomeProject); { + // Write version. + writer.writeAttribute(AttributeVersion, QString::number(Version)); + // Write project name. writer.writeTextElement(ElementName, project->name); diff --git a/Source/Tome/Features/Projects/Controller/projectserializer.h b/Source/Tome/Features/Projects/Controller/projectserializer.h index 67ae559a..0ef2d437 100644 --- a/Source/Tome/Features/Projects/Controller/projectserializer.h +++ b/Source/Tome/Features/Projects/Controller/projectserializer.h @@ -33,6 +33,7 @@ namespace Tome static const QString AttributeKey; static const QString AttributeTomeType; static const QString AttributeValue; + static const QString AttributeVersion; static const QString ElementComponents; static const QString ElementFieldDefinitions; static const QString ElementFileExtension; @@ -48,6 +49,8 @@ namespace Tome static const QString ElementType; static const QString ElementTypes; static const QString ElementTypeMap; + + static const int Version; }; } From 1ecf1fc4dda7ece9b79822c770364968eb851a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 23:04:43 +0100 Subject: [PATCH 60/72] ADDED: Lists - Editing list items. --- .../Tome/Features/Fields/View/listwidget.cpp | 35 +++++++++++++++++++ Source/Tome/Features/Fields/View/listwidget.h | 1 + 2 files changed, 36 insertions(+) diff --git a/Source/Tome/Features/Fields/View/listwidget.cpp b/Source/Tome/Features/Fields/View/listwidget.cpp index ebaf96b3..fce87d8e 100644 --- a/Source/Tome/Features/Fields/View/listwidget.cpp +++ b/Source/Tome/Features/Fields/View/listwidget.cpp @@ -17,6 +17,11 @@ ListWidget::ListWidget(RecordsController& recordsController, TypesController& ty // Add list view. this->listWidget = new QListWidget(this); + connect( + this->listWidget, + SIGNAL(itemDoubleClicked(QListWidgetItem*)), + SLOT(editItem(QListWidgetItem*)) + ); this->layout->addWidget(this->listWidget); // Add buttons. @@ -126,6 +131,36 @@ void ListWidget::addItem() } } +void ListWidget::editItem(QListWidgetItem* item) +{ + // Prepare window. + if (!this->listItemWindow) + { + this->listItemWindow = new ListItemWindow(this->recordsController, this->typesController, this); + } + + QVariant currentValue = item->text(); + + // Update view. + this->listItemWindow->setFieldType(this->fieldType); + this->listItemWindow->setValue(currentValue); + + // Show window. + int result = this->listItemWindow->exec(); + + if (result == QDialog::Accepted) + { + QVariant value = this->listItemWindow->getValue(); + + // Update model. + int index = this->getSelectedItemIndex(); + this->items[index] = value; + + // Update view. + item->setText(value.toString()); + } +} + void ListWidget::removeItem() { int index = this->getSelectedItemIndex(); diff --git a/Source/Tome/Features/Fields/View/listwidget.h b/Source/Tome/Features/Fields/View/listwidget.h index 2636e863..5b984833 100644 --- a/Source/Tome/Features/Fields/View/listwidget.h +++ b/Source/Tome/Features/Fields/View/listwidget.h @@ -35,6 +35,7 @@ namespace Tome private slots: void addItem(); + void editItem(QListWidgetItem* item); void removeItem(); void moveItemUp(); void moveItemDown(); From 82728de64be7ee802b7e6426443221874ca2b23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 23:28:35 +0100 Subject: [PATCH 61/72] FIXED: Records - Crash that could occur adding a new record to the project. --- Source/Tome/Core/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Tome/Core/mainwindow.cpp b/Source/Tome/Core/mainwindow.cpp index 77ee3d1c..6949c5b3 100644 --- a/Source/Tome/Core/mainwindow.cpp +++ b/Source/Tome/Core/mainwindow.cpp @@ -216,7 +216,7 @@ void MainWindow::on_actionNew_Record_triggered() // Update view. int index = this->controller->getRecordsController().indexOf(record); - QTreeWidgetItem* newItem = new QTreeWidgetItem((QTreeWidget*)0, QStringList(recordDisplayName)); + QTreeWidgetItem* newItem = new RecordTreeWidgetItem(recordId, recordDisplayName); this->ui->treeWidget->insertTopLevelItem(index, newItem); // Select new record. From 9f021b3792c30895b1e902ef7335efb2f514dc1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 23:28:56 +0100 Subject: [PATCH 62/72] FIXED: Records - Correctly refreshing records table immediately after creating a new record. --- Source/Tome/Core/mainwindow.cpp | 24 +++++++++++------------- Source/Tome/Core/mainwindow.h | 1 + 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Source/Tome/Core/mainwindow.cpp b/Source/Tome/Core/mainwindow.cpp index 6949c5b3..621fb54e 100644 --- a/Source/Tome/Core/mainwindow.cpp +++ b/Source/Tome/Core/mainwindow.cpp @@ -239,10 +239,7 @@ void MainWindow::on_actionNew_Record_triggered() } // Update view. - for (int i = 0; i < record.fieldValues.size(); ++i) - { - this->updateRecordRow(i); - } + this->refreshRecordTable(); } } @@ -323,10 +320,7 @@ void MainWindow::on_actionEdit_Record_triggered() } // Update view. - for (int i = 0; i < record.fieldValues.size(); ++i) - { - this->updateRecordRow(i); - } + this->refreshRecordTable(); } } @@ -490,11 +484,7 @@ void MainWindow::treeViewSelectionChanged(const QItemSelection& selected, const // Update field table. this->ui->tableWidget->setRowCount(record.fieldValues.size()); - - for (int i = 0; i < record.fieldValues.size(); ++i) - { - this->updateRecordRow(i); - } + this->refreshRecordTable(); } void MainWindow::addRecordField(const QString& fieldId) @@ -623,6 +613,14 @@ void MainWindow::onProjectChanged() this->updateRecentProjects(); } +void MainWindow::refreshRecordTable() +{ + for (int i = 0; i < this->ui->tableWidget->rowCount(); ++i) + { + this->updateRecordRow(i); + } +} + void MainWindow::resetFields() { this->ui->tableWidget->clear(); diff --git a/Source/Tome/Core/mainwindow.h b/Source/Tome/Core/mainwindow.h index 0bba5400..3398211f 100644 --- a/Source/Tome/Core/mainwindow.h +++ b/Source/Tome/Core/mainwindow.h @@ -72,6 +72,7 @@ class MainWindow : public QMainWindow void openProject(QString path); void removeRecordField(const QString& fieldId); void onProjectChanged(); + void refreshRecordTable(); void resetFields(); void resetRecords(); void showWindow(QWidget* widget); From d9abc7fe6ba6b094371c437a75f063b93fd28407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Wed, 17 Feb 2016 23:37:18 +0100 Subject: [PATCH 63/72] FIXED: Project - Correctly resetting record tree and table after loading another project. --- Source/Tome/Core/mainwindow.cpp | 6 ++++ .../Records/Controller/recordscontroller.cpp | 32 +++++++++++-------- .../Records/Controller/recordscontroller.h | 1 + 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Source/Tome/Core/mainwindow.cpp b/Source/Tome/Core/mainwindow.cpp index 621fb54e..19c58549 100644 --- a/Source/Tome/Core/mainwindow.cpp +++ b/Source/Tome/Core/mainwindow.cpp @@ -478,6 +478,11 @@ void MainWindow::treeViewSelectionChanged(const QItemSelection& selected, const return; } + if (!this->controller->getRecordsController().hasRecord(id)) + { + return; + } + // Get selected record. const Record& record = this->controller->getRecordsController().getRecord(id); @@ -566,6 +571,7 @@ void MainWindow::onProjectChanged() // Setup tree view. this->resetRecords(); + this->resetFields(); QList items; diff --git a/Source/Tome/Features/Records/Controller/recordscontroller.cpp b/Source/Tome/Features/Records/Controller/recordscontroller.cpp index 2d1d4e75..8fdecd55 100644 --- a/Source/Tome/Features/Records/Controller/recordscontroller.cpp +++ b/Source/Tome/Features/Records/Controller/recordscontroller.cpp @@ -41,6 +41,13 @@ const RecordSetList& RecordsController::getRecordSets() const const Record& RecordsController::getRecord(const QString& id) const { + return *this->getRecordById(id); +} + +const QStringList RecordsController::getRecordNames() const +{ + QStringList names; + for (int i = 0; i < this->model->size(); ++i) { const RecordSet& recordSet = this->model->at(i); @@ -48,34 +55,31 @@ const Record& RecordsController::getRecord(const QString& id) const for (int j = 0; j < recordSet.records.size(); ++j) { const Record& record = recordSet.records[j]; - - if (record.id == id) - { - return record; - } + names << record.displayName; } } - const QString errorMessage = "Record not found: " + id; - throw std::out_of_range(errorMessage.toStdString()); + return names; } -const QStringList RecordsController::getRecordNames() const +bool RecordsController::hasRecord(const QString& id) const { - QStringList names; - for (int i = 0; i < this->model->size(); ++i) { - const RecordSet& recordSet = this->model->at(i); + RecordSet& recordSet = (*this->model)[i]; for (int j = 0; j < recordSet.records.size(); ++j) { - const Record& record = recordSet.records[j]; - names << record.displayName; + Record& record = recordSet.records[j]; + + if (record.id == id) + { + return true; + } } } - return names; + return false; } int RecordsController::indexOf(const Record& record) const diff --git a/Source/Tome/Features/Records/Controller/recordscontroller.h b/Source/Tome/Features/Records/Controller/recordscontroller.h index b8c87e98..aab29e0b 100644 --- a/Source/Tome/Features/Records/Controller/recordscontroller.h +++ b/Source/Tome/Features/Records/Controller/recordscontroller.h @@ -30,6 +30,7 @@ namespace Tome */ const QStringList getRecordNames() const; + bool hasRecord(const QString& id) const; int indexOf(const Record& record) const; void removeRecordAt(const int index); void removeRecordField(const QString& recordId, const QString& fieldId); From 93a630cd171e58ed69dfbe0ce15f08fdfd2c7387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Thu, 18 Feb 2016 20:54:19 +0100 Subject: [PATCH 64/72] CHANGED: Fields - Field definition and components list items no longer appear as if they could be edited inline after their respective edit window has closed. --- Source/Tome/Features/Components/View/componentswindow.ui | 6 +++++- Source/Tome/Features/Fields/View/fielddefinitionswindow.ui | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Tome/Features/Components/View/componentswindow.ui b/Source/Tome/Features/Components/View/componentswindow.ui index 24e75f21..f2ed96d3 100644 --- a/Source/Tome/Features/Components/View/componentswindow.ui +++ b/Source/Tome/Features/Components/View/componentswindow.ui @@ -16,7 +16,11 @@ - + + + QAbstractItemView::NoEditTriggers + + diff --git a/Source/Tome/Features/Fields/View/fielddefinitionswindow.ui b/Source/Tome/Features/Fields/View/fielddefinitionswindow.ui index 8bc39ec2..5feb2ca3 100644 --- a/Source/Tome/Features/Fields/View/fielddefinitionswindow.ui +++ b/Source/Tome/Features/Fields/View/fielddefinitionswindow.ui @@ -23,6 +23,9 @@ + + QAbstractItemView::NoEditTriggers + QAbstractItemView::SingleSelection From 81b8190c1b1b3184db691d99b4b1b7a01a51e5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Thu, 18 Feb 2016 20:56:21 +0100 Subject: [PATCH 65/72] ADDED: Records - Clearing record field value table if no record is selected. --- Source/Tome/Core/mainwindow.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Source/Tome/Core/mainwindow.cpp b/Source/Tome/Core/mainwindow.cpp index 19c58549..57c4df92 100644 --- a/Source/Tome/Core/mainwindow.cpp +++ b/Source/Tome/Core/mainwindow.cpp @@ -473,19 +473,15 @@ void MainWindow::treeViewSelectionChanged(const QItemSelection& selected, const const QString& id = this->getSelectedRecordId(); - if (id.isEmpty()) - { - return; - } - - if (!this->controller->getRecordsController().hasRecord(id)) + if (id.isEmpty() || !this->controller->getRecordsController().hasRecord(id)) { + // Clear table. + this->ui->tableWidget->setRowCount(0); return; } // Get selected record. - const Record& record = - this->controller->getRecordsController().getRecord(id); + const Record& record = this->controller->getRecordsController().getRecord(id); // Update field table. this->ui->tableWidget->setRowCount(record.fieldValues.size()); From 9ebaca912758b544b022877c3a5f81bbd38460f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Thu, 18 Feb 2016 21:00:03 +0100 Subject: [PATCH 66/72] FIXED: Fields - Setting reference name instead of line edit string if field type is Reference. --- Source/Tome/Features/Fields/View/fieldvaluewidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Tome/Features/Fields/View/fieldvaluewidget.cpp b/Source/Tome/Features/Fields/View/fieldvaluewidget.cpp index 11779737..4baf4f40 100644 --- a/Source/Tome/Features/Fields/View/fieldvaluewidget.cpp +++ b/Source/Tome/Features/Fields/View/fieldvaluewidget.cpp @@ -94,7 +94,7 @@ QVariant FieldValueWidget::getFieldValue() const if (this->fieldType == BuiltInType::Reference) { - return this->lineEdit->text(); + return this->comboBox->currentText(); } // Check custom data types. From 0511e3a626ad3d97acb20217f0e2f4c3f16189f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Thu, 18 Feb 2016 21:03:37 +0100 Subject: [PATCH 67/72] ADDED: Export - Filter in Save As window. --- Source/Tome/Core/mainwindow.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Tome/Core/mainwindow.cpp b/Source/Tome/Core/mainwindow.cpp index 57c4df92..6b572459 100644 --- a/Source/Tome/Core/mainwindow.cpp +++ b/Source/Tome/Core/mainwindow.cpp @@ -433,11 +433,13 @@ void MainWindow::exportRecords(QAction* exportAction) // Build export file name suggestion. const QString suggestedFileName = this->controller->getProjectName() + exportTemplate.fileExtension; const QString suggestedFilePath = combinePaths(this->controller->getProjectPath(), suggestedFileName); + const QString filter = exportTemplateName + " (*" + exportTemplate.fileExtension + ")"; // Show file dialog. QString filePath = QFileDialog::getSaveFileName(this, tr("Export Records"), - suggestedFilePath); + suggestedFilePath, + filter); if (filePath.isEmpty()) { From 2693cb5f26897d23f254c6e68c5198edc333ed1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Thu, 18 Feb 2016 21:26:57 +0100 Subject: [PATCH 68/72] FIXED: Lists - Correctly de-serializing one-element lists. --- Doc/Example/Tome Example Project.tdata | 24 +++++++---- .../Controller/recordsetserializer.cpp | 43 ++++++++++--------- .../Records/Controller/recordsetserializer.h | 1 + 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/Doc/Example/Tome Example Project.tdata b/Doc/Example/Tome Example Project.tdata index ae3c1bf8..99613dad 100644 --- a/Doc/Example/Tome Example Project.tdata +++ b/Doc/Example/Tome Example Project.tdata @@ -2,8 +2,10 @@ - - + + + + @@ -35,7 +37,9 @@ - + + + @@ -49,7 +53,7 @@ - + @@ -57,8 +61,10 @@ - - + + + + @@ -80,7 +86,9 @@ - + + + @@ -94,7 +102,7 @@ - + diff --git a/Source/Tome/Features/Records/Controller/recordsetserializer.cpp b/Source/Tome/Features/Records/Controller/recordsetserializer.cpp index f5d474c3..d0425f31 100644 --- a/Source/Tome/Features/Records/Controller/recordsetserializer.cpp +++ b/Source/Tome/Features/Records/Controller/recordsetserializer.cpp @@ -9,6 +9,7 @@ using namespace Tome; const QString RecordSetSerializer::ElementDisplayName = "DisplayName"; const QString RecordSetSerializer::ElementId = "Id"; +const QString RecordSetSerializer::ElementItem = "Item"; const QString RecordSetSerializer::ElementRecord = "Record"; const QString RecordSetSerializer::ElementRecords = "Records"; const QString RecordSetSerializer::ElementValue = "Value"; @@ -53,12 +54,16 @@ void RecordSetSerializer::serialize(QIODevice& device, const RecordSet& recordSe { QVariantList list = value.toList(); + stream.writeStartElement(it.key()); + for (int i = 0; i < list.size(); ++i) { - stream.writeStartElement(it.key()); + stream.writeStartElement(ElementItem); stream.writeAttribute(ElementValue, list[i].toString()); stream.writeEndElement(); } + + stream.writeEndElement(); } else { @@ -104,38 +109,36 @@ void RecordSetSerializer::deserialize(QIODevice& device, RecordSet& recordSet) c reader.readStartElement(ElementRecord); - QString lastKey; - QVariant lastValue; - while (!reader.isAtElement(ElementRecord)) { QString key = reader.getElementName(); QVariant value = reader.readAttribute(ElementValue); - if (key == lastKey) + if (value.toString().isEmpty()) { - // List value. - if (lastValue.canConvert()) - { - QVariantList list = lastValue.toList(); - list.append(value); - value = list; - } - else + reader.readStartElement(key); { + // Begin list. QVariantList list = QVariantList(); - list.append(lastValue); - list.append(value); + + while (reader.isAtElement(ElementItem)) + { + // Read list item. + QVariant item = reader.readAttribute(ElementValue); + list.append(item); + reader.readEmptyElement(ElementItem); + } + value = list; } + reader.readEndElement(); + } + else + { + reader.readEmptyElement(key); } record.fieldValues[key] = value; - - reader.readEmptyElement(key); - - lastKey = key; - lastValue = value; } recordSet.records.push_back(record); diff --git a/Source/Tome/Features/Records/Controller/recordsetserializer.h b/Source/Tome/Features/Records/Controller/recordsetserializer.h index 8e7c9917..61016aed 100644 --- a/Source/Tome/Features/Records/Controller/recordsetserializer.h +++ b/Source/Tome/Features/Records/Controller/recordsetserializer.h @@ -29,6 +29,7 @@ namespace Tome private: static const QString ElementDisplayName; static const QString ElementId; + static const QString ElementItem; static const QString ElementRecord; static const QString ElementRecords; static const QString ElementValue; From 5c74197a5f5064c5767126b4c8b46e44b54a6793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Thu, 18 Feb 2016 21:33:44 +0100 Subject: [PATCH 69/72] CHANGED: Project - Increased version number. --- Project/Tome.pro | 4 +++- Source/Tome/Features/Help/View/aboutwindow.cpp | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Project/Tome.pro b/Project/Tome.pro index 754fa4ce..0f2a5577 100644 --- a/Project/Tome.pro +++ b/Project/Tome.pro @@ -13,8 +13,10 @@ TEMPLATE = app # Expose application version in Windows property window and in application code. # http://www.openguru.com/2009/11/qt-best-way-to-set-application-version.html -VERSION = 0.2 +VERSION = 0.3 +VERSION_NAME = Basilisk DEFINES += APP_VERSION=\\\"$$VERSION\\\" +DEFINES += APP_VERSION_NAME=\\\"$$VERSION_NAME\\\" Debug:DESTDIR = ../Bin/debug Debug:OBJECTS_DIR = ../Obj/debug diff --git a/Source/Tome/Features/Help/View/aboutwindow.cpp b/Source/Tome/Features/Help/View/aboutwindow.cpp index 3fc52cb7..4a29f4df 100644 --- a/Source/Tome/Features/Help/View/aboutwindow.cpp +++ b/Source/Tome/Features/Help/View/aboutwindow.cpp @@ -8,7 +8,8 @@ AboutWindow::AboutWindow(QWidget *parent) : ui->setupUi(this); // Show version number. - this->ui->labelVersion->setText("Version " + QApplication::instance()->applicationVersion()); + const QString version = "Version " + QApplication::instance()->applicationVersion() + " (" + APP_VERSION_NAME + ")"; + this->ui->labelVersion->setText(version); } AboutWindow::~AboutWindow() From c6868c8f5ec658d191ab55783fc5fd1a014a5aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Thu, 18 Feb 2016 21:39:15 +0100 Subject: [PATCH 70/72] FIXED: Project - Canceling Open Project no longer causes the application to crash. --- Source/Tome/Core/mainwindow.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Tome/Core/mainwindow.cpp b/Source/Tome/Core/mainwindow.cpp index 6b572459..22a1289a 100644 --- a/Source/Tome/Core/mainwindow.cpp +++ b/Source/Tome/Core/mainwindow.cpp @@ -530,6 +530,11 @@ QString MainWindow::getSelectedRecordId() const void MainWindow::openProject(QString path) { + if (path.isEmpty()) + { + return; + } + try { this->controller->openProject(path); From e540ef953346e2e5a282ceea07b46c9483363fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Thu, 18 Feb 2016 21:50:00 +0100 Subject: [PATCH 71/72] ADDED: Documentation - List window screenshot. --- .../Images/{CustomType.png => Enumeration.png} | Bin Doc/Manual/Images/List.png | Bin 0 -> 4232 bytes 2 files changed, 0 insertions(+), 0 deletions(-) rename Doc/Manual/Images/{CustomType.png => Enumeration.png} (100%) create mode 100644 Doc/Manual/Images/List.png diff --git a/Doc/Manual/Images/CustomType.png b/Doc/Manual/Images/Enumeration.png similarity index 100% rename from Doc/Manual/Images/CustomType.png rename to Doc/Manual/Images/Enumeration.png diff --git a/Doc/Manual/Images/List.png b/Doc/Manual/Images/List.png new file mode 100644 index 0000000000000000000000000000000000000000..2b1dd878bc89cc08087c815126ae90d5a8dc8031 GIT binary patch literal 4232 zcmZ{o2Q-{rx5pn6l6WJCnjjbnqD_z@qC|{3%;*v|4T(+|y(Pkk7Di`uCfevjh?3|% zMrMd%L?_XEcgMTFyY9X3{l2rF^*qnoYn{FJKI`n?{+|=74O6A3yGjQD0KK{zL>B<4 zVkrNC=cy@gOG2S205HPUA&UAQsY_!PnkGNd=T^sQG*RfdHoez`;w&>x;w7ouggg#D zddL|VEqt$nPVo$bp;3+gyJocuFv*^xIQ<~>%Q1C?l)w}Ez;o@M=S6P3&ai3HlL}R0 z{lxan>bBc!Zmy|1LL~#CPnv=BdKXp4u(Qw5mKe78B68zMh@oMqeU2+;zHnTwVYHdX zF%<*=h-oIBz_oEHIeGwiGD}PD?A+u60OGka8X#QJjtY3eXaY2Gw6FoUXirU@&^2;n z+Q~yJut5p8wDy_}?9wAf0B2e-EUC|<;Uyn3Rl@~iRAW4=$cXHa^MV_dpS))`AC9?C z4Ya7Unw-@5H};s1X78lQdE>5ZPz7i))4kvH@)cqMWfc?@eEq7JtNR(v{7c%w#zq4( zcq4Vkt3Ee3_xS)SSUVS@dv;Y|9fUw(4ad>ERnECikXcDWOCcI#Hzp=50 zc>t=>YTbB}{yw$j%|^odI(w)vQjHg+_)B`(vEcwy*-jg<^sJhsaIjcmJA}1A`M%bv z4B_k-)$olLGBi2q?H3n5E*h@?G+gzu+BOh*c2XJ?Ifa~eG-$NwcN*w!dkCiyl&mwg z!s5~eM2#b*>hQ7k9C5^{kW6d@)Z8Q@yRZcbHXNR9(i&8B% zw6@vYy|X({n50FC5R{)^YCoD_h$0;~_*KzDPe;GdSPJ+y_f&=cz`D@GJGS>|12$zn zRx=6;g!wzG*1enK#>MjZ4D5QrbSHL2*<22<{rK*I6I@sz&~KBIQ1DHfK(+)n_IS28 zZ{D~_J8a2QRDz)JX%!o{!eIS^tm@$`H@U?lPSn?yQj%`mU$* z?5+_qJ(`S?N99<;qdfNjvG~vnVTgzrVZUqQQbq$C>UQ4^LZB|xytbX@qypS{mH^b$ zi4|AZoMjRXNlCp~d-c+|vWj$a`C( zJ^Cz(#@i9ds>l-JB1o$}33tpV!D6a(WKVx*TGH0K@BDMcA3hbif)63g4U>P~-og_t zNRKAN-pB<`i-}3mzvYFHUddpg1_oU*!VcH4na4OO?%y35&yA|AhPo!G<;3uC{_w?= zq_L4kSinV-_86ZnXHrjV&G%5EwiYb;!r9PIiyfTrAt&1UY`%(+uT2;4r?kZ1Aa<&s zytpjYKW1L@Q=zxO=IY44ZB@LlH7JnDV_Kxzoyf@a`gd~oL5S(|Y(93T&%r+1eOKvZ z*LD1hAAfr##>^~L0nsO$V)*cE391&z`WvrrZh@62 z3ZzYf>qxgcU7&u1kCM0x{T@hy>50o_N^{X|3p|XM6d-*kDolUKjSru&*{4{q22W!7 zsmcla4go@TE7uF%bY&T#!dbt-w1RrRDtfX>rJ}fATNB82asT$*P^*=O3*E}>Ogc|@ zXMF9z#kTWf;%yHoy{TS%B@w2w0L7A!DZ zEzLBjJ|2Brgd-o|3YMxhA&~b==vLz8T-|*AYg_D?B8qhomn2~MEz2j5u-QA}TQzA( zY=~CNpe(8H5zFV;@Tw=a`6lMjzxRXj{jk~O+S&E_IKF`(Wsz-DDE}09a$NK4?U)}B z?}|N{hKQiWHcHdpw;GF*l8ewnOnjrkr2`X^Z{|K&x8@!^ge(7L){bUc<&yT@-%Mt} z?z!w975O^R51#Hb>$B4=4|S2n=udfYq)G4}4xavBrT~KL5C#Hn3D_2jB}J*91!iAb z+jV+!-2raV{f8<~Ts#z5BiDN;rBMSpQ{OX{{>2Ci`ZVEG0MVM#xM5PJ*Qx)h9RB9S z^s+{AxPy1%G4_Y^0}%%jf3i}fN}Pt}76k55By5n)Us;unl~1x%3PYI)=;@t#iY(&f z9UZ*etW#S%!2OMmG&X?%(QP}ZIF>JjtDLZ^s*M*2(A~%Gy45aSaku|XeBdL(^qwn1 zZ~>1tbjuSwTk57SOz1+%_G1PJUf|2`>Q#$TDB|TZZH-|Enbx)+H)U=^Na4n@!Q`^X zf+>|HRYYyL`$`D1V{ph!-vWFJ4a2BYXvh-(hQ{lSSexg*I=hw^X zA(Gi=6?IkxhA0EVJVz9L?QbXG0l6zk16=XysLWv4k6>tMm2xR$Y$*z5cMt9J;&&`J zB004=8v@C0hUr-!j4R7r2s?VLa_>uto8q6ctYvw4hjZ(=rMytu#$%DXuvFRpjTdHq zD1y>&;)^z_Y7V+Bj2+Z_EHvi(tnak+)_OwmIn^(`B)sepy+p_+Eb66waVY-=FD1>V{K;V#HFEB8EOd?5AX=Sr%!e3( zE8jN0XylHlSq-T8f5uRN(FkE(tWSi2pF0qu6OGlO`9Xn1xZ^UOzUS&DBr`SwyXlD> zJ@%?d7J}sbxf%wJcoZp8=xgW)y@I;Kq2&-2*z!X|W+G?;7%uzTlXcrMAaPS6&j6PK zgHlMUsW%wDGrPI3oZnI3p{;>P*=%35cpiufts{0kk;q3oD_#-7Y7;Z=CS!hO zHKDc@hI8d6UelcFN<@BSFRz9 z3ToApZ3>fxoTc^6S7m=*snd-zj%5$axiu0_;$I%CYu{$(l{F-=7PF|-$Wf

gnm( z%GX$77B%E#7H_)+S1;TZXQO1(rq+25xPXAz8IYRG42r)Ysvo?2^OI@wuDrt)>{cK8 zVjs=Z_OC0aI6y$Es#ssj3orqRD0JD4Ip-fhlhA(x#p$Udaq$ZkbsA4s`k}<2-mvh5 z{~iLr(LWKD3Y5|Gq{!zT6D_PsC)0Achk2ONHYwKL80L#lVQ19>1lb*ZgTq+dVXLw$I-|S~fNjpY&f}9}e|3DSu zO8RDF73%$#jr9{VywGF?QcwbVeFo;ZQ=};Sf~#ioyiUgehX~%z>l77<9=8nrccu~N zhBiFXuRYus$R}^3D`vY(qEu`p^5!em^SE7Z8zQ{<=^sII!WP9$GYHZ8xn>{OUT5A{ zpuhNu7S!H$AMY@e!<;!n{W#NUr5jbP5IVjgyF2f0S;E4oLy4_%>|nKH=?piIwGCoH zkDbMHh0GwPaE0QRT+G7^#fYPOu&!n=d}76%4>rYuhp8Vg9H`p661n#9ALad4yfO1? z_LZ=k9wcYPY*aiI^ZQX9IVW9@r$}&NJz6civ8LHR zBn%R8osN7wqvW;J6ozSO<{35LeR4;q=otUy&i+PISP56&`0=8>R`6`%CAU9l37aDQ z{G1orD5F35Y6khg1wiP58jY%4hx#9^M~MTSq_*cFr!`bLBNf&DudZ9|rWw$ieb~v< zSX$1)CAm~aqpMIOAmSfq-1pA5fy*kNGGU3;>|641-`FJ$?IM D02d^S literal 0 HcmV?d00001 From 8cef77da77eeb247cb364c44cc9a407cf827ed5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20Pr=C3=BChs?= Date: Thu, 18 Feb 2016 22:15:39 +0100 Subject: [PATCH 72/72] CHANGED: Project - Specifying output paths relative to Obj folder. --- Project/Tome.pro | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Project/Tome.pro b/Project/Tome.pro index 0f2a5577..0eedc478 100644 --- a/Project/Tome.pro +++ b/Project/Tome.pro @@ -18,17 +18,17 @@ VERSION_NAME = Basilisk DEFINES += APP_VERSION=\\\"$$VERSION\\\" DEFINES += APP_VERSION_NAME=\\\"$$VERSION_NAME\\\" -Debug:DESTDIR = ../Bin/debug -Debug:OBJECTS_DIR = ../Obj/debug -Debug:MOC_DIR = ../Obj/debug/.moc -Debug:RCC_DIR = ../Obj/debug/.rcc -Debug:UI_DIR = ../Obj/debug/.ui +Debug:DESTDIR = ../../Bin/debug +Debug:OBJECTS_DIR = ../../Obj/debug +Debug:MOC_DIR = ../../Obj/debug/.moc +Debug:RCC_DIR = ../../Obj/debug/.rcc +Debug:UI_DIR = ../../Obj/debug/.ui -Release:DESTDIR = ../Bin/release -Release:OBJECTS_DIR = ../Obj/release -Release:MOC_DIR = ../Obj/release/.moc -Release:RCC_DIR = ../Obj/release/.rcc -Release:UI_DIR = ../Obj/release/.ui +Release:DESTDIR = ../../Bin/release +Release:OBJECTS_DIR = ../../Obj/release +Release:MOC_DIR = ../../Obj/release/.moc +Release:RCC_DIR = ../../Obj/release/.rcc +Release:UI_DIR = ../../Obj/release/.ui SOURCES += ../Source/Tome/main.cpp \ ../Source/Tome/Core/mainwindow.cpp \