7 #include <QApplication> 
   19 #include "gui/menus/fontmenus.h" 
   20 #include "gui/menus/menudelegate.h" 
   25 using namespace swift::config;
 
   28 using namespace swift::gui::menus;
 
   31 using namespace swift::gui::settings;
 
   56         Q_ASSERT_X(s, Q_FUNC_INFO, 
"Shortcut");
 
   57         filter->setObjectName(
"Filter shortcut for " + this->
objectName());
 
   62         Q_ASSERT_X(s, Q_FUNC_INFO, 
"Shortcut");
 
   68         Q_ASSERT_X(s, Q_FUNC_INFO, 
"Shortcut");
 
   74         Q_ASSERT_X(s, Q_FUNC_INFO, 
"Shortcut");
 
   75         deleteRow->setObjectName(
"Remove selected rows for " + this->
objectName());
 
   80         Q_ASSERT_X(s, Q_FUNC_INFO, 
"Shortcut");
 
   81         copy->setObjectName(
"Copy selection shortcut for " + this->
objectName());
 
   86         Q_ASSERT_X(s, Q_FUNC_INFO, 
"Shortcut");
 
  102     void CViewBaseNonTemplate::setFilterWidgetImpl(
QWidget *filterWidget)
 
  125         this->setFilterWidgetImpl(filterDialog);
 
  130             Q_ASSERT_X(s, Q_FUNC_INFO, 
"filter dialog connect");
 
  138         this->setFilterWidgetImpl(filterWidget);
 
  141             bool s = 
connect(filterWidget, &CFilterWidget::changeFilter, 
this,
 
  143             Q_ASSERT_X(s, Q_FUNC_INFO, 
"filter connect changeFilter");
 
  146             Q_ASSERT_X(s, Q_FUNC_INFO, 
"filter connect modelDataChanged");
 
  178         return this->
saveJson(selectedOnly, directory);
 
  188         if (menu && nestPreviousMenu)
 
  194         else if (!menu && nestPreviousMenu)
 
  218             ma.
addAction(CIcons::refresh16(), 
"Update", CMenuAction::pathViewUpdates(),
 
  227             ma.
addAction(CIcons::refresh16(), 
"Reload from backend", CMenuAction::pathViewUpdates(),
 
  234                 ma.
addAction(CIcons::appMappings16(), 
"Automatically display (when loaded)",
 
  235                              CMenuAction::pathViewUpdates(), { 
this, &CViewBaseNonTemplate::toggleAutoDisplay });
 
  242             ma.
addAction(CIcons::delete16(), 
"Remove selected rows", CMenuAction::pathViewAddRemove(),
 
  248             ma.
addAction(CIcons::delete16(), 
"Clear", CMenuAction::pathViewAddRemove(),
 
  262                 ma.
addAction(CIcons::filter16(), 
"Remove Filter", CMenuAction::pathViewFilter(),
 
  269             ma.
addAction(CIcons::tableRelationship16(), 
"Materialize filtered data", CMenuAction::pathViewFilter(),
 
  275             ma.
addAction(CIcons::disk16(), 
"Load from file ", CMenuAction::pathViewLoadSave(),
 
  287                 ma.
addAction(CIcons::disk16(), 
"Save selected data in file", CMenuAction::pathViewLoadSave(),
 
  303             ma.
addAction(CIcons::paste16(), 
"Paste", CMenuAction::pathViewCutPaste(),
 
  310             ma.
addAction(CIcons::copy16(), 
"Copy", CMenuAction::pathViewCutPaste(),
 
  333         if (selectedFileOrDir.
isEmpty()) { 
return; }
 
  334         const QString dir = CDirectories::fileNameToDirectory(selectedFileOrDir);
 
  336         if (!d.
exists()) { 
return; }
 
  342         CLogMessage::preformatted(msg);
 
  399             menuActions.
addAction(
"Select all", CMenuAction::pathViewSelection(), 
nullptr,
 
  405                                   CMenuAction::pathViewSelection(), 
nullptr,
 
  413                 menuActions.
addAction(
"Switch to multi selection", CMenuAction::pathViewSelection(), 
nullptr,
 
  419                 menuActions.
addAction(
"Switch to extended selection", CMenuAction::pathViewSelection(), 
nullptr,
 
  425                 menuActions.
addAction(
"Switch to single selection", CMenuAction::pathViewSelection(), 
nullptr,
 
  449             menuActions.
addAction(CIcons::resizeVertical16(), 
"Resize rows to content", CMenuAction::pathViewResize(),
 
  464         if (CBuildConfig::isLocalDeveloperDebugBuild())
 
  466             menuActions.
addAction(CIcons::tableSheet16(), 
"Display as JSON", CMenuAction::pathViewLoadSave(),
 
  470                 menuActions.
addAction(CIcons::tableSheet16(), 
"Display selected as JSON",
 
  471                                       CMenuAction::pathViewLoadSave(),
 
  477         QAction *actionInteractiveResize =
 
  478             menuActions.
addAction(CIcons::viewTile(), 
"Resize (auto)", CMenuAction::pathViewResize(), 
nullptr);
 
  481         actionInteractiveResize->
setChecked(autoResize);
 
  485         QAction *actionWordWrap = menuActions.
addAction(CIcons::viewMultiColumn(), 
"Word wrap (multiline)",
 
  486                                                         CMenuAction::pathViewResize(), 
nullptr);
 
  520         std::sort(indexes.begin(), indexes.end());
 
  527         QModelIndexList unselected;
 
  529         for (
int r = 0; r < rows; r++)
 
  532             if (selected.contains(mi)) { 
continue; }
 
  533             unselected.push_back(mi);
 
  546         for (
int r : rows) { selectedItems.
select(this->
model()->index(r, 0), this->
model()->index(r, columns)); }
 
  548         return selectedItems.
size();
 
  586         default: Q_ASSERT_X(
false, Q_FUNC_INFO, 
"wrong resize mode"); 
break;
 
  593             if (!guard) { 
return; }
 
  604                                                CFileUtils::jsonWildcardAppendix());
 
  617         return CFileUtils::appendFilePaths(dir, name);
 
  639         if (!m.
isEmpty()) { CLogMessage::preformatted(m); }
 
  644         if (this->
isEmpty()) { 
return; }
 
  647         if (!m.
isEmpty()) { CLogMessage::preformatted(m); }
 
  652         if (this->
isEmpty()) { 
return; }
 
  655         if (!m.
isEmpty()) { CLogMessage::preformatted(m); }
 
  676         Q_ASSERT_X(
verticalHeader, Q_FUNC_INFO, 
"Missing vertical header");
 
  708         using namespace std::chrono_literals;
 
  717         if (containerSizeDependent >= 0)
 
  818     void CViewBaseNonTemplate::customMenuRequested(
const QPoint &
pos)
 
  823         if (menuActions.
isEmpty()) { 
return; }
 
  824         menuActions.
toQMenu(menu, 
true);
 
  832             QMenu *dockWidgetSubMenu = menu.
addMenu(CIcons::text16(), mm);
 
  837         menu.
exec(globalPos);
 
  842     void CViewBaseNonTemplate::toggleResizeMode(
bool checked)
 
  853     void CViewBaseNonTemplate::toggleWordWrap(
bool checked)
 
  855         if (this->
wordWrap() == checked) { 
return; }
 
  864     void CViewBaseNonTemplate::toggleAutoDisplay()
 
  868         Q_ASSERT_X(a->isCheckable(), Q_FUNC_INFO, 
"object not checkable");
 
  880         selectedItems.
select(this->
model()->index(0, 0), this->
model()->index(rows, columns));
 
  896     void CViewBaseNonTemplate::removeSelectedRowsChecked()
 
  906         event->acceptProposedAction();
 
  912         event->acceptProposedAction();
 
  917         if (!
event) { 
return; }
 
  923         if (!
event) { 
return; }
 
  929         containerSize = containerSize >= 0 ? containerSize : this->
rowCount();
 
  930         const int presizeRandomElements = containerSize > 1000 ? containerSize / 100 : containerSize / 40;
 
  931         return presizeRandomElements;
 
static QWidget * mainApplicationWidget()
Main application window widget.
 
The QProgressIndicator class lets an application display a progress indicator to show that a lengthy ...
 
void centerLoadIndicator(const QPoint &middle)
Center this load indicator.
 
int startAnimation(std::chrono::milliseconds timeout=std::chrono::milliseconds(0), bool processEvents=false)
Starts the spin animation.
 
void timedOut()
Timed out.
 
void stopAnimation(int indicatorId=-1)
Stops the spin animation.
 
Using this class provides a QTableView with the overlay functionality already integrated.
 
static const QKeySequence & keyDelete()
Delete, e.g. selected rows.
 
static const QKeySequence & keySelectAll()
For selecting all.
 
static const QKeySequence & keyResizeView()
Resize view.
 
static const QKeySequence & keyDisplayFilter()
Display filter.
 
static const QKeySequence & keyClearSelection()
For deselecting all.
 
static const QKeySequence & keyCopy()
Copy.
 
static QString toParenthesisString(const QKeySequence &sequence)
As string for menus etc. Looks like "(CTRL + R)".
 
static const QKeySequence & keySaveViews()
Save in views.
 
QAbstractItemView::SelectionMode getPreferredSelection() const
Preferred selection.
 
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
 
void menuAddItems(Menu menusToAdd)
Add given menu items.
 
void setSelectionModel(QItemSelectionModel *model)
 
components::CTextEditDialog * textEditDialog()
Init text edit dialog if required and return pointer to it.
 
static constexpr int ResizeSubsetThreshold
When to use pre-sizing with random elements.
 
void rowsResizeModeToInteractive()
Init as interactive, as this allows manually resizing.
 
bool m_forceStretchLastColumnWhenResized
a small table might (few columns) fail stretching, force again
 
void hideLoadIndicator(int loadingId=-1)
Hide loading indicator.
 
void setHorizontalHeaderSectionResizeMode(QHeaderView::ResizeMode mode)
Resize mode.
 
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...
 
menus::IMenuDelegate * setCustomMenu(menus::IMenuDelegate *menu, bool nestPreviousMenu=true)
Set custom menu if applicable.
 
Menu m_menus
Default menu settings.
 
@ PresizeSubset
use a subset of the data to resize
 
@ ResizingAlways
always resize
 
@ ResizingOnce
only one time
 
@ ResizingAuto
resizing when below threshold,
 
int selectedRowCount() const
Number of selected rows.
 
virtual void resizeToContents()
Resize to contents, strategy depends on container size.
 
SelectionMode m_originalSelectionMode
Selection mode set.
 
void triggerReload()
Trigger reload from backend by signal requestUpdate();.
 
bool isCurrentlyAllowingMultipleRowSelections() const
Is the current selection mode allow multiple selection.
 
virtual int removeSelectedRows()=0
Remove selected rows.
 
int getPresizeRandomElementsSize(int containerSize=-1) const
Calculate presize count.
 
bool allowsMultipleSelectedRows() const
Allows to select multiple rows.
 
void requestNewBackendData()
Load data from backend (where it makes sense)
 
ResizeMode m_resizeMode
mode
 
virtual void removeFilter()=0
Remove filter.
 
virtual QString getRememberedLastJsonDirectory() const
JSON directory.
 
virtual void onDoubleClicked(const QModelIndex &index)=0
Index double clicked.
 
void showVerticalHeader()
Vertical header.
 
virtual void displaySelectedJsonPopup()=0
Display JSON data.
 
virtual void onClicked(const QModelIndex &index)=0
Index clicked.
 
virtual bool acceptDrop(const QMimeData *mimeData) const =0
Accept drop data?
 
void loadIndicatorVisibilityChanged(bool visible)
Load indicator's visibility has been changed.
 
int getHorizontalHeaderFontHeight() const
Horizontal font height.
 
bool m_displayAutomatically
display directly when loaded
 
QModelIndexList selectedRows() const
Selected rows if any.
 
void loadJsonAction()
Load JSON for action/menu, void return signatur.
 
void menuRemoveItems(Menu menusToRemove)
Remove given menu items.
 
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
 
virtual QModelIndexList unselectedRows() const
Unselected (not selected) rows if any.
 
RowsResizeMode m_rowResizeMode
row resize mode for row height
 
void requestUpdate()
Ask for new data from currently loaded data.
 
bool m_enabledLoadIndicator
loading indicator enabled/disabled
 
int showLoadIndicatorWithTimeout(std::chrono::milliseconds timeout=std::chrono::milliseconds { 0 }, bool processEvents=true)
Show loading indicator which can time out.
 
void saveJsonAction()
Save JSON for action/menu, void return signatur.
 
void saveSelectedJsonAction()
Save JSON for action/menu, void return signatur.
 
void resizeEvent(QResizeEvent *event)
 
QWidget * mainApplicationWindowWidget() const
Main application window widget if any.
 
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 setFilterWidget(filters::CFilterWidget *filterWidget)
Set filter widget.
 
void dragEnterEvent(QDragEnterEvent *event)
 
swift::misc::CStatusMessage showFileLoadDialog(const QString &directory={})
Show file load dialog.
 
void onModelChanged()
Underlying model changed.
 
int m_resizeAutoNthTime
with ResizeAuto, resize every n-th time
 
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)
 
std::chrono::milliseconds m_loadIndicatorTimeoutDefault
default time for timeout
 
virtual void clear()=0
Clear data.
 
virtual void onRowSelected(const QModelIndex &index)=0
Row selected.
 
void rowsResizeModeToContent()
Resize mode to content.
 
void dropEvent(QDropEvent *event)
 
virtual bool filterDialogFinished(int status)=0
Filter dialog finished.
 
QString m_saveFileName
save file name (JSON)
 
menus::CFontMenu * m_fontMenu
font menu if applicable
 
void centerLoadIndicator()
Center / re-center load indicator.
 
virtual bool isResizeConditionMet(int containerSize=-1) const
Resize or skip resize?
 
bool hasSingleSelectedRow() const
Single selected row.
 
bool hasMultipleSelectedRows() const
Multiple selected rows.
 
swift::misc::CSettingReadOnly< settings::TGeneralGui > m_guiSettings
general GUI settings
 
~CViewBaseNonTemplate()
Destructor.
 
virtual bool isEmpty() const =0
Empty?
 
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
 
virtual void presizeOrFullResizeToContents()=0
Depending on CViewBaseNonTemplate::ResizeSubsetThreshold presize or fully resize.
 
virtual void customMenu(menus::CMenuActions &menuActions)
Method creating the menu.
 
swift::misc::CStatusMessage showFileSaveDialog(bool selectedOnly, const QString &directory={})
Show file save dialog.
 
virtual void updateSortIndicator()=0
Set the sort indicator to the current sort column.
 
virtual swift::misc::CStatusMessage saveJson(bool selectedOnly=false, const QString &directory={})=0
Save JSON.
 
void rowsResizeModeBasedOnThreshold(int elements)
Set content/interactive mode based on ResizeRowsToContentThreshold.
 
void enableLoadIndicator(bool enable)
Enable loading indicator.
 
static constexpr int ResizeRowsToContentThreshold
When to use rows resizing (which is slow)
 
bool isShowingLoadIndicator
Load indicator property allows using in stylesheet.
 
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
 
int selectRows(const QSet< int > &rows)
Select given rows.
 
bool setParentDockWidgetInfoArea(swift::gui::CDockWidgetInfoArea *parentDockableWidget)
Corresponding dockable widget in info area.
 
void init()
Init default values.
 
virtual void paste()=0
Clipboard cut/copy/paste.
 
void displayFilterDialog()
Display the filter dialog.
 
menus::IMenuDelegate * m_menu
custom menu if any
 
void selectAll()
Select all rows.
 
swift::misc::CSetting< swift::misc::settings::TDirectorySettings > m_dirSettings
directory for load/save
 
void setSingleSelection()
Change selection modes.
 
menus::CMenuActions initMenuActions(MenuFlag menu)
Init menu actions.
 
virtual void copy()=0
Clipboard cut/copy/paste.
 
void setFilterDialog(filters::CFilterDialog *filterDialog)
Filter dialog.
 
components::CTextEditDialog * m_textEditDialog
text edit dialog
 
void dragLeaveEvent(QDragLeaveEvent *event)
 
void triggerReloadFromBackend()
Trigger reload from backend by signal requestNewBackendData()
 
int unselectedRowCount() const
Unselected row count.
 
@ MenuDisplayAutomatically
allow to switch display automatically
 
@ MenuClear
allow clearing the view via menu
 
@ MenuFont
font related menu (size)
 
@ MenuRefresh
allow refreshing the view via menu
 
@ MenuCut
cut (for copy/paste)
 
@ MenuCopy
copy (for copy/paste)
 
@ MenuBackend
allow to request data from backend
 
@ MenuRemoveSelectedRows
allow to remove selected rows
 
@ MenuPaste
paste (for copy/paste)
 
@ MenuMaterializeFilter
materialize filter (filtered data become model data)
 
@ MenuFilter
filter can be opened
 
@ MenuToggleSelectionMode
allow to toggle selection mode
 
bool hasSelection() const
Selection (selected rows)
 
void dragMoveEvent(QDragMoveEvent *event)
 
virtual int rowCount() const =0
Elements in container.
 
bool displayAutomatically() const
Display automatically (when models are loaded)
 
bool m_enableDeleteSelectedRows
selected rows can be deleted
 
const QFont & getHorizontalHeaderFont() const
Header (horizontal) font.
 
virtual void cut()=0
Clipboard cut/copy/paste.
 
CStatusMessage setAndSave(const T &value, qint64 timestamp=0)
Write and save in the same step. Must be called from the thread in which the owner lives.
 
T get() const
Get a copy of the current value.
 
Directories (swift data directories)
 
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
 
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
 
bool isEmpty() const
Message empty.
 
Streamable status message, e.g.
 
High level reusable GUI components.
 
Filter to search data sets.
 
Models to be used with views, mainly QTableView.
 
Views, mainly QTableView.
 
Free functions in swift::misc.
 
virtual int columnCount(const QModelIndex &parent) const const=0
 
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
 
virtual int rowCount(const QModelIndex &parent) const const=0
 
void clicked(const QModelIndex &index)
 
void doubleClicked(const QModelIndex &index)
 
virtual bool event(QEvent *event) override
 
QAbstractItemModel * model() const const
 
virtual void resizeEvent(QResizeEvent *event) override
 
void setSelectionMode(QAbstractItemView::SelectionMode mode)
 
QItemSelectionModel * selectionModel() const const
 
void setTextElideMode(Qt::TextElideMode mode)
 
void toggled(bool checked)
 
bool exists() const const
 
const QMimeData * mimeData() const const
 
void select(const QModelIndex &topLeft, const QModelIndex &bottomRight)
 
void currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
 
bool hasSelection() const const
 
virtual void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
 
QModelIndexList selectedRows(int column) const const
 
qsizetype size() const const
 
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect(const QMetaObject::Connection &connection)
 
bool isSignalConnected(const QMetaMethod &signal) const const
 
QObject * parent() const const
 
QObject * sender() const const
 
void setObjectName(QAnyStringView name)
 
QString arg(Args &&... args) const const
 
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
 
bool isEmpty() const const
 
virtual void dropEvent(QDropEvent *event) override
 
void resizeColumnsToContents()
 
void resizeRowsToContents()
 
virtual void setSelectionModel(QItemSelectionModel *selectionModel) override
 
void setWordWrap(bool on)
 
QString toString() const const