itom
Loading...
Searching...
No Matches
workspaceWidget.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom.
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 itom is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17 General Public Licence for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21*********************************************************************** */
22
23#ifndef WORKSPACEWIDGET_H
24#define WORKSPACEWIDGET_H
25
26#ifndef Q_MOC_RUN
27 #include "python/pythonWrapper.h"
28#endif
29
30#include "../common/sharedStructures.h"
31#include "../common/sharedStructuresQt.h"
32#include "../global.h"
33
34#include "../python/pythonWorkspace.h"
35
36#include <qhash.h>
37#include <qmimedata.h>
38#include <qpixmap.h>
39#include <qset.h>
40#include <qtreewidget.h>
41
42namespace ito {
43
45/*
46The variable names of a WorkspaceWidget are usually strings, however these strings can
47also be numbers (e.g. children of a list or tuple). In this case, it is desired that numbers
48are compared to numbers based on their number value and not the text, such that 1 < 2 < 10 instead
49of "1" < "10" < "2".
50*/
51class WorkspaceTreeItem : public QTreeWidgetItem
52{
53public:
54 explicit WorkspaceTreeItem(int type = Type) : QTreeWidgetItem(type)
55 {
56 }
57 explicit WorkspaceTreeItem(const QStringList& strings, int type = Type) :
58 QTreeWidgetItem(strings, type)
59 {
60 }
61 explicit WorkspaceTreeItem(QTreeWidget* view, int type = Type) : QTreeWidgetItem(view, type)
62 {
63 }
64 WorkspaceTreeItem(QTreeWidget* view, const QStringList& strings, int type = Type) :
65 QTreeWidgetItem(strings, type)
66 {
67 }
68 WorkspaceTreeItem(QTreeWidget* view, QTreeWidgetItem* after, int type = Type) :
69 QTreeWidgetItem(view, after, type)
70 {
71 }
72 explicit WorkspaceTreeItem(QTreeWidgetItem* parent, int type = Type) :
73 QTreeWidgetItem(parent, type)
74 {
75 }
76 WorkspaceTreeItem(QTreeWidgetItem* parent, const QStringList& strings, int type = Type) :
77 QTreeWidgetItem(parent, strings, type)
78 {
79 }
80 WorkspaceTreeItem(QTreeWidgetItem* parent, QTreeWidgetItem* after, int type = Type) :
81 QTreeWidgetItem(parent, after, type)
82 {
83 }
84 WorkspaceTreeItem(const QTreeWidgetItem& other) : QTreeWidgetItem(other)
85 {
86 }
87
88 virtual ~WorkspaceTreeItem()
89 {
90 }
91
93 virtual bool operator<(const QTreeWidgetItem& other) const
94 {
95 int column = treeWidget()->sortColumn();
96 QString thisText = text(column);
97 QString otherText = other.text(column);
98
99 bool ok;
100 float a = thisText.toFloat(&ok);
101
102 if (ok)
103 {
104 float b = otherText.toFloat(&ok);
105 if (ok)
106 {
107 return a < b;
108 }
109 }
110
111 return thisText.localeAwareCompare(otherText) < 0;
112 }
113};
114
116class WorkspaceWidget : public QTreeWidget
117{
118 Q_OBJECT
119public:
120 WorkspaceWidget(bool globalNotLocal, QWidget* parent = NULL);
122
123 int numberOfSelectedItems(bool ableToBeRenamed = false) const;
124 int numberOfSelectedMainItems() const;
125 inline ito::PyWorkspaceContainer* getWorkspaceContainer()
126 {
127 return m_workspaceContainer;
128 }
129
131 {
132 RoleFullName = Qt::UserRole +
133 1,
135 RoleCompatibleTypes = Qt::UserRole + 2,
136 RoleType = Qt::UserRole + 3
137 };
138
139 QString getPythonReadableName(const QTreeWidgetItem* item) const;
140 QAction* m_displayItemDetails;
141
142protected:
143 QStringList mimeTypes() const;
144#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
145 QMimeData* mimeData(const QList<QTreeWidgetItem*> items) const;
146#else
147 QMimeData* mimeData(const QList<QTreeWidgetItem*>& items) const;
148#endif
149 void startDrag(Qt::DropActions supportedActions);
150
151private:
152 void updateView(
153 const QHash<QString, ito::PyWorkspaceItem*>& items,
154 const QString& baseName,
155 QTreeWidgetItem* parent = nullptr);
156 void recursivelyDeleteHash(QTreeWidgetItem* item);
157 void recursivelyDeleteHash(const QString& fullBaseName);
158
161 bool m_globalNotLocal;
162 QHash<QString, QTreeWidgetItem*> m_itemHash;
163 ito::PyWorkspaceContainer* m_workspaceContainer;
164
165 QPixmap m_dragPixmap;
166 Qt::DropActions supportedDragActions() const;
167
168signals:
169
170public slots:
171 void workspaceContainerUpdated(
172 PyWorkspaceItem* rootItem, QString fullNameRoot, QStringList recentlyDeletedFullNames);
173 void displayItemDetails();
174
175private slots:
177 QTreeWidgetItem* item, int column);
178 void itemExpanded(QTreeWidgetItem* item);
179 void itemCollapsed(QTreeWidgetItem* item);
180};
181
182} // end namespace ito
183
184#endif
Definition pythonWorkspace.h:92
every item in the workspace is represented by one PyWorkspaceItem
Definition pythonWorkspace.h:64
tiny derivative of QTreeWidgetItem, that overwrites the comparison operator
Definition workspaceWidget.h:52
virtual bool operator<(const QTreeWidgetItem &other) const
overwritten operator for better number comparison
Definition workspaceWidget.h:93
major class WorkspaceWidget to show a tree widget for the global and local workspace toolbox
Definition workspaceWidget.h:117
WorkspaceWidget(bool globalNotLocal, QWidget *parent=NULL)
constructor
Definition workspaceWidget.cpp:55
void itemDoubleClicked(QTreeWidgetItem *item, int column)
slot, invoked if item is double-clicked
Definition workspaceWidget.cpp:509
WorkspaceRole
Definition workspaceWidget.h:131
@ RoleFullName
Definition workspaceWidget.h:132
~WorkspaceWidget()
destructor
Definition workspaceWidget.cpp:147
Definition apiFunctionsGraph.cpp:40