/** * @brief Accesses items data * @param index Index of item * @param role Role * @return data */ QVariant ConcertModel::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() > m_concerts.count()) return QVariant(); if (role == Qt::UserRole) return index.row(); Concert *concert = m_concerts[index.row()]; if (index.column() == 0 && role == Qt::DisplayRole) { return concert->name(); } else if (index.column() == 0 && role == Qt::ToolTipRole) { if (concert->files().size() == 0) return QVariant(); return concert->files().at(0); } else if (index.column() == 1 && role == Qt::DisplayRole) { return concert->folderName(); } else if (role == Qt::UserRole+1) { return concert->infoLoaded(); } else if (role == Qt::UserRole+2) { return concert->hasChanged(); } else if (role == Qt::ForegroundRole) { if (concert->hasChanged()) return QColor(255, 0, 0); } else if (role == Qt::FontRole) { if (concert->hasChanged()) { QFont font; font.setItalic(true); return font; } } return QVariant(); }
void ConcertFilesWidget::openFolder() { m_contextMenu->close(); int row = ui->files->currentIndex().data(Qt::UserRole).toInt(); Concert *concert = Manager::instance()->concertModel()->concert(row); if (concert->files().isEmpty()) return; QFileInfo fi(concert->files().at(0)); QUrl url; if (fi.absolutePath().startsWith("\\\\") || fi.absolutePath().startsWith("//")) url.setUrl(QDir::toNativeSeparators(fi.absolutePath())); else url = QUrl::fromLocalFile(fi.absolutePath()); QDesktopServices::openUrl(url); }
/** * @brief Accesses items data * @param index Index of item * @param role Role * @return data */ QVariant ConcertModel::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() > m_concerts.count()) return QVariant(); if (role == Qt::UserRole) return index.row(); Concert *concert = m_concerts[index.row()]; if (index.column() == 0 && role == Qt::DisplayRole) { return Helper::appendArticle(concert->name()); } else if (index.column() == 0 && role == Qt::ToolTipRole) { if (concert->files().size() == 0) return QVariant(); return concert->files().at(0); } else if (index.column() == 1 && role == Qt::DisplayRole) { return concert->folderName(); } else if (role == Qt::UserRole+1) { return concert->controller()->infoLoaded(); } else if (role == Qt::UserRole+2) { return concert->hasChanged(); } else if (role == Qt::UserRole+3) { return concert->syncNeeded(); /* } else if (role == Qt::ForegroundRole) { if (concert->hasChanged()) return QColor(255, 0, 0); */ } else if (role == Qt::FontRole) { if (concert->hasChanged()) { QFont font; font.setItalic(true); return font; } } else if (role == Qt::DecorationRole) { if (!concert->controller()->infoLoaded()) return m_newIcon; else if (concert->syncNeeded()) return m_syncIcon; } return QVariant(); }