Implemented "find" button on resource selector widget

This commit is contained in:
Aruki 2017-02-01 21:01:14 -07:00
parent 548fcb2f8e
commit c53352c290
5 changed files with 63 additions and 3 deletions

View File

@ -72,6 +72,35 @@ CResourceBrowser::~CResourceBrowser()
delete mpUI;
}
void CResourceBrowser::SelectResource(CResourceEntry *pEntry)
{
ASSERT(pEntry);
// Clear search
mpUI->SearchBar->clear();
UpdateFilter();
// Select target directory
SelectDirectory(pEntry->Directory());
// Select resource
int Row = mpModel->GetIndexForEntry(pEntry).row();
mpUI->ResourceTableView->selectionModel()->clearSelection();
for (int iCol = 0; iCol < mpModel->columnCount(QModelIndex()); iCol++)
{
QModelIndex Index = mpModel->index(Row, iCol, QModelIndex());
QModelIndex ProxyIndex = mpProxyModel->mapFromSource(Index);
mpUI->ResourceTableView->selectionModel()->setCurrentIndex(ProxyIndex, QItemSelectionModel::Select);
}
}
void CResourceBrowser::SelectDirectory(CVirtualDirectory *pDir)
{
QModelIndex Index = mpDirectoryModel->GetIndexForDirectory(pDir);
mpUI->DirectoryTreeView->selectionModel()->setCurrentIndex(Index, QItemSelectionModel::ClearAndSelect);
}
void CResourceBrowser::RefreshResources()
{
// Fill resource table
@ -157,8 +186,7 @@ void CResourceBrowser::OnDoubleClickTable(QModelIndex Index)
if (mpModel->IsIndexDirectory(SourceIndex))
{
CVirtualDirectory *pDir = mpModel->IndexDirectory(SourceIndex);
QModelIndex Index = mpDirectoryModel->GetIndexForDirectory(pDir);
mpUI->DirectoryTreeView->selectionModel()->setCurrentIndex(Index, QItemSelectionModel::ClearAndSelect);
SelectDirectory(pDir);
}
// Resource - open resource for editing

View File

@ -27,6 +27,8 @@ class CResourceBrowser : public QDialog
public:
explicit CResourceBrowser(QWidget *pParent = 0);
~CResourceBrowser();
void SelectResource(CResourceEntry *pEntry);
void SelectDirectory(CVirtualDirectory *pDir);
// Accessors
inline CResourceEntry* SelectedEntry() const { return mpSelectedEntry; }

View File

@ -85,6 +85,21 @@ public:
return QVariant::Invalid;
}
QModelIndex GetIndexForEntry(CResourceEntry *pEntry) const
{
for (int iRes = 0; iRes < mEntries.size(); iRes++)
{
if (mEntries[iRes] == pEntry)
{
QModelIndex Out = index(mDirectories.size() + iRes, 0);
ASSERT(IndexEntry(Out) == pEntry);
return Out;
}
}
return QModelIndex();
}
CResourceEntry* IndexEntry(const QModelIndex& rkIndex) const
{
int Index = rkIndex.row() - mDirectories.size();
@ -144,7 +159,12 @@ protected:
void RecursiveAddDirectoryContents(CVirtualDirectory *pDir)
{
for (u32 iRes = 0; iRes < pDir->NumResources(); iRes++)
mEntries << pDir->ResourceByIndex(iRes);
{
CResourceEntry *pEntry = pDir->ResourceByIndex(iRes);
if (pEntry->TypeInfo()->IsVisibleInBrowser() && !pEntry->IsHidden())
mEntries << pDir->ResourceByIndex(iRes);
}
for (u32 iDir = 0; iDir < pDir->NumSubdirectories(); iDir++)
RecursiveAddDirectoryContents(pDir->SubdirectoryByIndex(iDir));

View File

@ -47,6 +47,7 @@ CResourceSelector::CResourceSelector(QWidget *pParent /*= 0*/)
// UI Connections
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(CreateContextMenu(QPoint)));
connect(mpSetButton, SIGNAL(clicked()), this, SLOT(Set()));
connect(mpFindButton, SIGNAL(clicked()), this, SLOT(Find()));
connect(mpClearButton, SIGNAL(clicked()), this, SLOT(Clear()));
// Set up context menu
@ -144,6 +145,14 @@ void CResourceSelector::Set()
}
}
void CResourceSelector::Find()
{
CResourceBrowser *pBrowser = gpEdApp->ResourceBrowser();
pBrowser->SelectResource(mpResEntry);
pBrowser->show();
pBrowser->raise();
}
void CResourceSelector::Clear()
{
mpResEntry = nullptr;

View File

@ -39,6 +39,7 @@ public:
public slots:
void CreateContextMenu(const QPoint& rkPoint);
void Set();
void Find();
void Clear();
void EditAsset();
void CopyName();