VirtualTileBox添加子项索引到数据索引的相互转换方法
This commit is contained in:
parent
8adeea0606
commit
ba1381df3e
@ -203,6 +203,11 @@ void VirtualTileBox::SetDataProvider(VirtualTileInterface *pProvider)
|
||||
}
|
||||
|
||||
|
||||
VirtualTileInterface* VirtualTileBox::GetDataProvider()
|
||||
{
|
||||
return m_pDataProvider;
|
||||
}
|
||||
|
||||
void VirtualTileBox::Refresh()
|
||||
{
|
||||
m_nMaxItemCount = GetTileLayout()->AjustMaxItem();
|
||||
@ -528,11 +533,8 @@ void VirtualTileBox::OnModelDataChanged(int nStartIndex, int nEndIndex)
|
||||
{
|
||||
for (auto i = nStartIndex; i <= nEndIndex; i++)
|
||||
{
|
||||
if (IsElementDisplay(i))
|
||||
{
|
||||
int nTopItemHeight = 0;
|
||||
int nItemIndex = i - GetTopElementIndex(nTopItemHeight);
|
||||
ASSERT(nItemIndex > 0);
|
||||
int nItemIndex = ElementIndexToItemIndex(nStartIndex);
|
||||
if (nItemIndex >= 0) {
|
||||
FillElement(m_items[nItemIndex], i);
|
||||
}
|
||||
}
|
||||
@ -543,3 +545,19 @@ void VirtualTileBox::OnModelCountChanged()
|
||||
Refresh();
|
||||
}
|
||||
|
||||
int VirtualTileBox::ElementIndexToItemIndex(int nElementIndex)
|
||||
{
|
||||
if (IsElementDisplay(nElementIndex))
|
||||
{
|
||||
int nTopItemHeight = 0;
|
||||
return nElementIndex - GetTopElementIndex(nTopItemHeight);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int VirtualTileBox::ItemIndexToElementIndex(int nItemIndex)
|
||||
{
|
||||
int nTopItemHeight = 0;
|
||||
return GetTopElementIndex(nTopItemHeight) + nItemIndex;
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,8 @@ public:
|
||||
*/
|
||||
virtual void SetDataProvider(VirtualTileInterface *pProvider);
|
||||
|
||||
virtual VirtualTileInterface* GetDataProvider();
|
||||
|
||||
/**
|
||||
* @brief 刷新列表
|
||||
* @return 无
|
||||
@ -194,6 +196,10 @@ private:
|
||||
|
||||
void OnModelCountChanged();
|
||||
|
||||
int ElementIndexToItemIndex(int nElementIndex);
|
||||
|
||||
int ItemIndexToElementIndex(int nItemIndex);
|
||||
|
||||
private:
|
||||
VirtualTileInterface *m_pDataProvider;
|
||||
int m_nMaxItemCount; // 列表真实控件数量上限
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "item.h"
|
||||
|
||||
#include "VirtualTileBox.h"
|
||||
#include "provider.h"
|
||||
|
||||
Item::Item()
|
||||
:control_img_(nullptr)
|
||||
@ -9,10 +10,9 @@ Item::Item()
|
||||
|
||||
|
||||
Item::~Item()
|
||||
{
|
||||
}
|
||||
= default;
|
||||
|
||||
void Item::InitSubControls(const std::wstring& img, const std::wstring& title)
|
||||
void Item::InitSubControls(const std::wstring& img, const std::wstring& title, int nDataIndex)
|
||||
{
|
||||
// 查找 Item 下的控件
|
||||
if (control_img_ == nullptr)
|
||||
@ -35,7 +35,7 @@ void Item::InitSubControls(const std::wstring& img, const std::wstring& title)
|
||||
|
||||
|
||||
label_title_->SetText(nbase::StringPrintf(L"%s %d%%", title.c_str(), t_time % 100));
|
||||
|
||||
m_nDataIndex = nDataIndex;
|
||||
|
||||
}
|
||||
|
||||
@ -43,5 +43,8 @@ void Item::InitSubControls(const std::wstring& img, const std::wstring& title)
|
||||
bool Item::OnRemove(ui::EventArgs* args)
|
||||
{
|
||||
// 删除时,只需删除数据就可以了,不要删除界面上的元素
|
||||
VirtualTileBox* pTileBox = dynamic_cast<VirtualTileBox*>(m_pOwner);
|
||||
Provider* pProvider = dynamic_cast<Provider*>(pTileBox->GetDataProvider());
|
||||
pProvider->RemoveTask(m_nDataIndex);
|
||||
return true;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ public:
|
||||
~Item();
|
||||
|
||||
// 提供外部调用来初始化 item 数据
|
||||
void InitSubControls(const std::wstring& img, const std::wstring& title);
|
||||
void InitSubControls(const std::wstring& img, const std::wstring& title, int nDataIndex);
|
||||
private:
|
||||
bool OnRemove(ui::EventArgs* args);
|
||||
|
||||
@ -20,5 +20,6 @@ private:
|
||||
ui::Progress* progress_;
|
||||
ui::Button* btn_del_;
|
||||
int64_t t_time;
|
||||
int m_nDataIndex;
|
||||
};
|
||||
|
||||
|
@ -29,7 +29,7 @@ void Provider::FillElement(ui::Control *control, int index)
|
||||
|
||||
std::wstring img = L"icon.png";
|
||||
std::wstring title = nbase::StringPrintf(L"%s [%02d]", m_vTasks[index].sName.c_str(), m_vTasks[index].nId);
|
||||
pItem->InitSubControls(img, title);
|
||||
pItem->InitSubControls(img, title, index);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user