| 53 | } |
| 54 | |
| 55 | QVariant CHistoryModel::data(const QModelIndex &index, int role) const |
| 56 | { |
| 57 | |
| 58 | if (!index.isValid() || index.row() >= m_historyItems.count()) |
| 59 | return QVariant(); |
| 60 | |
| 61 | if(!m_pDatabase) { |
| 62 | qCritical(log) << "The m_pDatabase is nullptr"; |
| 63 | return QVariant(); |
| 64 | } |
| 65 | |
| 66 | const HistoryItem &item = m_historyItems.at(index.row()); |
| 67 | |
| 68 | switch (role) { |
| 69 | case Qt::DisplayRole: |
| 70 | switch (index.column()) { |
| 71 | case ColumnTitle: |
| 72 | return item.title.isEmpty() ? tr("Untitled") : item.title; |
| 73 | case ColumnUrl: |
| 74 | return item.url; |
| 75 | case ColumnVisitTime: |
| 76 | return item.visitTime.toString(QLocale::system().dateFormat()); |
| 77 | } |
| 78 | break; |
| 79 | |
| 80 | case Qt::DecorationRole: |
| 81 | if (index.column() == ColumnTitle) { |
| 82 | return item.icon; |
| 83 | } |
| 84 | break; |
| 85 | |
| 86 | case Qt::ToolTipRole: |
| 87 | return QString(tr("Title: %1\nUrl: %2\nVisit Time: %3") |
| 88 | .arg(item.title) |
| 89 | .arg(item.url) |
| 90 | .arg(item.visitTime.toString(QLocale::system().dateFormat()))); |
| 91 | |
| 92 | case Qt::UserRole: |
| 93 | return item.url; // 返回URL用于导航 |
| 94 | } |
| 95 | |
| 96 | return QVariant(); |
| 97 | } |
| 98 | |
| 99 | void CHistoryModel::refresh() |
| 100 | { |
no test coverage detected