void bv_refinementt::post_process_arrays() { // just build the data structure build_index_map(); // we don't actually add any constraints }
/** * @brief Deletes an animation. * * The index of the selection may change, since animations are sorted * alphabetically. * Emits rowsAboutToBeRemoved(), removes the animation * and then emits rowsRemoved(), as required by QAbstractItemModel. * * Then, emits animation_deleted(). * * Except for the deleted animation, the existing selection is preserved, * though the index of many animations can change. * The selection is cleared before the operations and restored after, * updated with the new index. * * @param index Index of the animation to delete. * @throws EditorException in case of error. */ void SpriteModel::delete_animation(const Index &index) { // Make some checks first. if (!animation_exists(index)) { throw EditorException( tr("Animation '%1' don't exists").arg(index.animation_name)); } // Save and clear the selection since a lot of indexes may change. Index selection = get_selected_index(); clear_selection(); int animation_nb = get_animation_nb(index); // Delete the animation in the sprite file. sprite.remove_animation(index.animation_name.toStdString()); // Rebuild indexes in the list model (indexes were shifted). build_index_map(); // Call beginRemoveRows() as requested by QAbstractItemModel. beginRemoveRows(QModelIndex(), animation_nb, animation_nb); // Update our animation model list. animations.removeAt(animation_nb); // Notify people before restoring the selection, so that they have a // chance to know new indexes before receiving selection signals. endRemoveRows(); emit animation_deleted(index); // Restore the selection. set_selected_index(selection); }
/** * @brief Inserts an animation in this sprite. * * The index of the selection may change, since animations are sorted * alphabetically. * Emits rowsAboutToBeInserted(), inserts the animation * and then emits rowsInserted(), as required by QAbstractItemModel. * * Then, emits animation_created(). * * The newly created animation is not initially selected. * The existing selection is preserved, though the index of many * animations can change. * The selection is cleared before the operations and restored after, * updated with the new index. * * @param index Index of the animation to insert. * @param data Data of the animation. * @throws EditorException in case of error. */ void SpriteModel::insert_animation( const Index& index, const Solarus::SpriteAnimationData& data) { // Make some checks first. if (index.animation_name.length() <= 0) { throw EditorException(tr("Animation name cannot be empty")); } if (animation_exists(index)) { throw EditorException( tr("Animation '%1' already exists").arg(index.animation_name)); } // Save and clear the selection since a lot of indexes may change. Index selection = get_selected_index(); clear_selection(); // Add the animation to the sprite file. sprite.add_animation(index.animation_name.toStdString(), data); // Rebuild indexes in the list model (indexes were shifted). build_index_map(); // Call beginInsertRows() as requested by QAbstractItemModel. int animation_nb = get_animation_nb(index.animation_name); beginInsertRows(QModelIndex(), animation_nb, animation_nb); // Update our animation model list. animations.insert(animation_nb, AnimationModel(index.animation_name)); int num_directions = data.get_num_directions(); for (int nb = 0; nb < num_directions; nb++) { animations[animation_nb].directions.append( DirectionModel(index.animation_name, nb)); } // Notify people before restoring the selection, so that they have a // chance to know new indexes before receiving selection signals. endInsertRows(); emit animation_created(index); // Restore the selection. set_selected_index(selection); }
void arrayst::add_array_constraints() { // first get index map build_index_map(); // add constraints for if, with, array_of for(unsigned i=0; i<arrays.size(); i++) add_array_constraints( index_map[arrays.find_number(i)], arrays[i]); // add constraints for equalities for(array_equalitiest::const_iterator it= array_equalities.begin(); it!=array_equalities.end(); it++) add_array_constraints( index_map[arrays.find_number(it->f1)], *it); // add the Ackermann constraints add_array_Ackermann_constraints(); }
/** * @brief Creates a sprite model. * @param quest The quest. * @param sprite_id Id of the sprite to manage. * @param parent The parent object or nullptr. * @throws EditorException If the file could not be opened. */ SpriteModel::SpriteModel( Quest& quest, const QString& sprite_id, QObject* parent) : QAbstractItemModel(parent), quest(quest), sprite_id(sprite_id), selection_model(this) { // Load the sprite data file. QString path = quest.get_sprite_path(sprite_id); if (!sprite.import_from_file(path.toStdString())) { throw EditorException(tr("Cannot open sprite '%1'").arg(path)); } // Build the index map of animations. build_index_map(); // Create animations and directions models. for (const auto& kvp : names_to_indexes) { const QString& animation_name = kvp.first; AnimationModel animation(animation_name); int num_dir = get_animation(animation_name).get_num_directions(); for (int nb = 0; nb < num_dir; nb++) { animation.directions.append(DirectionModel(animation_name, nb)); } animations.append(animation); } // use the first tileset of the quest QStringList tilesets = quest.get_resources().get_elements(ResourceType::TILESET); if (tilesets.size() > 0) { tileset_id = tilesets[0]; } }
/** * @brief Changes the name of an animation. * * The index of the selection may change, since animations are sorted * alphabetically. * In this case, emits rowsAboutToBeMoved(), changes the index * and then emits rowsMoved(), as required by QAbstractItemModel. * * Then, emits animation_name_changed(), no matter if the index has also changed. * * The selection is preserved, though the index of many animations can change. * The selection is cleared before the operations and restored after, * updated with the new index. * * @param index Index of an existing animation. * @param new_name The new name to set. * @throws EditorException in case of error. */ void SpriteModel::set_animation_name(const Index& index, const QString& new_name) { if (new_name == index.animation_name) { // Nothing to do. return; } // Make some checks first. if (!animation_exists(index)) { throw EditorException( tr("Animation '%1' don't exists").arg(index.animation_name)); } if (new_name.length() <= 0) { throw EditorException(tr("Animation name cannot be empty")); } if (animation_exists(new_name)) { throw EditorException(tr("Animation '%1' already exists").arg(new_name)); } // Save and clear the selection since a lot of indexes may change. Index selection = get_selected_index(); clear_selection(); int animation_nb = get_animation_nb(index); // Change the name in the sprite file. sprite.set_animation_name( index.animation_name.toStdString(), new_name.toStdString()); // Change the index in the list model (if the order has changed). build_index_map(); int new_animation_nb = get_animation_nb(new_name); // Call beginMoveRows() if the index changes, as requested by // QAbstractItemModel. if (new_animation_nb != animation_nb) { int above_row = new_animation_nb; if (new_animation_nb > animation_nb) { ++above_row; } beginMoveRows(QModelIndex(), animation_nb, animation_nb, QModelIndex(), above_row); // Update our animation model list. animations.move(animation_nb, new_animation_nb); } animations[new_animation_nb].set_animation_name(new_name); // Notify people before restoring the selection, so that they have a // chance to know new indexes before receiving selection signals. if (new_animation_nb != animation_nb) { endMoveRows(); } emit animation_name_changed(index, Index(new_name)); // Restore the selection. if (selection.animation_name == index.animation_name) { selection.animation_name = new_name; } set_selected_index(selection); }