swift
Loading...
Searching...
No Matches
viewbase.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_GUI_VIEWBASE_H
7#define SWIFT_GUI_VIEWBASE_H
8
9#include <memory>
10
11#include <QAbstractItemView>
12#include <QFlags>
13#include <QHeaderView>
14#include <QJsonDocument>
15#include <QJsonObject>
16#include <QMap>
17#include <QModelIndexList>
18#include <QObject>
19#include <QString>
20#include <QTableView>
21#include <Qt>
22#include <QtGlobal>
23
25#include "gui/menus/menuaction.h"
30#include "gui/swiftguiexport.h"
31#include "misc/directories.h"
33#include "misc/propertyindex.h"
35#include "misc/statusmessage.h"
36#include "misc/variant.h"
37
38class QDragEnterEvent;
39class QDragLeaveEvent;
40class QDragMoveEvent;
41class QFont;
43class QMimeData;
44class QModelIndex;
45class QPaintEvent;
46class QPoint;
47class QShowEvent;
48class QTabWidget;
49
50namespace swift::misc
51{
52 class CWorker;
53}
54namespace swift::gui
55{
57 class CLoadIndicator;
58
59 namespace menus
60 {
61 class IMenuDelegate;
62 class CFontMenu;
63 } // namespace menus
64
65 namespace models
66 {
67 class CColumns;
68 }
69
70 namespace filters
71 {
72 class CFilterDialog;
73 class CFilterWidget;
74 } // namespace filters
75
76 namespace components
77 {
78 class CTextEditDialog;
79 }
80
81 namespace views
82 {
87 {
89
92
93 friend class CViewBaseItemDelegate;
94 friend class CViewBaseProxyStyle;
95
96 public:
108
111 {
112 Interactive,
113 Content
114 };
115
118 {
120 MenuClear = 1 << 0,
122 MenuRefresh = 1 << 2,
123 MenuBackend = 1 << 3,
126 MenuFilter = 1 << 5,
128 MenuSave = 1 << 7,
129 MenuLoad = 1 << 8,
131 MenuOrderable = 1 << 10,
132 MenuCopy = 1 << 11,
133 MenuPaste = 1 << 12,
134 MenuCut = 1 << 13,
135 MenuFont = 1 << 14,
136 MenuLoadAndSave = MenuLoad | MenuSave,
139 MenuDefaultDbViews = MenuToggleSelectionMode | MenuBackend | MenuFont,
140 // special menus, should be in derived classes, but enums cannot be inherited
141 // maybe shifted in the future to elsewhere
146 };
147 Q_DECLARE_FLAGS(Menu, MenuFlag)
148
149
150 static constexpr int ASyncRowsCountThreshold = 50;
151
153 static constexpr int ResizeSubsetThreshold = 250;
154
157 static constexpr int ResizeRowsToContentThreshold = 20;
158
160 virtual void clear() = 0;
161
163 virtual bool isEmpty() const = 0;
164
166 virtual int rowCount() const = 0;
167
169 virtual bool isOrderable() const = 0;
170
172 virtual bool setSorting(const swift::misc::CPropertyIndex &propertyIndex,
173 Qt::SortOrder order = Qt::AscendingOrder) = 0;
174
176 virtual void sortByPropertyIndex(const swift::misc::CPropertyIndex &propertyIndex,
177 Qt::SortOrder order = Qt::AscendingOrder) = 0;
178
180 virtual void setNoSorting() = 0;
181
183 virtual swift::misc::CPropertyIndex getSortProperty() const = 0;
184
186 virtual int getSortColumn() const = 0;
187
189 virtual bool hasValidSortColumn() const = 0;
190
192 virtual bool endsWithEmptyColumn() const = 0;
193
195 virtual Qt::SortOrder getSortOrder() const = 0;
196
198 virtual void allowDragDrop(bool allowDrag, bool allowDrop, bool allowDropJsonFile = false) = 0;
199
201 virtual bool isDropAllowed() const = 0;
202
204 virtual bool acceptDrop(const QMimeData *mimeData) const = 0;
205
207 bool setParentDockWidgetInfoArea(swift::gui::CDockWidgetInfoArea *parentDockableWidget) override;
208
211
213 void setResizeMode(ResizeMode mode) { m_resizeMode = mode; }
214
216 void setAutoResizeFrequency(int updateEveryNthTime) { m_resizeAutoNthTime = updateEveryNthTime; }
217
220
222 void setDisplayAutomatically(bool automatically) { m_displayAutomatically = automatically; }
223
226 {
227 Q_ASSERT(this->horizontalHeader());
228 return this->horizontalHeader()->font();
229 }
230
232 int getHorizontalHeaderFontHeight() const;
233
235 bool hasSelection() const;
236
238 QModelIndexList selectedRows() const;
239
241 virtual QModelIndexList unselectedRows() const;
242
244 int selectRows(const QSet<int> &rows);
245
247 int selectedRowCount() const;
248
250 int unselectedRowCount() const;
251
253 bool hasSingleSelectedRow() const;
254
256 bool hasMultipleSelectedRows() const;
257
259 bool allowsMultipleSelectedRows() const;
260
262 bool isCurrentlyAllowingMultipleRowSelections() const;
263
265 void setFilterDialog(filters::CFilterDialog *filterDialog);
266
269
271 void setFilterWidget(filters::CFilterWidget *filterWidget);
272
274 menus::IMenuDelegate *setCustomMenu(menus::IMenuDelegate *menu, bool nestPreviousMenu = true);
275
277 void enableLoadIndicator(bool enable);
278
280 bool isShowingLoadIndicator() const;
281
283 void acceptClickSelection(bool accept) { m_acceptClickSelection = accept; }
284
287
289 void acceptRowSelection(bool accept) { m_acceptRowSelection = accept; }
290
292 void menuRemoveItems(Menu menusToRemove);
293
295 void menuAddItems(Menu menusToAdd);
296
298 void setMenu(Menu menuItems) { m_menus = menuItems; }
299
301 Menu getMenu() const { return m_menus; }
302
304 void setSelectionModel(QItemSelectionModel *model) override;
305
307 QWidget *mainApplicationWindowWidget() const;
308
310 swift::misc::CStatusMessage showFileLoadDialog(const QString &directory = {});
311
313 swift::misc::CStatusMessage showFileSaveDialog(bool selectedOnly, const QString &directory = {});
314
316 void setSaveFileName(const QString &saveName) { m_saveFileName = saveName; }
317
320
323
327 void setForceColumnsToMaxSize(bool force) { this->setWordWrap(!force); }
328
330 void setHorizontalHeaderSectionResizeMode(QHeaderView::ResizeMode mode);
331
334 {
335 m_dirSettingsIndex = directoryIndex;
336 }
337
338 signals:
341
344
347
350
352 void modelDataChanged(int count, bool withFilter);
353
355 void modelDataChangedDigest(int count, bool withFilter);
356
359
361 void objectChanged(const swift::misc::CVariant &object, const swift::misc::CPropertyIndex &changedIndex);
362
365
368
371
373 void objectsDeleted(const swift::misc::CVariant &objectContainer);
374
377
378 public slots:
380 virtual void resizeToContents();
381
383 virtual void fullResizeToContents();
384
387
390
394
396 void rowsResizeModeBasedOnThreshold(int elements);
397
402 int showLoadIndicator(int containerSizeDependent = -1,
403 std::chrono::milliseconds timeout = std::chrono::milliseconds { 0 },
404 bool processEvents = true);
405
407 int showLoadIndicatorWithTimeout(std::chrono::milliseconds timeout = std::chrono::milliseconds { 0 },
408 bool processEvents = true);
409
411 void onModelChanged();
412
414 void hideLoadIndicator(int loadingId = -1);
415
418
420 virtual int removeSelectedRows() = 0;
421
423 virtual void clearHighlighting() = 0;
424
426 virtual void materializeFilter() = 0;
427
428 protected:
431
434
438 virtual void customMenu(menus::CMenuActions &menuActions);
439
443 void resizeEvent(QResizeEvent *event) override;
444
446 void dragEnterEvent(QDragEnterEvent *event) override;
447
449 void dragMoveEvent(QDragMoveEvent *event) override;
450
452 void dragLeaveEvent(QDragLeaveEvent *event) override;
453
455 void dropEvent(QDropEvent *event) override;
457
461
466 virtual int performUpdateContainer(const swift::misc::CVariant &variant, bool sort, bool resize) = 0;
467
469 virtual bool reachedResizeThreshold(int containerSize = -1) const = 0;
470
472 virtual bool isResizeConditionMet(int containerSize = -1) const;
473
475 int getPresizeRandomElementsSize(int containerSize = -1) const;
476
478 void centerLoadIndicator();
479
481 void init();
482
484 QString getFileDialogFileName(bool load) const;
485
488
490 virtual void updateSortIndicator() = 0;
491
493 virtual void mouseOverCallback(const QModelIndex &index, bool mouseOver) = 0;
494
496 virtual void drawDropIndicator(bool indicator) = 0;
497
499 void saveJsonAction();
500
503
505 virtual void displayJsonPopup() = 0;
506
508 virtual void displaySelectedJsonPopup() = 0;
509
511 void loadJsonAction();
512
515
517 void displayFilterDialog();
518
520 void settingsChanged();
521
523 void selectAll() override;
524
527 void setMultiSelection();
529 void setSingleSelection();
531
534 virtual void rememberLastJsonDirectory(const QString &selectedFileOrDir);
535
539
542 virtual void copy() = 0;
543 virtual void cut() = 0;
544 virtual void paste() = 0;
546
548 virtual void onClicked(const QModelIndex &index) = 0;
549
551 virtual void onDoubleClicked(const QModelIndex &index) = 0;
552
554 virtual void onRowSelected(const QModelIndex &index) = 0;
555
557 virtual swift::misc::CStatusMessage loadJson(const QString &directory = {}) = 0;
558
560 virtual swift::misc::CStatusMessage saveJson(bool selectedOnly = false, const QString &directory = {}) = 0;
561
563 void triggerReload();
564
566 void triggerReloadFromBackend();
567
569 virtual void removeFilter() = 0;
570
572 void showVerticalHeader();
573
575 virtual bool filterDialogFinished(int status) = 0;
576
578 virtual bool filterWidgetChangedFilter(bool enabled) = 0;
579
582
589 std::chrono::milliseconds m_loadIndicatorTimeoutDefault { 30 * 1000 };
591 true;
595 bool m_acceptRowSelection = false;
599 bool m_dropIndicator = false;
603 Menu m_menus = MenuDefault;
611 IndexDirLastViewJsonOrDefault;
619
620 private:
622 void removeSelectedRowsChecked();
623
625 void toggleAutoDisplay();
626
628 void customMenuRequested(const QPoint &pos);
629
631 void onLoadIndicatorTimedOut();
632
634 void toggleResizeMode(bool checked);
635
637 void toggleWordWrap(bool checked);
638
641 void setFilterWidgetImpl(QWidget *filterWidget);
642 };
643 Q_DECLARE_OPERATORS_FOR_FLAGS(swift::gui::views::CViewBaseNonTemplate::Menu)
644
645
646 template <class T>
647 class CViewBase : public CViewBaseNonTemplate, public models::ISelectionModel<typename T::ContainerType>
648 {
649 // I cannot use Q_OBJECT here, because: Template classes are not supported by Q_OBJECT
650 // and I cannot declare slots as SLOT because I have no Q_OBJECT macro
651
652 public:
654 using ModelClass = T;
655
657 using ContainerType = typename T::ContainerType;
658
660 using ObjectType = typename T::ObjectType;
661
663 ~CViewBase() override
664 {
665 if (m_model)
666 {
667 m_model->markDestroyed();
668 }
669 }
670
673
675 const ModelClass *derivedModel() const { return m_model; }
676
678 const models::CColumns &getColumns() const { return this->derivedModel()->getColumns(); }
679
682 int updateContainer(const ContainerType &container, bool sort = true, bool resize = true);
683
686 bool resize = true);
687
689 void updateContainerMaybeAsync(const ContainerType &container, bool sort = true, bool resize = true);
690
692 void insert(const ObjectType &value, bool resize = true);
693
695 void insert(const ContainerType &container, bool resize = true);
696
698 void push_back(const ObjectType &value, bool resize = true);
699
701 void push_back(const ContainerType &container, bool resize = true);
702
704 const ObjectType &at(const QModelIndex &index) const;
705
707 const ContainerType &container() const;
708
711
713 int rowOf(const ObjectType &obj) const;
714
716 const ContainerType &containerOrFilteredContainer(bool *filtered = nullptr) const;
717
720
722 void selectObjects(const ContainerType &selectedObjects) override;
723
725 ContainerType selectedObjects() const override;
726
728 ContainerType unselectedObjects() const override;
730
733
735 int updateSelected(const swift::misc::CVariant &variant, const swift::misc::CPropertyIndex &index);
736
739
742
744 template <class K0, class V0, class... KeysValues>
745 int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
746 {
747 if (this->rowCount() < 1)
748 {
749 return 0;
750 }
752 int r = cp.removeIf(k0, v0, keysValues...);
753 if (r < 1)
754 {
755 return 0;
756 }
758 return r;
759 }
760
762 template <class K1, class V1>
763 void replaceOrAdd(K1 key1, V1 value1, const ObjectType &replacement)
764 {
766 cp.replaceOrAdd(key1, value1, replacement);
768 }
769
772
774 int removeSelectedRows() override;
775
777 void presizeOrFullResizeToContents() override;
778
780 void clearHighlighting() override;
781
783 void materializeFilter() override;
785
788
790 void clear() override;
791
793 int rowCount() const override;
794
796 bool isEmpty() const override;
797
799 bool isOrderable() const override;
800
802 void allowDragDrop(bool allowDrag, bool allowDrop, bool allowDropJsonFile = false) override;
803
805 bool isDropAllowed() const override;
806
808 void dropEvent(QDropEvent *event) override;
809
811 bool acceptDrop(const QMimeData *mimeData) const override;
812
814 bool setSorting(const swift::misc::CPropertyIndex &propertyIndex,
815 Qt::SortOrder order = Qt::AscendingOrder) override;
816
818 void sortByPropertyIndex(const swift::misc::CPropertyIndex &propertyIndex,
819 Qt::SortOrder order = Qt::AscendingOrder) override;
820
822 void setNoSorting() override { m_model->setNoSorting(); }
823
825 swift::misc::CPropertyIndex getSortProperty() const override { return m_model->getSortProperty(); }
826
828 int getSortColumn() const override { return m_model->getSortColumn(); }
829
831 bool hasValidSortColumn() const override { return m_model->hasValidSortColumn(); }
832
834 bool endsWithEmptyColumn() const override { return m_model->endsWithEmptyColumn(); }
835
837 Qt::SortOrder getSortOrder() const override { return m_model->getSortOrder(); }
839
841 void sort();
842
844 void resort();
845
847 int columnCount() const;
848
850 QJsonObject toJson(bool selectedOnly = false) const;
851
854 bool selectedOnly = false) const;
855
857 virtual void setObjectName(const QString &name);
858
860 void takeFilterOwnership(std::unique_ptr<models::IModelFilter<ContainerType>> &filter);
861
863 bool hasFilter() const;
864
866 void addContainerTypesAsDropTypes(bool objectType = true, bool containerType = true);
867
869 void initAsOrderable();
870
873 {
874 Q_ASSERT(m_model);
875 m_model->setDropActions(dropActions);
876 }
877
879 void setTabWidgetViewText(QTabWidget *tw, int index);
880
884
885 protected:
886 ModelClass *m_model = nullptr;
887
890
892 void setSortIndicator();
893
895 void standardInit(ModelClass *model = nullptr);
896
899
901 bool reachedResizeThreshold(int containrerSize = -1) const override;
902
904 void performModeBasedResizeToContent() override;
905
907 int performUpdateContainer(const swift::misc::CVariant &variant, bool sort, bool resize) override;
908
910 void updateSortIndicator() override;
911
913 void mouseOverCallback(const QModelIndex &index, bool mouseOver) override;
914
916 void drawDropIndicator(bool indicator) override;
917
919 void copy() override;
920
922 void cut() override;
923
925 void paste() override;
926
928 void displayJsonPopup() override { this->displayContainerAsJsonPopup(false); }
929
932
934 bool filterDialogFinished(int status) override;
935
937 bool filterWidgetChangedFilter(bool enabled) override;
938
940 void removeFilter() override;
942
945
948
951 virtual void jsonLoadedAndModelUpdated(const ContainerType &data);
952
954 void customMenu(menus::CMenuActions &menuActions) override;
955
957 swift::misc::CStatusMessage loadJsonFile(const QString &fileName) override;
958
960 virtual void displayContainerAsJsonPopup(bool selectedOnly);
961
964
966 void onClicked(const QModelIndex &index) override;
967
969 void onDoubleClicked(const QModelIndex &index) override;
970
972 void onRowSelected(const QModelIndex &index) override;
973
975 swift::misc::CStatusMessage loadJson(const QString &directory = {}) override;
976
978 swift::misc::CStatusMessage saveJson(bool selectedOnly = false, const QString &directory = {}) override;
980 };
981 } // namespace views
982} // namespace swift::gui
983#endif // SWIFT_GUI_VIEWBASE_H
Specialized class for dock widgets serving as info area.
CEnableForDockWidgetInfoArea(CDockWidgetInfoArea *parentInfoArea=nullptr)
Constructor.
The QProgressIndicator class lets an application display a progress indicator to show that a lengthy ...
COverlayMessagesTableView(QWidget *parent=nullptr)
Constructor.
Base for filter dialog.
Base for filter dialog.
Standard font (size, style) menus. Can be used as nested menu or via getActions added manually.
Definition fontmenus.h:21
Bunch of CMenuAction objects.
Definition menuaction.h:384
Interface to implement a custom menu.
Header data for a table.
Definition columns.h:160
Model filter interface.
Definition modelfilter.h:21
Allow to get and select objects.
void sort()
Sort if columns or order changed.
Definition viewbase.cpp:550
ContainerType unselectedObjects() const
Unselected objects.
Definition viewbase.cpp:283
bool filterDialogFinished(int status)
Filter dialog finished.
Definition viewbase.cpp:987
int rowOf(const ObjectType &obj) const
The row of the given object.
Definition viewbase.cpp:243
void cut()
Clipboard cut/copy/paste.
Definition viewbase.cpp:944
int performUpdateContainer(const swift::misc::CVariant &variant, bool sort, bool resize)
Helper method with template free signature.
Definition viewbase.cpp:725
void standardInit(ModelClass *model=nullptr)
Standard initialization.
Definition viewbase.cpp:665
swift::misc::CStatusMessage loadJsonFile(const QString &fileName)
Method creating the menu.
Definition viewbase.cpp:798
void initAsOrderable()
Init so items can be ordered, includes enabling drag and drop.
Definition viewbase.cpp:616
bool acceptDrop(const QMimeData *mimeData) const
Accept drop data?
Definition viewbase.cpp:529
QList< int > rowsOf(const ContainerType &container) const
The rows of the given objects.
Definition viewbase.cpp:228
void removeFilter()
Remove filter.
Definition viewbase.cpp:591
void onRowSelected(const QModelIndex &index)
Row selected.
void setTabWidgetViewText(QTabWidget *tw, int index)
Set a tab widget text based on row count, filter etc.
Definition viewbase.cpp:626
swift::misc::CStatusMessage loadJson(const QString &directory={})
Load JSON.
Definition viewbase.cpp:895
void allowDragDrop(bool allowDrag, bool allowDrop, bool allowDropJsonFile=false)
Allow to drag and/or drop value objects.
Definition viewbase.cpp:495
void clearHighlighting()
Clear any highlighted objects.
Definition viewbase.cpp:435
bool isEmpty() const
Empty?
Definition viewbase.cpp:481
const models::CColumns & getColumns() const
The columns.
Definition viewbase.h:678
void updateContainerMaybeAsync(const ContainerType &container, bool sort=true, bool resize=true)
Based on size call sync / async update.
Definition viewbase.cpp:120
void insert(const ObjectType &value, bool resize=true)
Insert.
Definition viewbase.cpp:138
ContainerType selectedObjects() const
Selected objects.
Definition viewbase.cpp:267
swift::misc::CStatusMessage saveJson(bool selectedOnly=false, const QString &directory={})
Save JSON.
Definition viewbase.cpp:904
swift::misc::CPropertyIndex getSortProperty() const
Sorted by property.
Definition viewbase.h:825
ModelClass * m_model
corresponding model
Definition viewbase.h:886
void setSortIndicator()
Set the search indicator based on model.
Definition viewbase.cpp:655
int rowCount() const
Elements in container.
Definition viewbase.cpp:467
const ObjectType & at(const QModelIndex &index) const
Value object at.
Definition viewbase.cpp:214
void setDropActions(Qt::DropActions dropActions)
Drop actions.
Definition viewbase.h:872
void clear()
Clear data.
Definition viewbase.cpp:459
void displayJsonPopup()
Display JSON data.
Definition viewbase.h:928
typename T::ObjectType ObjectType
Model container element type.
Definition viewbase.h:660
void sortByPropertyIndex(const swift::misc::CPropertyIndex &propertyIndex, Qt::SortOrder order=Qt::AscendingOrder)
Sort by index.
Definition viewbase.cpp:544
bool filterWidgetChangedFilter(bool enabled)
Filter changed in filter widget.
Definition viewbase.cpp:994
virtual void setObjectName(const QString &name)
Set own name and the model's name.
Definition viewbase.cpp:576
void push_back(const ObjectType &value, bool resize=true)
Push back.
Definition viewbase.cpp:176
int columnCount() const
Column count.
Definition viewbase.cpp:474
virtual swift::misc::CStatusMessage validateLoadedJsonData(const ContainerType &data) const
Verify JSON data loaded in swift::gui::views::CViewBaseNonTemplate::loadJson.
Definition viewbase.cpp:771
bool reachedResizeThreshold(int containrerSize=-1) const
Skip resizing because of size?
Definition viewbase.cpp:700
QString toJsonString(QJsonDocument::JsonFormat format=QJsonDocument::Indented, bool selectedOnly=false) const
Convert to JSON string.
Definition viewbase.cpp:569
virtual swift::misc::CStatusMessage modifyLoadedJsonData(ContainerType &data) const
Modify JSON data loaded in swift::gui::views::CViewBaseNonTemplate::loadJson.
Definition viewbase.cpp:763
void selectObjects(const ContainerType &selectedObjects)
Select.
Definition viewbase.cpp:757
void onDoubleClicked(const QModelIndex &index)
Index double clicked.
void setPercentageColumnWidths()
Set the widths based on the column percentages.
Definition viewbase.cpp:639
void displaySelectedJsonPopup()
Display JSON data.
Definition viewbase.h:931
bool endsWithEmptyColumn() const
Using void column at the end?
Definition viewbase.h:834
CViewBase(QWidget *parent, ModelClass *model=nullptr)
Constructor.
Definition viewbase.cpp:31
virtual void displayContainerAsJsonPopup(bool selectedOnly)
Display the container as JSON popup.
Definition viewbase.cpp:884
void performModeBasedResizeToContent()
Perform resizing (no presizing) / non slot method for template.
Definition viewbase.cpp:710
bool hasFilter() const
Has filter set?
Definition viewbase.cpp:597
Qt::SortOrder getSortOrder() const
Get sort order.
Definition viewbase.h:837
int removeSelectedRows()
Remove selected rows.
Definition viewbase.cpp:380
bool isDropAllowed() const
Drop allowed?
Definition viewbase.cpp:508
swift::misc::CWorker * updateContainerAsync(const ContainerType &container, bool sort=true, bool resize=true)
Update whole container in background.
Definition viewbase.cpp:95
void resort()
Resort ("forced sorting").
Definition viewbase.cpp:556
void onClicked(const QModelIndex &index)
Remove filter.
virtual void jsonLoadedAndModelUpdated(const ContainerType &data)
In swift::gui::views::CViewBaseNonTemplate::loadJson the view has been updated because of loaded JSON...
Definition viewbase.cpp:779
const ModelClass * derivedModel() const
Model.
Definition viewbase.h:675
ObjectType selectedObject() const
Selected object (or default).
Definition viewbase.cpp:373
const ContainerType & container() const
Access to container.
Definition viewbase.cpp:221
int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
Remove elements matching some particular key/value pair(s).
Definition viewbase.h:745
typename T::ContainerType ContainerType
Model container type.
Definition viewbase.h:657
QJsonObject toJson(bool selectedOnly=false) const
Convert to JSON.
Definition viewbase.cpp:562
void replaceOrAdd(K1 key1, V1 value1, const ObjectType &replacement)
Replace elements matching the given element. If there is no match, push the new element on the end.
Definition viewbase.h:763
void materializeFilter()
Materialize filter.
Definition viewbase.cpp:442
void presizeOrFullResizeToContents()
Depending on CViewBaseNonTemplate::ResizeSubsetThreshold presize or fully resize.
Definition viewbase.cpp:414
int getSortColumn() const
Get sort column property index.
Definition viewbase.h:828
const ContainerType & containerOrFilteredContainer(bool *filtered=nullptr) const
Full container or cached filtered container as approproiate.
Definition viewbase.cpp:260
bool setSorting(const swift::misc::CPropertyIndex &propertyIndex, Qt::SortOrder order=Qt::AscendingOrder)
Sorting.
Definition viewbase.cpp:537
void mouseOverCallback(const QModelIndex &index, bool mouseOver)
From delegate indicating we are in mouse over state.
Definition viewbase.cpp:743
void takeFilterOwnership(std::unique_ptr< models::IModelFilter< ContainerType > > &filter)
Set filter and take ownership, any previously set filter will be destroyed.
Definition viewbase.cpp:585
void drawDropIndicator(bool indicator)
Draw drop indicator.
Definition viewbase.cpp:751
ModelClass * derivedModel()
Model.
Definition viewbase.h:672
void copy()
Clipboard cut/copy/paste.
Definition viewbase.cpp:922
int updateSelected(const swift::misc::CVariant &variant, const swift::misc::CPropertyIndex &index)
Update selected objects.
Definition viewbase.cpp:366
void setNoSorting()
Disable sorting.
Definition viewbase.h:822
bool hasValidSortColumn() const
Has valid sort column?
Definition viewbase.h:831
void updateSortIndicator()
Set the sort indicator to the current sort column.
Definition viewbase.cpp:732
void addContainerTypesAsDropTypes(bool objectType=true, bool containerType=true)
Add the object and container type as accepted drop types CDropBase::addAcceptedMetaTypeId.
Definition viewbase.cpp:603
void customMenu(menus::CMenuActions &menuActions)
Method creating the menu.
Definition viewbase.cpp:785
void dropEvent(QDropEvent *event)
Definition viewbase.cpp:515
ObjectType firstSelectedOrDefaultObject() const
First selected, the only one, or default.
Definition viewbase.cpp:299
int updateContainer(const ContainerType &container, bool sort=true, bool resize=true)
Update whole container.
Definition viewbase.cpp:41
bool isOrderable() const
Is the corresponding model orderable, swift::misc::models::CListModelBaseNonTemplate::isOrderable.
Definition viewbase.cpp:488
void paste()
Clipboard cut/copy/paste.
Definition viewbase.cpp:955
virtual bool filterWidgetChangedFilter(bool enabled)=0
Filter changed in filter widget.
QString getFileDialogFileName(bool load) const
Default file for load/save operations.
QWidget * m_filterWidget
filter widget or dialog
Definition viewbase.h:602
components::CTextEditDialog * textEditDialog()
Init text edit dialog if required and return pointer to it.
virtual void drawDropIndicator(bool indicator)=0
Draw drop indicator.
static constexpr int ResizeSubsetThreshold
When to use pre-sizing with random elements.
Definition viewbase.h:153
void rowsResizeModeToInteractive()
Init as interactive, as this allows manually resizing.
bool m_acceptRowSelection
selection changed
Definition viewbase.h:595
bool m_forceStretchLastColumnWhenResized
a small table might (few columns) fail stretching, force again
Definition viewbase.h:590
void hideLoadIndicator(int loadingId=-1)
Hide loading indicator.
void setAllowCacheFileFormatJson(bool allow)
Enable/disable cache file format to be loaded as JSON.
Definition viewbase.h:322
virtual bool reachedResizeThreshold(int containerSize=-1) const =0
Skip resizing because of size?
swift::misc::CDirectories::ColumnIndex m_dirSettingsIndex
allows to set more specialized directories //!< remember last JSON directory, having this member allo...
Definition viewbase.h:610
void hideLoadIndicatorForced()
Parameterless version of hideLoadIndicator.
Definition viewbase.h:417
Menu m_menus
Default menu settings.
Definition viewbase.h:603
ResizeMode
Resize mode, when to resize rows / columns.
Definition viewbase.h:100
@ PresizeSubset
use a subset of the data to resize
Definition viewbase.h:104
@ ResizingAuto
resizing when below threshold,
Definition viewbase.h:101
virtual void resizeToContents()
Resize to contents, strategy depends on container size.
SelectionMode m_originalSelectionMode
Selection mode set.
Definition viewbase.h:585
virtual int removeSelectedRows()=0
Remove selected rows.
virtual void mouseOverCallback(const QModelIndex &index, bool mouseOver)=0
From delegate indicating we are in mouse over state.
int getPresizeRandomElementsSize(int containerSize=-1) const
Calculate presize count.
virtual Qt::SortOrder getSortOrder() const =0
Get sort order.
void acceptDoubleClickSelection(bool accept)
Accept double click selection.
Definition viewbase.h:286
void requestNewBackendData()
Load data from backend (where it makes sense).
virtual int performUpdateContainer(const swift::misc::CVariant &variant, bool sort, bool resize)=0
Helper method with template free signature.
virtual void removeFilter()=0
Remove filter.
virtual void setNoSorting()=0
Disable sorting.
virtual QString getRememberedLastJsonDirectory() const
JSON directory.
virtual void onDoubleClicked(const QModelIndex &index)=0
Index double clicked.
virtual void displaySelectedJsonPopup()=0
Display JSON data.
virtual void clearHighlighting()=0
Clear any highlighted objects.
virtual void onClicked(const QModelIndex &index)=0
Index clicked.
bool allowCacheFileFormatJson() const
Allow cache file JSON to be loaded.
Definition viewbase.h:319
RowsResizeMode
How rows are resized, makes sense when.
Definition viewbase.h:111
virtual bool acceptDrop(const QMimeData *mimeData) const =0
Accept drop data?
void loadIndicatorVisibilityChanged(bool visible)
Load indicator's visibility has been changed.
void setSaveFileName(const QString &saveName)
Save file name (optional).
Definition viewbase.h:316
bool m_displayAutomatically
display directly when loaded
Definition viewbase.h:597
void modelChanged()
Model bas been changed (means data in view have been changed).
virtual bool hasValidSortColumn() const =0
Has valid sort column?
void loadJsonAction()
Load JSON for action/menu, void return signatur.
ResizeMode getResizeMode() const
Resize mode.
Definition viewbase.h:210
void setSettingsDirectoryIndex(swift::misc::CDirectories::ColumnIndex directoryIndex)
Index of the directory we "remember".
Definition viewbase.h:333
int m_skipResizeThreshold
when to skip resize (rows count)
Definition viewbase.h:587
virtual void rememberLastJsonDirectory(const QString &selectedFileOrDir)
JSON directory.
virtual swift::misc::CStatusMessage loadJson(const QString &directory={})=0
Load JSON.
CLoadIndicator * m_loadIndicator
load indicator if needed
Definition viewbase.h:606
virtual int getSortColumn() const =0
Get sort column property index.
RowsResizeMode m_rowResizeMode
row resize mode for row height
Definition viewbase.h:584
void requestUpdate()
Ask for new data from currently loaded data.
void setResizeMode(ResizeMode mode)
Set resize mode.
Definition viewbase.h:213
virtual swift::misc::CStatusMessage loadJsonFile(const QString &filePath)=0
Load JSON file.
virtual bool endsWithEmptyColumn() const =0
Using void column at the end?
void setDisplayAutomatically(bool automatically)
Display automatically (when models are loaded).
Definition viewbase.h:222
bool m_enabledLoadIndicator
loading indicator enabled/disabled
Definition viewbase.h:593
const QFont & getHorizontalHeaderFont() const
Header (horizontal) font.
Definition viewbase.h:225
void saveJsonAction()
Save JSON for action/menu, void return signatur.
void saveSelectedJsonAction()
Save JSON for action/menu, void return signatur.
void objectChanged(const swift::misc::CVariant &object, const swift::misc::CPropertyIndex &changedIndex)
Single object was changed in model.
virtual void allowDragDrop(bool allowDrag, bool allowDrop, bool allowDropJsonFile=false)=0
Allow to drag and/or drop value objects.
virtual void displayJsonPopup()=0
Display JSON data.
virtual void performModeBasedResizeToContent()=0
Perform resizing (no presizing) / non slot method for template.
virtual void materializeFilter()=0
Materialize filter.
void jsonLoadCompleted(const swift::misc::CStatusMessage &msg)
JSON data load from disk completed, the swift::misc::CStatusMessage represents the success.
int m_resizeAutoNthTime
with ResizeAuto, resize every n-th time
Definition viewbase.h:588
virtual void fullResizeToContents()
Full resizing to content, might be slow.
void setMultiSelection()
Change selection modes.
QMap< MenuFlag, menus::CMenuActions > m_menuFlagActions
initialized actions for menu flag (enum)
Definition viewbase.h:608
std::chrono::milliseconds m_loadIndicatorTimeoutDefault
default time for timeout
Definition viewbase.h:589
virtual void clear()=0
Clear data.
bool m_acceptDoubleClickSelection
double clicked
Definition viewbase.h:596
virtual void sortByPropertyIndex(const swift::misc::CPropertyIndex &propertyIndex, Qt::SortOrder order=Qt::AscendingOrder)=0
Sort by index.
virtual void onRowSelected(const QModelIndex &index)=0
Row selected.
void rowsResizeModeToContent()
Resize mode to content.
virtual bool filterDialogFinished(int status)=0
Filter dialog finished.
QString m_saveFileName
save file name (JSON)
Definition viewbase.h:609
menus::CFontMenu * m_fontMenu
font menu if applicable
Definition viewbase.h:605
void centerLoadIndicator()
Center / re-center load indicator.
virtual bool isResizeConditionMet(int containerSize=-1) const
Resize or skip resize?
virtual bool isDropAllowed() const =0
Drop allowed?
swift::misc::CSettingReadOnly< settings::TGeneralGui > m_guiSettings
general GUI settings
Definition viewbase.h:616
void objectSelected(const swift::misc::CVariant &object)
Object has been selected.
virtual bool isEmpty() const =0
Empty?
void modelDataChangedDigest(int count, bool withFilter)
Model data changed,.
int showLoadIndicator(int containerSizeDependent=-1, std::chrono::milliseconds timeout=std::chrono::milliseconds { 0 }, bool processEvents=true)
Show loading indicator.
int m_resizeCount
flag / counter, how many resize activities
Definition viewbase.h:586
virtual swift::misc::CPropertyIndex getSortProperty() const =0
Sorted by property.
virtual void presizeOrFullResizeToContents()=0
Depending on CViewBaseNonTemplate::ResizeSubsetThreshold presize or fully resize.
virtual void customMenu(menus::CMenuActions &menuActions)
Method creating the menu.
static constexpr int ASyncRowsCountThreshold
When (row count) to use asynchronous updates.
Definition viewbase.h:150
bool m_allowCacheFileJson
allow Cache format JSON to be loaded
Definition viewbase.h:601
virtual void updateSortIndicator()=0
Set the sort indicator to the current sort column.
void setAutoResizeFrequency(int updateEveryNthTime)
In.
Definition viewbase.h:216
virtual swift::misc::CStatusMessage saveJson(bool selectedOnly=false, const QString &directory={})=0
Save JSON.
virtual bool setSorting(const swift::misc::CPropertyIndex &propertyIndex, Qt::SortOrder order=Qt::AscendingOrder)=0
Sorting.
void setMenu(Menu menuItems)
Set menu items.
Definition viewbase.h:298
QWidget * getFilterWidget() const
Filter widget if any.
Definition viewbase.h:268
void rowsResizeModeBasedOnThreshold(int elements)
Set content/interactive mode based on ResizeRowsToContentThreshold.
void asyncUpdateFinished()
Asynchronous update finished.
void setForceColumnsToMaxSize(bool force)
Force that columns are extended to full viewport width. Workaround as of https://stackoverflow....
Definition viewbase.h:327
static constexpr int ResizeRowsToContentThreshold
When to use rows resizing (which is slow).
Definition viewbase.h:157
bool isShowingLoadIndicator
Load indicator property allows using in stylesheet.
Definition viewbase.h:91
void settingsChanged()
Settings have been changed.
void setExtendedSelection()
Change selection modes.
void modelDataChanged(int count, bool withFilter)
Model data changed.
bool m_showingLoadIndicator
showing loading indicator
Definition viewbase.h:592
bool setParentDockWidgetInfoArea(swift::gui::CDockWidgetInfoArea *parentDockableWidget)
Corresponding dockable widget in info area.
virtual void paste()=0
Clipboard cut/copy/paste.
void displayFilterDialog()
Display the filter dialog.
menus::IMenuDelegate * m_menu
custom menu if any
Definition viewbase.h:604
swift::misc::CSetting< swift::misc::settings::TDirectorySettings > m_dirSettings
directory for load/save
Definition viewbase.h:613
void setSingleSelection()
Change selection modes.
menus::CMenuActions initMenuActions(MenuFlag menu)
Init menu actions.
bool m_forceColumnsToMaxSize
force that columns are extended to full viewport width
Definition viewbase.h:600
virtual void copy()=0
Clipboard cut/copy/paste.
components::CTextEditDialog * m_textEditDialog
text edit dialog
Definition viewbase.h:607
void objectsDeleted(const swift::misc::CVariant &objectContainer)
Objects deleted from model.
@ MenuDisplayAutomatically
allow to switch display automatically
Definition viewbase.h:124
@ MenuClear
allow clearing the view via menu
Definition viewbase.h:120
@ MenuFont
font related menu (size)
Definition viewbase.h:135
@ MenuDisplayAutomaticallyAndRefresh
should come together
Definition viewbase.h:125
@ MenuRefresh
allow refreshing the view via menu
Definition viewbase.h:122
@ MenuOrderable
items can be ordered (if container is swift::misc::IOrderableList
Definition viewbase.h:131
@ MenuHighlightStashed
highlight stashed models
Definition viewbase.h:142
@ MenuCopy
copy (for copy/paste)
Definition viewbase.h:132
@ MenuBackend
allow to request data from backend
Definition viewbase.h:123
@ MenuRemoveSelectedRows
allow to remove selected rows
Definition viewbase.h:121
@ MenuPaste
paste (for copy/paste)
Definition viewbase.h:133
@ MenuMaterializeFilter
materialize filter (filtered data become model data)
Definition viewbase.h:127
@ MenuToggleSelectionMode
allow to toggle selection mode
Definition viewbase.h:130
void acceptClickSelection(bool accept)
Accept click selection.
Definition viewbase.h:283
void acceptRowSelection(bool accept)
Accept row selection.
Definition viewbase.h:289
void objectDoubleClicked(const swift::misc::CVariant &object)
Object has been double clicked.
virtual int rowCount() const =0
Elements in container.
bool displayAutomatically() const
Display automatically (when models are loaded).
Definition viewbase.h:219
bool m_enableDeleteSelectedRows
selected rows can be deleted
Definition viewbase.h:598
CViewBaseNonTemplate(QWidget *parent)
Constructor.
virtual void cut()=0
Clipboard cut/copy/paste.
virtual bool isOrderable() const =0
Is the corresponding model orderable, swift::misc::models::CListModelBaseNonTemplate::isOrderable.
void objectClicked(const swift::misc::CVariant &object)
Object has been clicked.
ColumnIndex
Properties by index.
Definition directories.h:29
Specialized value object compliant map for variants, based on indexes.
Class template for accessing a specific value in the CSettingsCache.
Class template for accessing a specific value in the CSettingsCache.
Streamable status message, e.g.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition variant.h:69
Class for doing some arbitrary parcel of work in its own thread.
Definition worker.h:230
High level reusable GUI components.
Filter to search data sets.
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
GUI related classes.
Free functions in swift::misc.
virtual bool event(QEvent *event) override
QAbstractItemModel * model() const const
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
QObject * parent() const const
typedef DropActions
SortOrder
QHeaderView * horizontalHeader() const const
void setWordWrap(bool on)
QWidget(QWidget *parent, Qt::WindowFlags f)
void resize(const QSize &)
#define SWIFT_GUI_EXPORT
Export a class or function from the library.