Skip to content

Commit

Permalink
Fix issue with moving characters & locations to the end of list
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkanovikov committed Nov 28, 2024
1 parent 724b0d6 commit dfe0e20
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 39 deletions.
5 changes: 0 additions & 5 deletions src/core/management_layer/content/project/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2420,9 +2420,6 @@ ProjectManager::ProjectManager(QObject* _parent, QWidget* _parentWidget,
d->addDocumentToContainer(Domain::DocumentObjectType::Characters,
Domain::DocumentObjectType::Character, _name, _content);
});
connect(&d->modelsFacade, &ProjectModelsFacade::moveCharacterRequested,
d->projectStructureModel,
qOverload<const QUuid&, int>(&BusinessLayer::StructureModel::moveItem));
connect(&d->modelsFacade, &ProjectModelsFacade::characterNameChanged, this,
[this](BusinessLayer::AbstractModel* _character, const QString& _newName,
const QString& _oldName) {
Expand Down Expand Up @@ -2594,8 +2591,6 @@ ProjectManager::ProjectManager(QObject* _parent, QWidget* _parentWidget,
d->addDocumentToContainer(Domain::DocumentObjectType::Locations,
Domain::DocumentObjectType::Location, _name, _content);
});
connect(&d->modelsFacade, &ProjectModelsFacade::moveLocationRequested, d->projectStructureModel,
qOverload<const QUuid&, int>(&BusinessLayer::StructureModel::moveItem));
connect(&d->modelsFacade, &ProjectModelsFacade::locationNameChanged, this,
[this](BusinessLayer::AbstractModel* _location, const QString& _newName,
const QString& _oldName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,6 @@ BusinessLayer::AbstractModel* ProjectModelsFacade::modelFor(Domain::DocumentObje

connect(charactersModel, &BusinessLayer::CharactersModel::createCharacterRequested,
this, &ProjectModelsFacade::createCharacterRequested);
connect(charactersModel, &BusinessLayer::CharactersModel::moveCharacterRequested, this,
&ProjectModelsFacade::moveCharacterRequested);

model = charactersModel;
break;
Expand Down Expand Up @@ -1126,8 +1124,6 @@ BusinessLayer::AbstractModel* ProjectModelsFacade::modelFor(Domain::DocumentObje

connect(locationsModel, &BusinessLayer::LocationsModel::createLocationRequested, this,
&ProjectModelsFacade::createLocationRequested);
connect(locationsModel, &BusinessLayer::LocationsModel::moveLocationRequested, this,
&ProjectModelsFacade::moveLocationRequested);

model = locationsModel;
break;
Expand Down
10 changes: 0 additions & 10 deletions src/core/management_layer/content/project/project_models_facade.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,6 @@ class ProjectModelsFacade : public QObject
*/
void createCharacterRequested(const QString& _name, const QByteArray& _content);

/**
* @brief Необходимо переставить персонажа в новое место
*/
void moveCharacterRequested(const QUuid& _uuid, int _to);

/**
* @brief Изменилось имя персонажа
*/
Expand All @@ -192,11 +187,6 @@ class ProjectModelsFacade : public QObject
*/
void createLocationRequested(const QString& _name, const QByteArray& _content);

/**
* @brief Необходимо переставить локацию в новое место
*/
void moveLocationRequested(const QUuid& _uuid, int _to);

/**
* @brief Изменилось название локации
*/
Expand Down
11 changes: 6 additions & 5 deletions src/corelib/business_layer/model/characters/characters_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ CharactersModel::CharactersModel(QObject* _parent)
&CharactersModel::updateDocumentContent);
connect(this, &CharactersModel::characterPositionChanged, this,
&CharactersModel::updateDocumentContent);
connect(this, &CharactersModel::moveCharacterRequested, this,
&CharactersModel::updateDocumentContent);
}

void CharactersModel::addCharacterModel(CharacterModel* _characterModel)
Expand Down Expand Up @@ -147,12 +145,15 @@ void CharactersModel::moveCharacter(const QString& _name, int _index)
for (int index = 0; index < d->characterModels.size(); ++index) {
auto characterModel = d->characterModels[index];
if (characterModel->name() == nameCorrected) {
if (index == _index) {
//
// Если перемещение происходит вниз списка, то корректируем целевой индекс
//
const int indexCorrected = index < _index ? _index - 1 : _index;
if (index == indexCorrected) {
break;
}

d->characterModels.move(index, _index);
emit moveCharacterRequested(characterModel->document()->uuid(), _index);
d->characterModels.move(index, indexCorrected);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ class CORE_LIBRARY_EXPORT CharactersModel : public AbstractModel
*/
void createCharacterRequested(const QString& _name, const QByteArray& _content);

/**
* @brief Необходимо перенести персонажа на заданную позицию
*/
void moveCharacterRequested(const QUuid& _uuid, int _to);

protected:
/**
* @brief Реализация модели для работы с документами
Expand Down
11 changes: 6 additions & 5 deletions src/corelib/business_layer/model/locations/locations_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ LocationsModel::LocationsModel(QObject* _parent)
&LocationsModel::updateDocumentContent);
connect(this, &LocationsModel::locationPositionChanged, this,
&LocationsModel::updateDocumentContent);
connect(this, &LocationsModel::moveLocationRequested, this,
&LocationsModel::updateDocumentContent);
}

void LocationsModel::addLocationModel(LocationModel* _locationModel)
Expand Down Expand Up @@ -147,12 +145,15 @@ void LocationsModel::moveLocation(const QString& _name, int _index)
for (int index = 0; index < d->locationModels.size(); ++index) {
auto locationModel = d->locationModels[index];
if (locationModel->name() == nameCorrected) {
if (index == _index) {
//
// Если перемещение происходит вниз списка, то корректируем целевой индекс
//
const int indexCorrected = index < _index ? _index - 1 : _index;
if (index == indexCorrected) {
break;
}

d->locationModels.move(index, _index);
emit moveLocationRequested(locationModel->document()->uuid(), _index);
d->locationModels.move(index, indexCorrected);
break;
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/corelib/business_layer/model/locations/locations_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ class CORE_LIBRARY_EXPORT LocationsModel : public AbstractModel
*/
void createLocationRequested(const QString& _name, const QByteArray& _content);

/**
* @brief Необходимо перенести локацию на заданную позицию
*/
void moveLocationRequested(const QUuid& _uuid, int _to);

protected:
/**
* @brief Реализация модели для работы с документами
Expand Down

0 comments on commit dfe0e20

Please sign in to comment.