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:
parent
837183ec79
commit
59fab4c9e2
@ -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;
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user