swift
Loading...
Searching...
No Matches
aircraftcategorytreeview.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QAction>
7#include <QMenu>
8#include <QModelIndex>
9
10#include "gui/menus/menuaction.h"
12#include "misc/icons.h"
13
14using namespace swift::misc;
15using namespace swift::misc::aviation;
16using namespace swift::gui::models;
17
18namespace swift::gui::views
19{
29
31 {
32 if (!this->categoryModel())
33 {
34 return;
35 }
36 this->categoryModel()->updateContainer(categories);
37
40 // using Qt::QueuedConnection seems to fix for expand all
41 // also this->expandToDepth(0) seems to work
42 this->expandAll();
43 }
44
46 {
47 if (!this->categoryModel())
48 {
49 return;
50 }
51 this->categoryModel()->clear();
52 }
53
54 void CAircraftCategoryTreeView::fullResizeToContents() { m_dsFullResize.inputSignal(); }
55
57 {
58 if (this->categoryModel())
59 {
60 this->categoryModel()->setColumns(columns);
61 }
62 }
63
64 void CAircraftCategoryTreeView::fullResizeToContentsImpl()
65 {
66 if (this->isEmpty())
67 {
68 return;
69 }
70 const int cc = this->categoryModel()->columnCount();
71 for (int c = 0; c < cc; c++)
72 {
74 }
75 }
76
77 bool CAircraftCategoryTreeView::isEmpty() const { return this->categoryModel()->rowCount() < 1; }
78
79 const CAircraftCategoryTreeModel *CAircraftCategoryTreeView::categoryModel() const
80 {
82 }
83
84 CAircraftCategoryTreeModel *CAircraftCategoryTreeView::categoryModel()
85 {
87 }
88
89 CAircraftCategory CAircraftCategoryTreeView::selectedObject() const
90 {
91 const CAircraftCategoryTreeModel *model = this->categoryModel();
92 if (!model)
93 {
94 return {};
95 }
96 return model->container().frontOrDefault();
97 }
98
99 void CAircraftCategoryTreeView::onExpanded(const QModelIndex &index)
100 {
101 Q_UNUSED(index);
102 this->fullResizeToContents();
103 }
104
105 void CAircraftCategoryTreeView::customMenu(const QPoint &point)
106 {
107 if (!this->categoryModel())
108 {
109 return;
110 }
111 if (this->categoryModel()->container().isEmpty())
112 {
113 return;
114 }
115
116 auto *menu = new QMenu(this); // menu
117 auto *resize = new QAction(CIcons::resize16(), "Resize", this);
118 connect(resize, &QAction::triggered, this, &CAircraftCategoryTreeView::fullResizeToContentsImpl);
119
120 menu->addAction(resize);
121 menu->popup(this->viewport()->mapToGlobal(point));
122 }
123} // namespace swift::gui::views
Header data for a table.
Definition columns.h:160
CAircraftCategoryTreeView(QWidget *parent=nullptr)
Constructor.
void updateContainer(const swift::misc::aviation::CAircraftCategoryList &categories)
Update container.
void setColumns(const models::CColumns &columns)
Set columns.
static const QPixmap & resize16()
Resize.
Value object for aircraft categories.
Value object encapsulating a list of ICAO codes.
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
Free functions in swift::misc.
QAbstractItemModel * model() const const
QWidget * viewport() const const
void triggered(bool checked)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
T qobject_cast(QObject *object)
virtual int columnCount(const QModelIndex &parent) const const override
QueuedConnection
CustomContextMenu
QTreeView(QWidget *parent)
void expandAll()
void expanded(const QModelIndex &index)
void resizeColumnToContents(int column)
virtual void setModel(QAbstractItemModel *model) override
QWidget(QWidget *parent, Qt::WindowFlags f)
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
void customContextMenuRequested(const QPoint &pos)
QPoint mapToGlobal(const QPoint &pos) const const
void resize(const QSize &)