mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 18:35:20 +00:00
Merge remote-tracking branch 'rcutmore/bug-3345'
This commit is contained in:
commit
021cef74ff
@ -1,21 +1,34 @@
|
||||
#include "pathgridcreator.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStringListModel>
|
||||
|
||||
#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"
|
||||
#include "idvalidator.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<CSMWorld::IdTable&> (
|
||||
*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 +37,27 @@ 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());
|
||||
mCell->setValidator(new IdValidator(relaxedIdRules, this));
|
||||
insertBeforeButtons(mCell, true);
|
||||
|
||||
setupCellsInput();
|
||||
connect(mCell, SIGNAL (textChanged(const QString&)), this, SLOT (cellChanged()));
|
||||
connect(mCell, SIGNAL (returnPressed()), this, SLOT (inputReturnPressed()));
|
||||
}
|
||||
|
||||
connect(&getData(), SIGNAL (idListChanged()), this, SLOT (setupCellsInput()));
|
||||
connect(mCell, SIGNAL (currentIndexChanged(const QString&)), this, SLOT (cellChanged()));
|
||||
void CSVWorld::PathgridCreator::cloneMode(
|
||||
const std::string& originId,
|
||||
const CSMWorld::UniversalId::Type type)
|
||||
{
|
||||
CSVWorld::GenericCreator::cloneMode(originId, type);
|
||||
|
||||
// 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 +92,7 @@ void CSVWorld::PathgridCreator::focus()
|
||||
void CSVWorld::PathgridCreator::reset()
|
||||
{
|
||||
CSVWorld::GenericCreator::reset();
|
||||
mCell->setCurrentIndex(0);
|
||||
mCell->setText("");
|
||||
}
|
||||
|
||||
void CSVWorld::PathgridCreator::cellChanged()
|
||||
@ -79,23 +100,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<CSMWorld::Pathgrid>& pathgrids = getData().getPathgrids();
|
||||
const CSMWorld::IdCollection<CSMWorld::Cell>& 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()
|
||||
);
|
||||
}
|
||||
|
@ -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 Setup cells in combo box.
|
||||
void setupCellsInput();
|
||||
/// \brief Creator factory for pathgrid record creator.
|
||||
class PathgridCreatorFactory : public CreatorFactoryBase
|
||||
{
|
||||
public:
|
||||
|
||||
virtual Creator *makeCreator(
|
||||
CSMDoc::Document& document,
|
||||
const CSMWorld::UniversalId& id) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
||||
new CSVDoc::SubViewFactoryWithCreator<TableSubView, InfoCreatorFactory>);
|
||||
|
||||
manager.add (CSMWorld::UniversalId::Type_Pathgrids,
|
||||
new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<PathgridCreator> >);
|
||||
new CSVDoc::SubViewFactoryWithCreator<TableSubView, PathgridCreatorFactory>);
|
||||
|
||||
manager.add (CSMWorld::UniversalId::Type_Globals,
|
||||
new CSVDoc::SubViewFactoryWithCreator<TableSubView, CreatorFactory<GlobalCreator> >);
|
||||
@ -174,7 +174,7 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
||||
new CSVDoc::SubViewFactoryWithCreator<DialogueSubView, JournalCreatorFactory> (false));
|
||||
|
||||
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,
|
||||
new CSVDoc::SubViewFactoryWithCreator<DialogueSubView, CreatorFactory<GenericCreator, CSMWorld::Scope_Project | CSMWorld::Scope_Session> > (false));
|
||||
|
Loading…
x
Reference in New Issue
Block a user