| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
|---|---|
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "symbolmodel.h" |
| 6 | #include "definitions.h" |
| 7 | |
| 8 | #include <QDebug> |
| 9 | |
| 10 | SymbolModel::SymbolModel(QObject *parent) |
| 11 | : QFileSystemModel (parent) |
| 12 | { |
| 13 | setFilter(QDir::Dirs|QDir::NoDotAndDotDot); |
| 14 | } |
| 15 | |
| 16 | QVariant SymbolModel::data(const QModelIndex &index, int role) const |
| 17 | { |
| 18 | if (role == Qt::ItemDataRole::DecorationRole) { |
| 19 | return QVariant(); |
| 20 | } else if (role == Qt::ItemDataRole::ToolTipRole) { |
| 21 | QFile file(filePath(index) + QDir::separator() + SymbolPri::recordFileName); |
| 22 | if (file.exists()) { |
| 23 | if (!file.open(QFile::ReadOnly)) { |
| 24 | qCritical() << file.errorString(); |
| 25 | } |
| 26 | QString data = file.readAll(); |
| 27 | data = data.remove(data.length() -1, 1); |
| 28 | file.close(); |
| 29 | return data; |
| 30 | } |
| 31 | } else { |
| 32 | // TODO:Huang yu |
| 33 | } |
| 34 | return QFileSystemModel::data(index, role); |
| 35 | } |
| 36 | |
| 37 | int SymbolModel::columnCount(const QModelIndex &parent) const |
| 38 | { |
| 39 | Q_UNUSED(parent) |
| 40 | return 1; |
| 41 | } |
| 42 | |
| 43 | bool SymbolModel::hasChildren(const QModelIndex &parent) const |
| 44 | { |
| 45 | auto folder = fileInfo(parent).filePath(); |
| 46 | QDir dir(folder); |
| 47 | dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); |
| 48 | dir.setSorting(QDir::Name); |
| 49 | QStringList allFolder = dir.entryList(); |
| 50 | return !allFolder.isEmpty(); |
| 51 | } |
| 52 |