Compare commits
No commits in common. "e773033f3bd532ac7444f16d7403864fd8c082f8" and "da05b706e4880afc63c44ed16967f6c7ce3a8335" have entirely different histories.
e773033f3b
...
da05b706e4
6 changed files with 5 additions and 76 deletions
|
@ -4,7 +4,6 @@
|
|||
#include "tree/SwayTreeModel.h"
|
||||
#include <QScreen>
|
||||
#include <QTimer>
|
||||
#include <iostream>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||
|
@ -19,9 +18,6 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
ui->treeView->setModel(model);
|
||||
ui->treeView->expandAll();
|
||||
|
||||
ui->treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
ui->treeView->selectionModel()->select(model->findFocusedWindowIndex(), QItemSelectionModel::ClearAndSelect);
|
||||
|
||||
for (int c = 0; c < model->columnCount(); ++c)
|
||||
ui->treeView->resizeColumnToContents(c);
|
||||
}
|
||||
|
@ -33,6 +29,5 @@ MainWindow::~MainWindow() {
|
|||
}
|
||||
|
||||
void MainWindow::update() {
|
||||
std::cout << ui->treeView->currentIndex().parent().row() << "\n";
|
||||
// model->update();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
template<class T>
|
||||
class AbstractTreeModel : public QAbstractItemModel {
|
||||
static_assert(std::is_base_of<AbstractTreeNode<T>, T>::value,
|
||||
"Tree node subject class is not derived from AbstractTreeNode");
|
||||
"Tree model subject class is not derived from AbstractTreeNode");
|
||||
|
||||
public:
|
||||
Q_DISABLE_COPY_MOVE(AbstractTreeModel)
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
|
||||
explicit AbstractTreeNode(T *parent = nullptr) : parent(parent) {}
|
||||
|
||||
[[nodiscard]] T *parentItem() const { return parent; };
|
||||
[[nodiscard]] T *parentItem() { return parent; };
|
||||
|
||||
[[nodiscard]] size_t childCount() const { return children.size(); };
|
||||
|
||||
|
@ -31,7 +31,7 @@ public:
|
|||
|
||||
[[nodiscard]] virtual int columnCount() const = 0;
|
||||
|
||||
[[nodiscard]] int row() const {
|
||||
[[nodiscard]] int row() {
|
||||
if (parent == nullptr)
|
||||
return 0;
|
||||
const auto it = std::find_if(parent->children.cbegin(), parent->children.cend(),
|
||||
|
@ -46,7 +46,7 @@ public:
|
|||
|
||||
void appendChild(std::unique_ptr<T> &child) { children.push_back(std::move(child)); }
|
||||
|
||||
[[nodiscard]] T *findChild(std::function<bool(const T &)> test) const {
|
||||
[[nodiscard]] T* findChild(std::function<bool(const T &)> test) {
|
||||
|
||||
for (int i = 0; i < childCount(); ++i) {
|
||||
auto* c = child(i);
|
||||
|
@ -56,29 +56,6 @@ public:
|
|||
return nullptr;
|
||||
};
|
||||
|
||||
[[nodiscard]] const T *findChildRecursive(std::function<bool(const T *)> test) const {
|
||||
if (test((const T *) this))
|
||||
return (const T*) this;
|
||||
|
||||
for (int i = 0; i < childCount(); ++i) {
|
||||
auto *c = child(i);
|
||||
const T *r = c->findChildRecursive(test);
|
||||
if (r != nullptr)
|
||||
return r;
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
[[nodiscard]] const T *findParentRecursive(std::function<bool(const T *)> test) const {
|
||||
if (test((const T *) this))
|
||||
return (const T*) this;
|
||||
|
||||
if (parent == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return this->findParentRecursive(test);
|
||||
};
|
||||
|
||||
void removeChild(int i) {
|
||||
if (i >= 0 && i < childCount()) {
|
||||
children.erase(std::next(children.begin(), i));
|
||||
|
|
|
@ -3,18 +3,3 @@
|
|||
//
|
||||
|
||||
#include "SwayTreeModel.h"
|
||||
|
||||
QModelIndex SwayTreeModel::findFocusedWindowIndex() const {
|
||||
std::vector<int> indices;
|
||||
for (const auto *head = getRoot()->findFocused(); head != nullptr; head = head->parentItem()) {
|
||||
indices.insert(indices.cbegin(), head->row());
|
||||
}
|
||||
|
||||
// weirdness, idk... ask QT
|
||||
QModelIndex idx = this->index(indices.size() < 2 ? 0 : indices[1], 0);
|
||||
for (int i = 2; i < indices.size(); ++i) {
|
||||
idx = this->index(indices[i], 0, idx);
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
|
|
@ -42,9 +42,6 @@ public:
|
|||
};
|
||||
|
||||
|
||||
[[nodiscard]] QModelIndex findFocusedWindowIndex() const;
|
||||
|
||||
|
||||
private:
|
||||
SwayTreeNode * rootItem;
|
||||
};
|
||||
|
|
|
@ -149,32 +149,6 @@ public:
|
|||
[[nodiscard]] QVariant headerData(int column) const override;
|
||||
|
||||
[[nodiscard]] int columnCount() const override { return 1; };
|
||||
|
||||
[[nodiscard]] const SwayTreeNode *findFocused() const {
|
||||
std::function<bool(const SwayTreeNode *)> focused = [](const SwayTreeNode *testNode) {
|
||||
return testNode->node.focused;
|
||||
};
|
||||
return this->findChildRecursive(focused);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline const SwayTreeNode *findRoot() const {
|
||||
return this->findParentRecursive(matchNodeType(NodeType::root));
|
||||
}
|
||||
|
||||
[[nodiscard]] inline const SwayTreeNode *findOutput() const {
|
||||
return this->findParentRecursive(matchNodeType(NodeType::output));
|
||||
}
|
||||
|
||||
[[nodiscard]] inline const SwayTreeNode *findWorkspace() const {
|
||||
return this->findParentRecursive(matchNodeType(NodeType::workspace));
|
||||
}
|
||||
|
||||
private:
|
||||
[[nodiscard]] static std::function<bool(const SwayTreeNode *)> matchNodeType(const NodeType::NodeType type) {
|
||||
return [type](const SwayTreeNode *testNode) {
|
||||
return testNode->node.type == type;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue