diff options
author | Arno <arno@disconnect.de> | 2016-09-05 04:38:59 +0200 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2016-09-05 04:38:59 +0200 |
commit | 821b07a3187b9a11b5d5678f0c3ad2f28689f9e8 (patch) | |
tree | b024668b72445ff6cddad827c119fafb9f41a19a | |
parent | 3a6e43400ff1c36269d6b7cb822b3ffe6ff58fb7 (diff) | |
download | ShemovCleaner-821b07a3187b9a11b5d5678f0c3ad2f28689f9e8.tar.gz ShemovCleaner-821b07a3187b9a11b5d5678f0c3ad2f28689f9e8.tar.bz2 ShemovCleaner-821b07a3187b9a11b5d5678f0c3ad2f28689f9e8.zip |
Use enums in TorrentWidget
Revamp gatherData() to use Enums for colums, roles and data.
-rw-r--r-- | torrentwidget.cpp | 44 | ||||
-rw-r--r-- | torrentwidget.h | 4 |
2 files changed, 27 insertions, 21 deletions
diff --git a/torrentwidget.cpp b/torrentwidget.cpp index cf866df..f7b51df 100644 --- a/torrentwidget.cpp +++ b/torrentwidget.cpp @@ -155,35 +155,37 @@ void TorrentWidget::gatherData(){ QBrush redBrush(Qt::red); QBrush greenBrush(Qt::darkGreen); foreach(QFileInfo fi, fl){ + QList<QStandardItem*> fData; + for(int i = 0; i < ColumnCount; ++i){ + QStandardItem *item = new QStandardItem; + item->setEditable(false); + fData << item; + } int result = 0; q.bindValue(":fn", fi.fileName()); q.exec(); while(q.next()){ result = q.value(0).toInt(); } - QStandardItem *i1; - QStandardItem *i2 = new QStandardItem(fi.fileName()); - i2->setEditable(false); - QStandardItem *i3 = new QStandardItem(fi.created().toString(Qt::RFC2822Date)); - i3->setEditable(false); + fData[NameColumn]->setText(fi.fileName()); + fData[NameColumn]->setData(fi.absoluteFilePath(), FullPathRole); + fData[CreatedColumn]->setText(fi.created().toString(Qt::RFC2822Date)); if(result){ - i1 = new QStandardItem(QIcon(":/huge_bra.png"), QString()); - i1->setData(1); - i2->setForeground(greenBrush); + fData[IconColumn]->setIcon(QIcon(":/huge_bra.png")); + fData[IconColumn]->setData(Present, PresentRole); + fData[NameColumn]->setForeground(greenBrush); }else{ - i1 = new QStandardItem(QIcon(":/gaping_ass.png"), QString()); - i1->setData(0); - i2->setForeground(redBrush); + fData[IconColumn]->setIcon(QIcon(":/gaping_ass.png")); + fData[IconColumn]->setData(NotPresent, PresentRole); + fData[NameColumn]->setForeground(redBrush); } - i1->setEditable(false); - i2->setData(fi.absoluteFilePath()); - root->appendRow(QList<QStandardItem*>() << i1 << i2 << i3); + root->appendRow(fData); } readHeaderData(); } void TorrentWidget::deleteFiles(){ - QModelIndexList sel = mFileView->selectionModel()->selectedRows(1); + QModelIndexList sel = mFileView->selectionModel()->selectedRows(NameColumn); if(sel.isEmpty()){ return; } @@ -192,7 +194,7 @@ void TorrentWidget::deleteFiles(){ int ctr = 0; if(res == QMessageBox::Yes){ foreach(QModelIndex i, sel){ - QString fp = i.data(Qt::UserRole + 1).toString(); + QString fp = i.data(FullPathRole).toString(); bool ok = QFile::remove(fp); if(ok){ ++ctr; @@ -209,7 +211,7 @@ void TorrentWidget::deleteFiles(){ } void TorrentWidget::moveFiles(){ - QModelIndexList sel = mFileView->selectionModel()->selectedRows(1); + QModelIndexList sel = mFileView->selectionModel()->selectedRows(NameColumn); if(sel.isEmpty()){ return; } @@ -217,7 +219,7 @@ void TorrentWidget::moveFiles(){ if(!dir.isEmpty()){ int ctr = 0; foreach(QModelIndex i, sel){ - QFileInfo fp(i.data(Qt::UserRole + 1).toString()); + QFileInfo fp(i.data(FullPathRole).toString()); QString newfn = QString("%1/%2").arg(dir).arg(fp.fileName()); bool ok = QFile::rename(fp.absoluteFilePath(), newfn); if(ok){ @@ -231,11 +233,11 @@ void TorrentWidget::moveFiles(){ } void TorrentWidget::torrentInfo(){ - QModelIndexList sel = mFileView->selectionModel()->selectedRows(1); + QModelIndexList sel = mFileView->selectionModel()->selectedRows(NameColumn); if(sel.isEmpty()){ return; } - QString fn = sel.first().data(Qt::UserRole + 1).toString(); + QString fn = sel.first().data(FullPathRole).toString(); TorrentParser p(fn, this); QList<QVariant> tData = p.parse(); tData.removeAll(QVariant()); @@ -252,7 +254,7 @@ void TorrentWidget::searchFile(){ int success = 0; for(int i = 0; i < count; ++i){ QModelIndex cur = mProxy->index(i, 1); - QString fn = cur.data(Qt::UserRole + 1).toString(); + QString fn = cur.data(FullPathRole).toString(); TorrentParser p(fn); emit statusMessage(QString(tr("parsing %1").arg(fn))); QList<QVariant> torrentData = p.parse(); diff --git a/torrentwidget.h b/torrentwidget.h index 4a354ce..aa3d977 100644 --- a/torrentwidget.h +++ b/torrentwidget.h @@ -20,6 +20,10 @@ class TorrentDisplay; class TorrentWidget : public QWidget { Q_OBJECT public: + enum CustomRoles { PresentRole = Qt::UserRole + 1, FullPathRole = Qt::UserRole + 2 }; + enum { ColumnCount = 3 }; + enum Columns { IconColumn = 0, NameColumn = 1, CreatedColumn = 2 }; + enum Present { NotPresent = 0, Present = 1 }; TorrentWidget(QWidget *parent = 0); QToolBar *toolBar() { return mToolBar; } QMenuBar *menuBar() { return mMenuBar; } |