From fc986529ced7c84249dca8a64592b5e938653c7a Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 27 Oct 2010 09:18:26 +0200 Subject: [PATCH] * No need for our own SourceTreeView ItemDelegate. --- src/CMakeLists.txt | 2 - src/sourcetree/sourcesmodel.cpp | 12 ++++++ src/sourcetree/sourcesmodel.h | 1 + src/sourcetree/sourcetreedelegate.cpp | 52 -------------------------- src/sourcetree/sourcetreedelegate.h | 25 ------------- src/sourcetree/sourcetreeitemwidget.ui | 4 +- src/sourcetree/sourcetreeview.cpp | 4 -- src/sourcetree/sourcetreeview.h | 2 - 8 files changed, 15 insertions(+), 87 deletions(-) delete mode 100644 src/sourcetree/sourcetreedelegate.cpp delete mode 100644 src/sourcetree/sourcetreedelegate.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ed62920c5..5f6e7904e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -114,7 +114,6 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui} sourcetree/sourcetreeitem.cpp sourcetree/sourcetreeitemwidget.cpp sourcetree/sourcetreeview.cpp - sourcetree/sourcetreedelegate.cpp topbar/topbar.cpp topbar/clearbutton.cpp @@ -231,7 +230,6 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui} sourcetree/sourcetreeitem.h sourcetree/sourcetreeitemwidget.h sourcetree/sourcetreeview.h - sourcetree/sourcetreedelegate.h topbar/topbar.h topbar/clearbutton.h diff --git a/src/sourcetree/sourcesmodel.cpp b/src/sourcetree/sourcesmodel.cpp index 521bf0323..6ff6be8fe 100644 --- a/src/sourcetree/sourcesmodel.cpp +++ b/src/sourcetree/sourcesmodel.cpp @@ -67,6 +67,18 @@ SourcesModel::flags( const QModelIndex& index ) const } +QVariant +SourcesModel::data( const QModelIndex& index, int role ) const +{ + if ( role == Qt::SizeHintRole ) + { + return QSize( 0, 18 ); + } + + return QStandardItemModel::data( index, role ); +} + + void SourcesModel::loadSources() { diff --git a/src/sourcetree/sourcesmodel.h b/src/sourcetree/sourcesmodel.h index cd5e0cab7..e39f3b11c 100644 --- a/src/sourcetree/sourcesmodel.h +++ b/src/sourcetree/sourcesmodel.h @@ -18,6 +18,7 @@ public: virtual QStringList mimeTypes() const; virtual Qt::DropActions supportedDropActions() const; virtual Qt::ItemFlags flags( const QModelIndex& index ) const; + QVariant data( const QModelIndex& index, int role ) const; bool appendItem( const Tomahawk::source_ptr& source ); bool removeItem( const Tomahawk::source_ptr& source ); diff --git a/src/sourcetree/sourcetreedelegate.cpp b/src/sourcetree/sourcetreedelegate.cpp deleted file mode 100644 index e6fae45c6..000000000 --- a/src/sourcetree/sourcetreedelegate.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "sourcetreedelegate.h" - -#include -#include - - -SourceTreeDelegate::SourceTreeDelegate( QAbstractItemView* parent ) - : QStyledItemDelegate( (QObject*)parent ) - , m_view( parent ) -{ -} - - -QWidget* -SourceTreeDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const -{ - QLineEdit* editor = new QLineEdit( parent ); - editor->setFrame( false ); - editor->setObjectName( "playlistEditor" ); - - return editor; -} - - -void -SourceTreeDelegate::updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const -{ - if ( editor->objectName() != "playlistEditor" ) - return; - - QRect r = option.rect; - r.adjust( 20, -1, -8, 1 ); - - editor->setGeometry( r ); -} - - -void -SourceTreeDelegate::setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const -{ - QLineEdit* le = static_cast( editor ); - - model->setData( index, le->text(), Qt::EditRole ); -} - - -QSize -SourceTreeDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const -{ - QSize size = QStyledItemDelegate::sizeHint( option, index ); - return size; -} diff --git a/src/sourcetree/sourcetreedelegate.h b/src/sourcetree/sourcetreedelegate.h deleted file mode 100644 index 0166f2cb3..000000000 --- a/src/sourcetree/sourcetreedelegate.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SOURCETREEDELEGATE_H -#define SOURCETREEDELEGATE_H - -#include -#include - -class SourceTreeDelegate : public QStyledItemDelegate -{ -Q_OBJECT - -public: - SourceTreeDelegate( QAbstractItemView* parent = 0 ); - -protected: - QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; - - QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const; - void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const; - void setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const; - -private: - QAbstractItemView* m_view; -}; - -#endif // SOURCETREEDELEGATE_H diff --git a/src/sourcetree/sourcetreeitemwidget.ui b/src/sourcetree/sourcetreeitemwidget.ui index 8910bcde2..0bacbbba7 100644 --- a/src/sourcetree/sourcetreeitemwidget.ui +++ b/src/sourcetree/sourcetreeitemwidget.ui @@ -6,12 +6,12 @@ 0 0 - 400 + 298 44 - + 0 0 diff --git a/src/sourcetree/sourcetreeview.cpp b/src/sourcetree/sourcetreeview.cpp index 16af2a4da..777f7becf 100644 --- a/src/sourcetree/sourcetreeview.cpp +++ b/src/sourcetree/sourcetreeview.cpp @@ -6,7 +6,6 @@ #include "playlistmanager.h" #include "sourcetreeitem.h" #include "sourcesmodel.h" -#include "sourcetreedelegate.h" #include #include @@ -36,9 +35,6 @@ SourceTreeView::SourceTreeView( QWidget* parent ) setContextMenuPolicy( Qt::CustomContextMenu ); connect( this, SIGNAL( customContextMenuRequested( const QPoint& ) ), SLOT( onCustomContextMenu( const QPoint& ) ) ); - m_delegate = new SourceTreeDelegate( this ); - setItemDelegate( m_delegate ); - m_model = new SourcesModel( this ); setModel( m_model ); diff --git a/src/sourcetree/sourcetreeview.h b/src/sourcetree/sourcetreeview.h index adc81663a..f4bfd0a45 100644 --- a/src/sourcetree/sourcetreeview.h +++ b/src/sourcetree/sourcetreeview.h @@ -9,7 +9,6 @@ class CollectionModel; class PlaylistModel; class SourcesModel; -class SourceTreeDelegate; class SourceTreeView : public QTreeView { @@ -48,7 +47,6 @@ private: CollectionModel* m_collectionModel; SourcesModel* m_model; - SourceTreeDelegate* m_delegate; QModelIndex m_contextMenuIndex; QMenu m_playlistMenu;