From 207695e094524db0f740b5c527eacb1708e79412 Mon Sep 17 00:00:00 2001 From: Rob Cutmore Date: Tue, 21 Mar 2017 07:58:01 -0400 Subject: [PATCH] Editor: switch input for pathgrid creator Switched from QComboBox to DropLineEdit for pathgrid creator input. This allows the input the use auto-complete and be a drop target from the cells table. --- apps/opencs/view/world/pathgridcreator.cpp | 76 ++++++++++++---------- apps/opencs/view/world/pathgridcreator.hpp | 48 ++++++++++++-- apps/opencs/view/world/subviews.cpp | 4 +- 3 files changed, 86 insertions(+), 42 deletions(-) diff --git a/apps/opencs/view/world/pathgridcreator.cpp b/apps/opencs/view/world/pathgridcreator.cpp index 980c031ca..d597254c6 100644 --- a/apps/opencs/view/world/pathgridcreator.cpp +++ b/apps/opencs/view/world/pathgridcreator.cpp @@ -1,21 +1,33 @@ #include "pathgridcreator.hpp" -#include #include -#include -#include +#include "../../model/doc/document.hpp" + +#include "../../model/world/columns.hpp" #include "../../model/world/data.hpp" +#include "../../model/world/idcompletionmanager.hpp" +#include "../../model/world/idtable.hpp" + +#include "../widget/droplineedit.hpp" std::string CSVWorld::PathgridCreator::getId() const { - return mCell->currentText().toUtf8().constData(); + return mCell->text().toUtf8().constData(); +} + +CSMWorld::IdTable& CSVWorld::PathgridCreator::getPathgridsTable() const +{ + return dynamic_cast ( + *getData().getTableModel(getCollectionId()) + ); } CSVWorld::PathgridCreator::PathgridCreator( CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id, + CSMWorld::IdCompletionManager& completionManager, bool relaxedIdRules ) : GenericCreator(data, undoStack, id, relaxedIdRules) { @@ -24,19 +36,26 @@ CSVWorld::PathgridCreator::PathgridCreator( 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); + // Add cell ID input with auto-completion. + CSMWorld::ColumnBase::Display displayType = CSMWorld::ColumnBase::Display_Cell; + mCell = new CSVWidget::DropLineEdit(displayType, this); + mCell->setCompleter(completionManager.getCompleter(displayType).get()); insertBeforeButtons(mCell, true); - setupCellsInput(); + connect(mCell, SIGNAL (textChanged(const QString&)), this, SLOT (cellChanged())); + connect(mCell, SIGNAL (returnPressed()), this, SLOT (inputReturnPressed())); +} + +void CSVWorld::PathgridCreator::cloneMode( + const std::string& originId, + const CSMWorld::UniversalId::Type type) +{ + CSVWorld::GenericCreator::cloneMode(originId, type); - connect(&getData(), SIGNAL (idListChanged()), this, SLOT (setupCellsInput())); - connect(mCell, SIGNAL (currentIndexChanged(const QString&)), this, SLOT (cellChanged())); + // Look up cloned record in pathgrids table and set cell ID text. + CSMWorld::IdTable& table = getPathgridsTable(); + int column = table.findColumnIndex(CSMWorld::Columns::ColumnId_Id); + mCell->setText(table.data(table.getModelIndex(originId, column)).toString()); } std::string CSVWorld::PathgridCreator::getErrors() const @@ -71,7 +90,7 @@ void CSVWorld::PathgridCreator::focus() void CSVWorld::PathgridCreator::reset() { CSVWorld::GenericCreator::reset(); - mCell->setCurrentIndex(0); + mCell->setText(""); } void CSVWorld::PathgridCreator::cellChanged() @@ -79,23 +98,14 @@ void CSVWorld::PathgridCreator::cellChanged() update(); } -void CSVWorld::PathgridCreator::setupCellsInput() +CSVWorld::Creator *CSVWorld::PathgridCreatorFactory::makeCreator( + CSMDoc::Document& document, + const CSMWorld::UniversalId& id) const { - mCell->clear(); - - // 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); + return new PathgridCreator( + document.getData(), + document.getUndoStack(), + id, + document.getIdCompletionManager() + ); } diff --git a/apps/opencs/view/world/pathgridcreator.hpp b/apps/opencs/view/world/pathgridcreator.hpp index 7c4f7f705..c2ae20fc0 100644 --- a/apps/opencs/view/world/pathgridcreator.hpp +++ b/apps/opencs/view/world/pathgridcreator.hpp @@ -1,10 +1,26 @@ #ifndef PATHGRIDCREATOR_HPP #define PATHGRIDCREATOR_HPP -class QComboBox; - #include "genericcreator.hpp" +namespace CSMDoc +{ + class Document; +} + +namespace CSMWorld +{ + class Data; + class IdCompletionManager; + class IdTable; + class UniversalId; +} + +namespace CSVWidget +{ + class DropLineEdit; +} + namespace CSVWorld { /// \brief Record creator for pathgrids. @@ -12,37 +28,55 @@ namespace CSVWorld { Q_OBJECT - QComboBox *mCell; + CSVWidget::DropLineEdit *mCell; private: - /// \return Cell ID selected by user. + /// \return Cell ID entered by user. virtual std::string getId() const; + /// \return reference to table containing pathgrids. + CSMWorld::IdTable& getPathgridsTable() const; + public: PathgridCreator( CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id, + CSMWorld::IdCompletionManager& completionManager, bool relaxedIdRules = false); + /// \brief Set cell ID input widget to ID of record to be cloned. + /// \param originId Cell ID to be cloned. + /// \param type Type of record to be cloned. + virtual void cloneMode( + const std::string& originId, + const CSMWorld::UniversalId::Type type); + /// \return Error description for current user input. virtual std::string getErrors() const; /// \brief Set focus to cell ID input widget. virtual void focus(); - /// \brief Reset selected cell ID. + /// \brief Clear cell ID input widget. virtual void reset(); private slots: /// \brief Check user input for errors. void cellChanged(); + }; + + /// \brief Creator factory for pathgrid record creator. + class PathgridCreatorFactory : public CreatorFactoryBase + { + public: - /// \brief Setup cells in combo box. - void setupCellsInput(); + virtual Creator *makeCreator( + CSMDoc::Document& document, + const CSMWorld::UniversalId& id) const; }; } diff --git a/apps/opencs/view/world/subviews.cpp b/apps/opencs/view/world/subviews.cpp index 32661ed93..93e105106 100644 --- a/apps/opencs/view/world/subviews.cpp +++ b/apps/opencs/view/world/subviews.cpp @@ -76,7 +76,7 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) new CSVDoc::SubViewFactoryWithCreator); manager.add (CSMWorld::UniversalId::Type_Pathgrids, - new CSVDoc::SubViewFactoryWithCreator >); + new CSVDoc::SubViewFactoryWithCreator); manager.add (CSMWorld::UniversalId::Type_Globals, new CSVDoc::SubViewFactoryWithCreator >); @@ -174,7 +174,7 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) new CSVDoc::SubViewFactoryWithCreator (false)); manager.add (CSMWorld::UniversalId::Type_Pathgrid, - new CSVDoc::SubViewFactoryWithCreator > (false)); + new CSVDoc::SubViewFactoryWithCreator (false)); manager.add (CSMWorld::UniversalId::Type_DebugProfile, new CSVDoc::SubViewFactoryWithCreator > (false));