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.
pull/188/head
Rob Cutmore 8 years ago
parent 0dcb6a9bd4
commit 207695e094

@ -1,21 +1,33 @@
#include "pathgridcreator.hpp" #include "pathgridcreator.hpp"
#include <QComboBox>
#include <QLabel> #include <QLabel>
#include <QSortFilterProxyModel>
#include <QStringListModel>
#include "../../model/doc/document.hpp"
#include "../../model/world/columns.hpp"
#include "../../model/world/data.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 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<CSMWorld::IdTable&> (
*getData().getTableModel(getCollectionId())
);
} }
CSVWorld::PathgridCreator::PathgridCreator( CSVWorld::PathgridCreator::PathgridCreator(
CSMWorld::Data& data, CSMWorld::Data& data,
QUndoStack& undoStack, QUndoStack& undoStack,
const CSMWorld::UniversalId& id, const CSMWorld::UniversalId& id,
CSMWorld::IdCompletionManager& completionManager,
bool relaxedIdRules bool relaxedIdRules
) : GenericCreator(data, undoStack, id, relaxedIdRules) ) : GenericCreator(data, undoStack, id, relaxedIdRules)
{ {
@ -24,19 +36,26 @@ CSVWorld::PathgridCreator::PathgridCreator(
QLabel *label = new QLabel("Cell ID", this); QLabel *label = new QLabel("Cell ID", this);
insertBeforeButtons(label, false); insertBeforeButtons(label, false);
// Create combo box with case-insensitive sorting. // Add cell ID input with auto-completion.
mCell = new QComboBox(this); CSMWorld::ColumnBase::Display displayType = CSMWorld::ColumnBase::Display_Cell;
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel; mCell = new CSVWidget::DropLineEdit(displayType, this);
QStringListModel *listModel = new QStringListModel; mCell->setCompleter(completionManager.getCompleter(displayType).get());
proxyModel->setSourceModel(listModel);
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
mCell->setModel(proxyModel);
insertBeforeButtons(mCell, true); 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())); // Look up cloned record in pathgrids table and set cell ID text.
connect(mCell, SIGNAL (currentIndexChanged(const QString&)), this, SLOT (cellChanged())); 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 std::string CSVWorld::PathgridCreator::getErrors() const
@ -71,7 +90,7 @@ void CSVWorld::PathgridCreator::focus()
void CSVWorld::PathgridCreator::reset() void CSVWorld::PathgridCreator::reset()
{ {
CSVWorld::GenericCreator::reset(); CSVWorld::GenericCreator::reset();
mCell->setCurrentIndex(0); mCell->setText("");
} }
void CSVWorld::PathgridCreator::cellChanged() void CSVWorld::PathgridCreator::cellChanged()
@ -79,23 +98,14 @@ void CSVWorld::PathgridCreator::cellChanged()
update(); update();
} }
void CSVWorld::PathgridCreator::setupCellsInput() CSVWorld::Creator *CSVWorld::PathgridCreatorFactory::makeCreator(
CSMDoc::Document& document,
const CSMWorld::UniversalId& id) const
{ {
mCell->clear(); return new PathgridCreator(
document.getData(),
// Populate combo box with cells that don't have a pathgrid yet. document.getUndoStack(),
const CSMWorld::IdCollection<CSMWorld::Pathgrid>& pathgrids = getData().getPathgrids(); id,
const CSMWorld::IdCollection<CSMWorld::Cell>& cells = getData().getCells(); document.getIdCompletionManager()
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);
} }

@ -1,10 +1,26 @@
#ifndef PATHGRIDCREATOR_HPP #ifndef PATHGRIDCREATOR_HPP
#define PATHGRIDCREATOR_HPP #define PATHGRIDCREATOR_HPP
class QComboBox;
#include "genericcreator.hpp" #include "genericcreator.hpp"
namespace CSMDoc
{
class Document;
}
namespace CSMWorld
{
class Data;
class IdCompletionManager;
class IdTable;
class UniversalId;
}
namespace CSVWidget
{
class DropLineEdit;
}
namespace CSVWorld namespace CSVWorld
{ {
/// \brief Record creator for pathgrids. /// \brief Record creator for pathgrids.
@ -12,37 +28,55 @@ namespace CSVWorld
{ {
Q_OBJECT Q_OBJECT
QComboBox *mCell; CSVWidget::DropLineEdit *mCell;
private: private:
/// \return Cell ID selected by user. /// \return Cell ID entered by user.
virtual std::string getId() const; virtual std::string getId() const;
/// \return reference to table containing pathgrids.
CSMWorld::IdTable& getPathgridsTable() const;
public: public:
PathgridCreator( PathgridCreator(
CSMWorld::Data& data, CSMWorld::Data& data,
QUndoStack& undoStack, QUndoStack& undoStack,
const CSMWorld::UniversalId& id, const CSMWorld::UniversalId& id,
CSMWorld::IdCompletionManager& completionManager,
bool relaxedIdRules = false); 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. /// \return Error description for current user input.
virtual std::string getErrors() const; virtual std::string getErrors() const;
/// \brief Set focus to cell ID input widget. /// \brief Set focus to cell ID input widget.
virtual void focus(); virtual void focus();
/// \brief Reset selected cell ID. /// \brief Clear cell ID input widget.
virtual void reset(); virtual void reset();
private slots: private slots:
/// \brief Check user input for errors. /// \brief Check user input for errors.
void cellChanged(); void cellChanged();
};
/// \brief Creator factory for pathgrid record creator.
class PathgridCreatorFactory : public CreatorFactoryBase
{
public:
/// \brief Setup cells in combo box. virtual Creator *makeCreator(
void setupCellsInput(); CSMDoc::Document& document,
const CSMWorld::UniversalId& id) const;
}; };
} }

@ -76,7 +76,7 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
new CSVDoc::SubViewFactoryWithCreator<TableSubView, InfoCreatorFactory>); new CSVDoc::SubViewFactoryWithCreator<TableSubView, InfoCreatorFactory>);
manager.add (CSMWorld::UniversalId::Type_Pathgrids, manager.add (CSMWorld::UniversalId::Type_Pathgrids,
new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<PathgridCreator> >); new CSVDoc::SubViewFactoryWithCreator<TableSubView, PathgridCreatorFactory>);
manager.add (CSMWorld::UniversalId::Type_Globals, manager.add (CSMWorld::UniversalId::Type_Globals,
new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<GlobalCreator> >); new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<GlobalCreator> >);
@ -174,7 +174,7 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
new CSVDoc::SubViewFactoryWithCreator<DialogueSubView, JournalCreatorFactory> (false)); new CSVDoc::SubViewFactoryWithCreator<DialogueSubView, JournalCreatorFactory> (false));
manager.add (CSMWorld::UniversalId::Type_Pathgrid, manager.add (CSMWorld::UniversalId::Type_Pathgrid,
new CSVDoc::SubViewFactoryWithCreator<DialogueSubView, CreatorFactory<PathgridCreator> > (false)); new CSVDoc::SubViewFactoryWithCreator<DialogueSubView, PathgridCreatorFactory> (false));
manager.add (CSMWorld::UniversalId::Type_DebugProfile, manager.add (CSMWorld::UniversalId::Type_DebugProfile,
new CSVDoc::SubViewFactoryWithCreator<DialogueSubView, CreatorFactory<GenericCreator, CSMWorld::Scope_Project | CSMWorld::Scope_Session> > (false)); new CSVDoc::SubViewFactoryWithCreator<DialogueSubView, CreatorFactory<GenericCreator, CSMWorld::Scope_Project | CSMWorld::Scope_Session> > (false));

Loading…
Cancel
Save