1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-18 13:12:50 +00:00

Use std::unique_ptr in ItemView

This commit is contained in:
Evil Eye 2022-08-31 19:03:45 +02:00
parent 837183ec79
commit 59fab4c9e2
8 changed files with 28 additions and 32 deletions

View File

@ -247,12 +247,13 @@ namespace MWGui
auto model = std::make_unique<InventoryItemModel>(MWMechanics::getPlayer());
mModel = model.get();
mSortModel = new SortFilterItemModel(std::move(model));
auto sortModel = std::make_unique<SortFilterItemModel>(std::move(model));
mSortModel = sortModel.get();
mSortModel->setFilter(SortFilterItemModel::Filter_OnlyIngredients);
mItemView->setModel (mSortModel);
mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars();
mNameEdit->setCaption("");
mNameEdit->setCaption({});
mBrewCountEdit->setValue(1);
int index = 0;

View File

@ -125,9 +125,10 @@ void CompanionWindow::setPtr(const MWWorld::Ptr& npc)
updateEncumbranceBar();
auto model = std::make_unique<CompanionItemModel>(npc);
mModel = model.get();
mSortModel = new SortFilterItemModel(std::move(model));
mFilterEdit->setCaption(std::string());
mItemView->setModel(mSortModel);
auto sortModel = std::make_unique<SortFilterItemModel>(std::move(model));
mSortModel = sortModel.get();
mFilterEdit->setCaption({});
mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars();
setTitle(npc.getClass().getName(npc));

View File

@ -148,9 +148,10 @@ namespace MWGui
mDisposeCorpseButton->setVisible(loot);
mModel = model.get();
mSortModel = new SortFilterItemModel(std::move(model));
auto sortModel = std::make_unique<SortFilterItemModel>(std::move(model));
mSortModel = sortModel.get();
mItemView->setModel (mSortModel);
mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars();
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCloseButton);

View File

@ -128,12 +128,14 @@ namespace MWGui
if (mSortModel) // reuse existing SortModel when possible to keep previous category/filter settings
mSortModel->setSourceModel(std::move(tradeModel));
else
mSortModel = new SortFilterItemModel(std::move(tradeModel));
{
auto sortModel = std::make_unique<SortFilterItemModel>(std::move(tradeModel));
mSortModel = sortModel.get();
mItemView->setModel(std::move(sortModel));
}
mSortModel->setNameFilter(mFilterEdit->getCaption());
mItemView->setModel(mSortModel);
mFilterAll->setStateSelected(true);
mFilterWeapon->setStateSelected(false);
mFilterApparel->setStateSelected(false);

View File

@ -36,8 +36,9 @@ namespace MWGui
void ItemSelectionDialog::openContainer(const MWWorld::Ptr& container)
{
mSortModel = new SortFilterItemModel(std::make_unique<InventoryItemModel>(container));
mItemView->setModel(mSortModel);
auto sortModel = std::make_unique<SortFilterItemModel>(std::make_unique<InventoryItemModel>(container));
mSortModel = sortModel.get();
mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars();
}

View File

@ -16,23 +16,13 @@ namespace MWGui
{
ItemView::ItemView()
: mModel(nullptr)
, mScrollView(nullptr)
: mScrollView(nullptr)
{
}
ItemView::~ItemView()
void ItemView::setModel(std::unique_ptr<ItemModel> model)
{
delete mModel;
}
void ItemView::setModel(ItemModel *model)
{
if (mModel == model)
return;
delete mModel;
mModel = model;
mModel = std::move(model);
update();
}
@ -114,7 +104,7 @@ void ItemView::update()
ItemWidget* itemWidget = dragArea->createWidget<ItemWidget>("MW_ItemIcon",
MyGUI::IntCoord(0, 0, 42, 42), MyGUI::Align::Default);
itemWidget->setUserString("ToolTipType", "ItemModelIndex");
itemWidget->setUserData(std::make_pair(i, mModel));
itemWidget->setUserData(std::make_pair(i, mModel.get()));
ItemWidget::ItemState state = ItemWidget::None;
if (item.mType == ItemStack::Type_Barter)
state = ItemWidget::Barter;

View File

@ -13,13 +13,12 @@ namespace MWGui
MYGUI_RTTI_DERIVED(ItemView)
public:
ItemView();
~ItemView() override;
/// Register needed components with MyGUI's factory manager
static void registerComponents ();
/// Takes ownership of \a model
void setModel (ItemModel* model);
void setModel(std::unique_ptr<ItemModel> model);
typedef MyGUI::delegates::CMultiDelegate1<ItemModel::ModelIndex> EventHandle_ModelIndex;
typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void;
@ -44,7 +43,7 @@ namespace MWGui
void onSelectedBackground (MyGUI::Widget* sender);
void onMouseWheelMoved(MyGUI::Widget* _sender, int _rel);
ItemModel* mModel;
std::unique_ptr<ItemModel> mModel;
MyGUI::ScrollView* mScrollView;
};

View File

@ -116,8 +116,9 @@ namespace MWGui
auto tradeModel = std::make_unique<TradeItemModel>(std::make_unique<ContainerItemModel>(itemSources, worldItems), mPtr);
mTradeModel = tradeModel.get();
mSortModel = new SortFilterItemModel(std::move(tradeModel));
mItemView->setModel (mSortModel);
auto sortModel = std::make_unique<SortFilterItemModel>(std::move(tradeModel));
mSortModel = sortModel.get();
mItemView->setModel(std::move(sortModel));
mItemView->resetScrollBars();
updateLabels();