diff --git a/src/base/scanfoldersmodel.cpp b/src/base/scanfoldersmodel.cpp index 25a61e4ba..a001c30b8 100644 --- a/src/base/scanfoldersmodel.cpp +++ b/src/base/scanfoldersmodel.cpp @@ -122,11 +122,21 @@ QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const value = Utils::Fs::toNativePath(pathData->watchPath); break; case DOWNLOAD: - if (role == Qt::DisplayRole) { + if (role == Qt::UserRole) { value = pathData->downloadType; } - else if ((role == Qt::UserRole) && (pathData->downloadType == CUSTOM_LOCATION)) { - value = pathData->downloadPath; + else if (role == Qt::DisplayRole) { + switch (pathData->downloadType) { + case DOWNLOAD_IN_WATCH_FOLDER: + value = tr("Watch Folder"); + break; + case DEFAULT_LOCATION: + value = tr("Default Folder"); + break; + case CUSTOM_LOCATION: + value = pathData->downloadPath; + break; + } } break; } @@ -178,7 +188,7 @@ bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value, || (index.column() != DOWNLOAD)) return false; - if (role == Qt::DisplayRole) { + if (role == Qt::UserRole) { PathType type = static_cast(value.toInt()); if (type == CUSTOM_LOCATION) return false; @@ -187,7 +197,7 @@ bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value, m_pathList[index.row()]->downloadPath.clear(); emit dataChanged(index, index); } - else if (role == Qt::UserRole) { + else if (role == Qt::DisplayRole) { QString path = value.toString(); if (path.isEmpty()) // means we didn't pass CUSTOM_LOCATION type return false; diff --git a/src/gui/options.ui b/src/gui/options.ui index 684033f21..a57baf0c4 100644 --- a/src/gui/options.ui +++ b/src/gui/options.ui @@ -745,6 +745,9 @@ 80 + + false + @@ -2724,7 +2727,7 @@ 0 0 - 89 + 98 28 diff --git a/src/gui/scanfoldersdelegate.cpp b/src/gui/scanfoldersdelegate.cpp index 20e276c5e..6de8dcce7 100644 --- a/src/gui/scanfoldersdelegate.cpp +++ b/src/gui/scanfoldersdelegate.cpp @@ -46,50 +46,14 @@ ScanFoldersDelegate::ScanFoldersDelegate(QObject *parent, QTreeView *foldersView { } -void ScanFoldersDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - painter->save(); - - switch(index.column()) { - case ScanFoldersModel::WATCH: - QItemDelegate::paint(painter, option, index); - break; - - case ScanFoldersModel::DOWNLOAD: { - QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option); - QItemDelegate::drawBackground(painter, opt, index); - QString text; - - switch (index.data().toInt()) { - case ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER: - text = tr("Watch Folder"); - break; - case ScanFoldersModel::DEFAULT_LOCATION: - text = tr("Default Folder"); - break; - case ScanFoldersModel::CUSTOM_LOCATION: - text = index.data(Qt::UserRole).toString(); - break; - } - QItemDelegate::drawDisplay(painter, opt, option.rect, text); - break; - } - - default: - break; - } - - painter->restore(); -} - void ScanFoldersDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QComboBox *combobox = static_cast(editor); // Set combobox index - if (index.data().toInt() == ScanFoldersModel::CUSTOM_LOCATION) + if (index.data(Qt::UserRole).toInt() == ScanFoldersModel::CUSTOM_LOCATION) combobox->setCurrentIndex(4); // '4' is the index of the item after the separator in the QComboBox menu else - combobox->setCurrentIndex(index.data().toInt()); + combobox->setCurrentIndex(index.data(Qt::UserRole).toInt()); } QWidget *ScanFoldersDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const @@ -102,9 +66,9 @@ QWidget *ScanFoldersDelegate::createEditor(QWidget *parent, const QStyleOptionVi editor->addItem(tr("Watch Folder")); editor->addItem(tr("Default Folder")); editor->addItem(tr("Browse...")); - if (index.data().toInt() == ScanFoldersModel::CUSTOM_LOCATION) { + if (index.data(Qt::UserRole).toInt() == ScanFoldersModel::CUSTOM_LOCATION) { editor->insertSeparator(3); - editor->addItem(index.data(Qt::UserRole).toString()); + editor->addItem(index.data().toString()); } connect(editor, SIGNAL(currentIndexChanged(int)), this, SLOT(comboboxIndexChanged(int))); @@ -128,7 +92,7 @@ void ScanFoldersDelegate::setModelData(QWidget *editor, QAbstractItemModel *mode switch (value) { case ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER: case ScanFoldersModel::DEFAULT_LOCATION: - model->setData(index, value, Qt::DisplayRole); + model->setData(index, value, Qt::UserRole); break; case ScanFoldersModel::CUSTOM_LOCATION: @@ -136,10 +100,10 @@ void ScanFoldersDelegate::setModelData(QWidget *editor, QAbstractItemModel *mode index, QFileDialog::getExistingDirectory( 0, tr("Choose save path"), - index.data().toInt() == ScanFoldersModel::CUSTOM_LOCATION ? - index.data(Qt::UserRole).toString() : + index.data(Qt::UserRole).toInt() == ScanFoldersModel::CUSTOM_LOCATION ? + index.data().toString() : Preferences::instance()->getSavePath()), - Qt::UserRole); + Qt::DisplayRole); break; default: diff --git a/src/gui/scanfoldersdelegate.h b/src/gui/scanfoldersdelegate.h index c427735c7..c9b1af98b 100644 --- a/src/gui/scanfoldersdelegate.h +++ b/src/gui/scanfoldersdelegate.h @@ -53,7 +53,6 @@ private slots: private: void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const; - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; void setEditorData(QWidget *editor, const QModelIndex &index) const; QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const;