diff --git a/apps/openmw/mwgui/alchemywindow.cpp b/apps/openmw/mwgui/alchemywindow.cpp index 48d1a609fc..e7ae5b74c5 100644 --- a/apps/openmw/mwgui/alchemywindow.cpp +++ b/apps/openmw/mwgui/alchemywindow.cpp @@ -247,12 +247,13 @@ namespace MWGui auto model = std::make_unique(MWMechanics::getPlayer()); mModel = model.get(); - mSortModel = new SortFilterItemModel(std::move(model)); + auto sortModel = std::make_unique(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; diff --git a/apps/openmw/mwgui/companionwindow.cpp b/apps/openmw/mwgui/companionwindow.cpp index a8e545f8fd..99ed2d995c 100644 --- a/apps/openmw/mwgui/companionwindow.cpp +++ b/apps/openmw/mwgui/companionwindow.cpp @@ -125,9 +125,10 @@ void CompanionWindow::setPtr(const MWWorld::Ptr& npc) updateEncumbranceBar(); auto model = std::make_unique(npc); mModel = model.get(); - mSortModel = new SortFilterItemModel(std::move(model)); - mFilterEdit->setCaption(std::string()); - mItemView->setModel(mSortModel); + auto sortModel = std::make_unique(std::move(model)); + mSortModel = sortModel.get(); + mFilterEdit->setCaption({}); + mItemView->setModel(std::move(sortModel)); mItemView->resetScrollBars(); setTitle(npc.getClass().getName(npc)); diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 4f48f70636..ad23af4711 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -148,9 +148,10 @@ namespace MWGui mDisposeCorpseButton->setVisible(loot); mModel = model.get(); - mSortModel = new SortFilterItemModel(std::move(model)); + auto sortModel = std::make_unique(std::move(model)); + mSortModel = sortModel.get(); - mItemView->setModel (mSortModel); + mItemView->setModel(std::move(sortModel)); mItemView->resetScrollBars(); MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCloseButton); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 297bfb04b1..8a3a72d2b0 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -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(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); diff --git a/apps/openmw/mwgui/itemselection.cpp b/apps/openmw/mwgui/itemselection.cpp index 4674e9bf5e..1a34f5d623 100644 --- a/apps/openmw/mwgui/itemselection.cpp +++ b/apps/openmw/mwgui/itemselection.cpp @@ -36,8 +36,9 @@ namespace MWGui void ItemSelectionDialog::openContainer(const MWWorld::Ptr& container) { - mSortModel = new SortFilterItemModel(std::make_unique(container)); - mItemView->setModel(mSortModel); + auto sortModel = std::make_unique(std::make_unique(container)); + mSortModel = sortModel.get(); + mItemView->setModel(std::move(sortModel)); mItemView->resetScrollBars(); } diff --git a/apps/openmw/mwgui/itemview.cpp b/apps/openmw/mwgui/itemview.cpp index 14f2c1dd9b..ba12d622c5 100644 --- a/apps/openmw/mwgui/itemview.cpp +++ b/apps/openmw/mwgui/itemview.cpp @@ -16,23 +16,13 @@ namespace MWGui { ItemView::ItemView() - : mModel(nullptr) - , mScrollView(nullptr) + : mScrollView(nullptr) { } -ItemView::~ItemView() +void ItemView::setModel(std::unique_ptr 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("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; diff --git a/apps/openmw/mwgui/itemview.hpp b/apps/openmw/mwgui/itemview.hpp index 4074e55e48..e2f882e618 100644 --- a/apps/openmw/mwgui/itemview.hpp +++ b/apps/openmw/mwgui/itemview.hpp @@ -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 model); typedef MyGUI::delegates::CMultiDelegate1 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 mModel; MyGUI::ScrollView* mScrollView; }; diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 5832bab830..3abe10a6fb 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -116,8 +116,9 @@ namespace MWGui auto tradeModel = std::make_unique(std::make_unique(itemSources, worldItems), mPtr); mTradeModel = tradeModel.get(); - mSortModel = new SortFilterItemModel(std::move(tradeModel)); - mItemView->setModel (mSortModel); + auto sortModel = std::make_unique(std::move(tradeModel)); + mSortModel = sortModel.get(); + mItemView->setModel(std::move(sortModel)); mItemView->resetScrollBars(); updateLabels();