Merge remote-tracking branch 'rcutmore/bug-3345'

0.6.1
Marc Zinnschlag 8 years ago
commit c2ecd47acd

@ -1,29 +1,101 @@
#include "pathgridcreator.hpp"
#include <QComboBox>
#include <QLabel>
#include <QSortFilterProxyModel>
#include <QStringListModel>
#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);
setupCellsInput();
connect(&getData(), SIGNAL (idListChanged()), this, SLOT (setupCellsInput()));
connect(mCell, SIGNAL (currentIndexChanged(const QString&)), this, SLOT (cellChanged()));
}
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;
}
void CSVWorld::PathgridCreator::focus()
{
mCell->setFocus();
}
void CSVWorld::PathgridCreator::reset()
{
CSVWorld::GenericCreator::reset();
mCell->setCurrentIndex(0);
}
void CSVWorld::PathgridCreator::cellChanged()
{
update();
}
void CSVWorld::PathgridCreator::setupCellsInput()
{
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);
}

@ -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(
@ -20,6 +29,20 @@ namespace CSVWorld
/// \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.
virtual void reset();
private slots:
/// \brief Check user input for errors.
void cellChanged();
/// \brief Setup cells in combo box.
void setupCellsInput();
};
}

Loading…
Cancel
Save