CVirtualDirectoryModel: Eliminate string copies where applicable
This commit is contained in:
parent
fdcb0b770c
commit
dcfb34ca1c
|
@ -169,15 +169,12 @@ bool CVirtualDirectoryModel::dropMimeData(const QMimeData *pkData, Qt::DropActio
|
||||||
|
|
||||||
QMimeData* CVirtualDirectoryModel::mimeData(const QModelIndexList& rkIndexes) const
|
QMimeData* CVirtualDirectoryModel::mimeData(const QModelIndexList& rkIndexes) const
|
||||||
{
|
{
|
||||||
if (rkIndexes.size() == 1)
|
if (rkIndexes.size() != 1)
|
||||||
{
|
|
||||||
QModelIndex Index = rkIndexes.front();
|
|
||||||
CVirtualDirectory *pDir = IndexDirectory(Index);
|
|
||||||
CResourceMimeData *pMimeData = new CResourceMimeData(pDir);
|
|
||||||
return pMimeData;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
const QModelIndex Index = rkIndexes.front();
|
||||||
|
CVirtualDirectory *pDir = IndexDirectory(Index);
|
||||||
|
return new CResourceMimeData(pDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::DropActions CVirtualDirectoryModel::supportedDragActions() const
|
Qt::DropActions CVirtualDirectoryModel::supportedDragActions() const
|
||||||
|
@ -231,7 +228,9 @@ QModelIndex CVirtualDirectoryModel::GetIndexForDirectory(CVirtualDirectory *pDir
|
||||||
|
|
||||||
CVirtualDirectory* CVirtualDirectoryModel::IndexDirectory(const QModelIndex& rkIndex) const
|
CVirtualDirectory* CVirtualDirectoryModel::IndexDirectory(const QModelIndex& rkIndex) const
|
||||||
{
|
{
|
||||||
if (!rkIndex.isValid()) return nullptr;
|
if (!rkIndex.isValid())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
return static_cast<CVirtualDirectory*>(rkIndex.internalPointer());
|
return static_cast<CVirtualDirectory*>(rkIndex.internalPointer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +241,7 @@ void CVirtualDirectoryModel::SetRoot(CVirtualDirectory *pDir)
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CVirtualDirectoryModel::GetProposedIndex(QString Path, QModelIndex& rOutParent, int& rOutRow)
|
bool CVirtualDirectoryModel::GetProposedIndex(const QString& Path, QModelIndex& rOutParent, int& rOutRow)
|
||||||
{
|
{
|
||||||
// Get parent path
|
// Get parent path
|
||||||
TString FullPath = TO_TSTRING(Path);
|
TString FullPath = TO_TSTRING(Path);
|
||||||
|
@ -279,16 +278,17 @@ bool CVirtualDirectoryModel::GetProposedIndex(QString Path, QModelIndex& rOutPar
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVirtualDirectoryModel::OnDirectoryAboutToBeMoved(CVirtualDirectory *pDir, QString NewPath)
|
void CVirtualDirectoryModel::OnDirectoryAboutToBeMoved(CVirtualDirectory *pDir, const QString& NewPath)
|
||||||
{
|
{
|
||||||
QModelIndex Parent;
|
QModelIndex Parent;
|
||||||
int Row;
|
int Row;
|
||||||
|
|
||||||
if (GetProposedIndex(NewPath, Parent, Row))
|
if (!GetProposedIndex(NewPath, Parent, Row))
|
||||||
{
|
return;
|
||||||
QModelIndex OldIndex = GetIndexForDirectory(pDir);
|
|
||||||
QModelIndex OldParent = OldIndex.parent();
|
const QModelIndex OldIndex = GetIndexForDirectory(pDir);
|
||||||
int OldRow = OldIndex.row();
|
const QModelIndex OldParent = OldIndex.parent();
|
||||||
|
const int OldRow = OldIndex.row();
|
||||||
|
|
||||||
if (OldParent == Parent && (Row == OldRow || Row == OldRow + 1))
|
if (OldParent == Parent && (Row == OldRow || Row == OldRow + 1))
|
||||||
{
|
{
|
||||||
|
@ -301,9 +301,8 @@ void CVirtualDirectoryModel::OnDirectoryAboutToBeMoved(CVirtualDirectory *pDir,
|
||||||
mMovingRows = true;
|
mMovingRows = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CVirtualDirectoryModel::OnDirectoryAboutToBeCreated(QString DirPath)
|
void CVirtualDirectoryModel::OnDirectoryAboutToBeCreated(const QString& DirPath)
|
||||||
{
|
{
|
||||||
QModelIndex Parent;
|
QModelIndex Parent;
|
||||||
int Row;
|
int Row;
|
||||||
|
@ -317,7 +316,7 @@ void CVirtualDirectoryModel::OnDirectoryAboutToBeCreated(QString DirPath)
|
||||||
|
|
||||||
void CVirtualDirectoryModel::OnDirectoryAboutToBeDeleted(CVirtualDirectory *pDir)
|
void CVirtualDirectoryModel::OnDirectoryAboutToBeDeleted(CVirtualDirectory *pDir)
|
||||||
{
|
{
|
||||||
QModelIndex Index = GetIndexForDirectory(pDir);
|
const QModelIndex Index = GetIndexForDirectory(pDir);
|
||||||
|
|
||||||
if (Index.isValid())
|
if (Index.isValid())
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,11 +37,11 @@ public:
|
||||||
void SetRoot(CVirtualDirectory *pDir);
|
void SetRoot(CVirtualDirectory *pDir);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool GetProposedIndex(QString Path, QModelIndex& rOutParent, int& rOutRow);
|
bool GetProposedIndex(const QString& Path, QModelIndex& rOutParent, int& rOutRow);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void OnDirectoryAboutToBeMoved(CVirtualDirectory *pDir, QString NewPath);
|
void OnDirectoryAboutToBeMoved(CVirtualDirectory *pDir, const QString& NewPath);
|
||||||
void OnDirectoryAboutToBeCreated(QString DirPath);
|
void OnDirectoryAboutToBeCreated(const QString& DirPath);
|
||||||
void OnDirectoryAboutToBeDeleted(CVirtualDirectory *pDir);
|
void OnDirectoryAboutToBeDeleted(CVirtualDirectory *pDir);
|
||||||
void FinishModelChanges();
|
void FinishModelChanges();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue