qt: update ReadableBrowser

This commit is contained in:
Jussi Kuokkanen 2019-11-17 15:18:45 +02:00
parent ce7ee06bb1
commit ae6ef819f6
2 changed files with 15 additions and 19 deletions

View File

@ -6,9 +6,14 @@
ReadableBrowser::ReadableBrowser(ReadableManager *readableManager, QWidget *parent) : QWidget(parent) { ReadableBrowser::ReadableBrowser(ReadableManager *readableManager, QWidget *parent) : QWidget(parent) {
m_mainLayout = new QVBoxLayout; m_mainLayout = new QVBoxLayout;
m_readableTreeView = new QTreeView; m_readableTreeView = new ReadableTreeView;
m_browserModel = new QStandardItemModel; // Forward ReadableTreeView::itemDragStarted to ReadableWidget
connect(m_readableTreeView, &ReadableTreeView::itemDragStarted, [=]() {
emit itemDragStarted();
});
m_browserModel = new ReadableItemModel;
m_readableManager = readableManager; m_readableManager = readableManager;
@ -17,13 +22,12 @@ ReadableBrowser::ReadableBrowser(ReadableManager *readableManager, QWidget *pare
m_mainLayout->addWidget(m_readableTreeView); m_mainLayout->addWidget(m_readableTreeView);
setLayout(m_mainLayout); setLayout(m_mainLayout);
} }
ReadableBrowser::~ReadableBrowser() { ReadableBrowser::~ReadableBrowser() {
} }
void ReadableBrowser::genBrowserTree(QTreeView *treeView, QStandardItemModel *itemModel) { void ReadableBrowser::genBrowserTree(ReadableTreeView *treeView, QStandardItemModel *itemModel) {
QStandardItem *parentItem = itemModel->invisibleRootItem(); QStandardItem *parentItem = itemModel->invisibleRootItem();
std::function<void(tc_readable_node_t*, QStandardItem*)> traverse; std::function<void(tc_readable_node_t*, QStandardItem*)> traverse;
@ -74,11 +78,3 @@ QStandardItem *ReadableBrowser::addBrowserItem(tc_readable_node_t* node, QStanda
return item; return item;
} }
void ReadableBrowser::mousePressEvent(QMouseEvent *event) {
/*if (event->button() == Qt::LeftButton) {
QDrag *drag = new QDrag(this);
Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
qDebug() << drag->mimeData();
}*/
}

View File

@ -7,7 +7,9 @@
#include <QDropEvent> #include <QDropEvent>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QTreeView> #include <QTreeView>
#include <QStandardItemModel>
#include <ReadableItemModel.h>
#include <ReadableTreeView.h>
class ReadableBrowser : public QWidget { class ReadableBrowser : public QWidget {
Q_OBJECT Q_OBJECT
@ -15,16 +17,14 @@ public:
ReadableBrowser(ReadableManager *readableManager, QWidget *parent = nullptr); ReadableBrowser(ReadableManager *readableManager, QWidget *parent = nullptr);
~ReadableBrowser(); ~ReadableBrowser();
signals: signals:
void itemDragStarted(QString &text); void itemDragStarted();
private: private:
ReadableManager *m_readableManager; // ReadableManager instance that the browser is generated from ReadableManager *m_readableManager; // ReadableManager instance that the browser is generated from
QVBoxLayout *m_mainLayout; QVBoxLayout *m_mainLayout;
QTreeView *m_readableTreeView; ReadableTreeView *m_readableTreeView;
QStandardItemModel *m_browserModel; ReadableItemModel *m_browserModel;
void genBrowserTree(QTreeView *treeView, QStandardItemModel *itemModel); void genBrowserTree(ReadableTreeView *treeView, QStandardItemModel *itemModel);
QStandardItem *addBrowserItem(tc_readable_node_t* node, QStandardItem *parent); // Return a newly created item that is a child of 'parent' QStandardItem *addBrowserItem(tc_readable_node_t* node, QStandardItem *parent); // Return a newly created item that is a child of 'parent'
void mousePressEvent(QMouseEvent *event); // Start the drag event for an item
}; };