plasma: proxy QTreeWidget instead of QTreeView

much more convenient, already testing it via experimental lsof applet

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-17 05:01:27 +03:00
parent c72478ab01
commit 50a9aa403b
6 changed files with 26 additions and 50 deletions

View file

@ -466,7 +466,7 @@ install(
Plasma/ToolButton Plasma/ToolButton
Plasma/ToolTipContent Plasma/ToolTipContent
Plasma/ToolTipManager Plasma/ToolTipManager
Plasma/TreeView Plasma/TreeWidget
Plasma/CalendarWidget Plasma/CalendarWidget
Plasma/View Plasma/View
Plasma/Wallpaper Plasma/Wallpaper

View file

@ -1 +0,0 @@
#include "../../plasma/widgets/treeview.h"

View file

@ -0,0 +1 @@
#include "../../plasma/widgets/treewidget.h"

View file

@ -92,7 +92,7 @@ set(plasma_LIB_SRCS
widgets/svgwidget.cpp widgets/svgwidget.cpp
widgets/tabbar.cpp widgets/tabbar.cpp
widgets/textbrowser.cpp widgets/textbrowser.cpp
widgets/treeview.cpp widgets/treewidget.cpp
widgets/textedit.cpp widgets/textedit.cpp
widgets/calendarwidget.cpp widgets/calendarwidget.cpp
) )
@ -198,7 +198,7 @@ install(
widgets/scrollwidget.h widgets/scrollwidget.h
widgets/tabbar.h widgets/tabbar.h
widgets/textbrowser.h widgets/textbrowser.h
widgets/treeview.h widgets/treewidget.h
widgets/textedit.h widgets/textedit.h
widgets/calendarwidget.h widgets/calendarwidget.h
DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/plasma/widgets DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/plasma/widgets

View file

@ -17,10 +17,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "treeview.h" #include "treewidget.h"
#include <QTreeView> #include <QTreeWidget>
#include <QHeaderView>
#include <QScrollBar> #include <QScrollBar>
#include <kiconloader.h> #include <kiconloader.h>
@ -30,17 +29,17 @@
namespace Plasma namespace Plasma
{ {
class TreeViewPrivate class TreeWidgetPrivate
{ {
public: public:
Plasma::Style::Ptr style; Plasma::Style::Ptr style;
}; };
TreeView::TreeView(QGraphicsWidget *parent) TreeWidget::TreeWidget(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent), : QGraphicsProxyWidget(parent),
d(new TreeViewPrivate) d(new TreeWidgetPrivate)
{ {
QTreeView *native = new QTreeView(); QTreeWidget *native = new QTreeWidget();
setWidget(native); setWidget(native);
native->setWindowIcon(QIcon()); native->setWindowIcon(QIcon());
native->setAttribute(Qt::WA_NoSystemBackground); native->setAttribute(Qt::WA_NoSystemBackground);
@ -51,28 +50,18 @@ TreeView::TreeView(QGraphicsWidget *parent)
native->horizontalScrollBar()->setStyle(d->style.data()); native->horizontalScrollBar()->setStyle(d->style.data());
} }
TreeView::~TreeView() TreeWidget::~TreeWidget()
{ {
delete d; delete d;
Plasma::Style::doneWithSharedStyle(); Plasma::Style::doneWithSharedStyle();
} }
void TreeView::setModel(QAbstractItemModel *model) QTreeWidget *TreeWidget::nativeWidget() const
{ {
nativeWidget()->setModel(model); return static_cast<QTreeWidget*>(widget());
}
QAbstractItemModel *TreeView::model()
{
return nativeWidget()->model();
}
QTreeView *TreeView::nativeWidget() const
{
return static_cast<QTreeView*>(widget());
} }
} }
#include "moc_treeview.cpp" #include "moc_treewidget.cpp"

View file

@ -17,54 +17,41 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef PLASMA_TREEVIEW_H #ifndef PLASMA_TREEWIDGET_H
#define PLASMA_TREEVIEW_H #define PLASMA_TREEWIDGET_H
#include <QtGui/QGraphicsProxyWidget> #include <QtGui/QGraphicsProxyWidget>
#include <plasma/plasma_export.h> #include <plasma/plasma_export.h>
#include <QTreeView> #include <QTreeWidget>
#include <QAbstractItemModel> #include <QAbstractItemModel>
namespace Plasma namespace Plasma
{ {
class TreeViewPrivate; class TreeWidgetPrivate;
/** /**
* @class TreeView plasma/widgets/treeview.h <Plasma/Widgets/TreeView> * @class TreeWidget plasma/widgets/treewidget.h <Plasma/Widgets/TreeWidget>
* *
* @short Provides a plasma-themed QTreeView. * @short Provides a plasma-themed QTreeWidget.
*/ */
class PLASMA_EXPORT TreeView : public QGraphicsProxyWidget class PLASMA_EXPORT TreeWidget : public QGraphicsProxyWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel)
public: public:
explicit TreeView(QGraphicsWidget *parent = 0); explicit TreeWidget(QGraphicsWidget *parent = 0);
~TreeView(); ~TreeWidget();
/** /**
* Sets a model for this weather view * @return the native widget wrapped by this TreeWidget
*
* @param model the model to display
*/ */
void setModel(QAbstractItemModel *model); QTreeWidget *nativeWidget() const;
/**
* @return the model shown by this view
*/
QAbstractItemModel *model();
/**
* @return the native widget wrapped by this TreeView
*/
QTreeView *nativeWidget() const;
private: private:
TreeViewPrivate *const d; TreeWidgetPrivate *const d;
}; };
} }