diff --git a/apps/opencs/view/world/pathgridcreator.cpp b/apps/opencs/view/world/pathgridcreator.cpp index a305b1249..166acafd2 100644 --- a/apps/opencs/view/world/pathgridcreator.cpp +++ b/apps/opencs/view/world/pathgridcreator.cpp @@ -1,28 +1,74 @@ #include "pathgridcreator.hpp" +#include +#include +#include +#include + #include "../../model/world/data.hpp" +std::string CSVWorld::PathgridCreator::getId() const +{ + return mCell->currentText().toUtf8().constData(); +} + CSVWorld::PathgridCreator::PathgridCreator( CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id, bool relaxedIdRules ) : GenericCreator(data, undoStack, id, relaxedIdRules) -{} +{ + setManualEditing(false); + + QLabel *label = new QLabel("Cell ID", this); + insertBeforeButtons(label, false); + + // Create combo box with case-insensitive sorting. + mCell = new QComboBox(this); + QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel; + QStringListModel *listModel = new QStringListModel; + proxyModel->setSourceModel(listModel); + proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); + mCell->setModel(proxyModel); + insertBeforeButtons(mCell, true); + + // Populate combo box with cells that don't have a pathgrid yet. + const CSMWorld::IdCollection& pathgrids = getData().getPathgrids(); + const CSMWorld::IdCollection& cells = getData().getCells(); + const int cellCount = cells.getSize(); + for (int i = 0; i < cellCount; ++i) + { + std::string cellId = cells.getId(i); + if (pathgrids.searchId(cellId) == -1) + { + mCell->addItem(QString::fromStdString(cellId)); + } + } + + mCell->model()->sort(0); + mCell->setCurrentIndex(0); +} std::string CSVWorld::PathgridCreator::getErrors() const { - std::string pathgridId = getId(); + std::string cellId = getId(); // Check user input for any errors. + // The last two checks, cell with existing pathgrid and non-existent cell, + // shouldn't be needed but we absolutely want to make sure they never happen. std::string errors; - if (pathgridId.empty()) + if (cellId.empty()) { - errors = "No Pathgrid ID entered"; + errors = "No cell ID selected"; } - else if (getData().getPathgrids().searchId(pathgridId) > -1) + else if (getData().getPathgrids().searchId(cellId) > -1) { - errors = "Pathgrid with this ID already exists"; + errors = "Pathgrid for selected cell ID already exists"; + } + else if (getData().getCells().searchId(cellId) == -1) + { + errors = "Cell with selected cell ID does not exist"; } return errors; diff --git a/apps/opencs/view/world/pathgridcreator.hpp b/apps/opencs/view/world/pathgridcreator.hpp index 10f64a0a7..5508fadd7 100644 --- a/apps/opencs/view/world/pathgridcreator.hpp +++ b/apps/opencs/view/world/pathgridcreator.hpp @@ -1,6 +1,8 @@ #ifndef PATHGRIDCREATOR_HPP #define PATHGRIDCREATOR_HPP +class QComboBox; + #include "genericcreator.hpp" namespace CSVWorld @@ -10,6 +12,13 @@ namespace CSVWorld { Q_OBJECT + QComboBox *mCell; + + private: + + /// \return Cell ID selected by user. + virtual std::string getId() const; + public: PathgridCreator(