Commit 112ad001 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

simplify project tree construction

parent e0bcc697
......@@ -378,7 +378,6 @@ void KateProject::registerUntrackedDocument(KTextEditor::Document *document)
// create document item
QFileInfo fileInfo(document->url().toLocalFile());
KateProjectItem *fileItem = new KateProjectItem(KateProjectItem::File, fileInfo.fileName());
fileItem->setData(document->url().toLocalFile(), Qt::ToolTipRole);
fileItem->slotModifiedChanged(document);
connect(document, &KTextEditor::Document::modifiedChanged, this, &KateProject::slotModifiedChanged);
// clang-format off
......
......@@ -89,7 +89,7 @@ bool KateProjectItem::operator<(const QStandardItem &other) const
{
// let directories stay first
const auto thisType = data(TypeRole).toInt();
const bool otherType = other.data(TypeRole).toInt();
const auto otherType = other.data(TypeRole).toInt();
if (thisType != otherType) {
return thisType < otherType;
}
......
......@@ -264,7 +264,6 @@ void KateProjectWorker::loadFilesEntry(QStandardItem *parent, const QVariantMap
*/
QHash<QString, QStandardItem *> dir2Item;
dir2Item[QString()] = parent;
QVector<QPair<QStandardItem *, QStandardItem *>> item2ParentPath;
for (const QString &filePath : files) {
/**
* cheap file name computation
......@@ -279,7 +278,8 @@ void KateProjectWorker::loadFilesEntry(QStandardItem *parent, const QVariantMap
* already hang in directories in tree
*/
KateProjectItem *fileItem = new KateProjectItem(KateProjectItem::File, fileName);
fileItem->setData(filePath, Qt::ToolTipRole);
fileItem->setData(filePath, Qt::UserRole);
(*file2Item)[filePath] = fileItem;
// get the directory's relative path to the base directory
QString dirRelPath = dir.relativeFilePath(filePathName);
......@@ -288,16 +288,8 @@ void KateProjectWorker::loadFilesEntry(QStandardItem *parent, const QVariantMap
dirRelPath = QString();
}
item2ParentPath.append(QPair<QStandardItem *, QStandardItem *>(fileItem, directoryParent(dir2Item, dirRelPath)));
fileItem->setData(filePath, Qt::UserRole);
(*file2Item)[filePath] = fileItem;
}
/**
* plug in the file items to the tree
*/
for (const auto &item : qAsConst(item2ParentPath)) {
item.second->appendRow(item.first);
// put in our item to the right directory parent
directoryParent(dir2Item, dirRelPath)->appendRow(fileItem);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment