mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-07-21 05:44:06 +00:00
Merge remote-tracking branch 'rcutmore/bug-3345'
This commit is contained in:
commit
021cef74ff
3 changed files with 88 additions and 42 deletions
|
@ -1,21 +1,34 @@
|
||||||
#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"
|
||||||
|
#include "idvalidator.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 +37,27 @@ 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);
|
mCell->setValidator(new IdValidator(relaxedIdRules, this));
|
||||||
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()));
|
||||||
|
}
|
||||||
|
|
||||||
connect(&getData(), SIGNAL (idListChanged()), this, SLOT (setupCellsInput()));
|
void CSVWorld::PathgridCreator::cloneMode(
|
||||||
connect(mCell, SIGNAL (currentIndexChanged(const QString&)), this, SLOT (cellChanged()));
|
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
|
std::string CSVWorld::PathgridCreator::getErrors() const
|
||||||
|
@ -71,7 +92,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 +100,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 Setup cells in combo box.
|
/// \brief Creator factory for pathgrid record creator.
|
||||||
void setupCellsInput();
|
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>);
|
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…
Reference in a new issue