diff --git a/src/blackgui/views/viewbase.cpp b/src/blackgui/views/viewbase.cpp index a84c41a90..702c6676e 100644 --- a/src/blackgui/views/viewbase.cpp +++ b/src/blackgui/views/viewbase.cpp @@ -786,7 +786,7 @@ namespace BlackGui } template - CStatusMessage CViewBase::ps_loadJson(const QString &directory) + CStatusMessage CViewBase::loadJson(const QString &directory) { const QString fileName = QFileDialog::getOpenFileName(nullptr, tr("Load data file"), @@ -796,7 +796,7 @@ namespace BlackGui } template - CStatusMessage CViewBase::ps_saveJson(bool selectedOnly, const QString &directory) + CStatusMessage CViewBase::saveJson(bool selectedOnly, const QString &directory) { const QString fileName = QFileDialog::getSaveFileName(nullptr, tr("Save data file"), @@ -899,27 +899,27 @@ namespace BlackGui } template - void CViewBase::ps_clicked(const QModelIndex &index) + void CViewBase::onClicked(const QModelIndex &index) { if (!m_acceptClickSelection) { return; } if (!index.isValid()) { return; } - emit objectClicked(CVariant::fromValue(at(index))); + emit this->objectClicked(CVariant::fromValue(at(index))); } template - void CViewBase::ps_doubleClicked(const QModelIndex &index) + void CViewBase::onDoubleClicked(const QModelIndex &index) { if (!m_acceptDoubleClickSelection) { return; } if (!index.isValid()) { return; } - emit objectDoubleClicked(CVariant::fromValue(at(index))); + emit this->objectDoubleClicked(CVariant::fromValue(at(index))); } template - void CViewBase::ps_rowSelected(const QModelIndex &index) + void CViewBase::onRowSelected(const QModelIndex &index) { if (!m_acceptRowSelection) { return; } if (!index.isValid()) { return; } - emit objectSelected(CVariant::fromValue(at(index))); + emit this->objectSelected(CVariant::fromValue(at(index))); } } // namespace } // namespace diff --git a/src/blackgui/views/viewbase.h b/src/blackgui/views/viewbase.h index 70b5616eb..4a0935493 100644 --- a/src/blackgui/views/viewbase.h +++ b/src/blackgui/views/viewbase.h @@ -517,6 +517,21 @@ namespace BlackGui virtual void paste() = 0; //! @} + //! Index clicked + virtual void onClicked(const QModelIndex &index) = 0; + + //! Index double clicked + virtual void onDoubleClicked(const QModelIndex &index) = 0; + + //! Row selected + virtual void onRowSelected(const QModelIndex &index) = 0; + + //! Load JSON + virtual BlackMisc::CStatusMessage loadJson(const QString &directory = {}) = 0; + + //! Save JSON + virtual BlackMisc::CStatusMessage saveJson(bool selectedOnly = false, const QString &directory = {}) = 0; + //! Trigger reload from backend by signal requestUpdate(); void triggerReload(); @@ -565,28 +580,6 @@ namespace BlackGui BlackMisc::CSetting m_dirSettings { this }; //!< directory for load/save BlackMisc::CSettingReadOnly m_guiSettings { this, &CViewBaseNonTemplate::settingsChanged }; //!< general GUI settings - protected slots: - //! Index clicked - virtual void ps_clicked(const QModelIndex &index) = 0; - - //! Index double clicked - virtual void ps_doubleClicked(const QModelIndex &index) = 0; - - //! Row selected - virtual void ps_rowSelected(const QModelIndex &index) = 0; - - //! Load JSON - virtual BlackMisc::CStatusMessage ps_loadJson(const QString &directory = {}) = 0; - - //! Save JSON - virtual BlackMisc::CStatusMessage ps_saveJson(bool selectedOnly = false, const QString &directory = {}) = 0; - - // ------------ slots of CViewDbObjects ---------------- - // need to be declared here and overridden, as this is the only part with valid Q_OBJECT - - //! Highlight DB data - virtual void ps_toggleHighlightDbData() {} - private: //! Remove selected rows if enabled void removeSelectedRowsChecked(); @@ -597,8 +590,8 @@ namespace BlackGui //! Custom menu was requested void customMenuRequested(const QPoint &pos); - //! Indicator has been updated - void updatedIndicator(); + //! Indicator timed out + void onLoadIndicatorTimedOut(); //! Toggle the resize mode void toggleResizeMode(bool checked); @@ -820,15 +813,13 @@ namespace BlackGui //! Display the container as JSON popup virtual void displayContainerAsJsonPopup(bool selectedOnly); - // --------------------------------------------- SLOTS start here ----------------------------------------- - - //! \name Slot overrides from base class + //! \name Overrides from base class //! @{ - virtual void ps_clicked(const QModelIndex &index) override; - virtual void ps_doubleClicked(const QModelIndex &index) override; - virtual void ps_rowSelected(const QModelIndex &index) override; - virtual BlackMisc::CStatusMessage ps_loadJson(const QString &directory = {}) override; - virtual BlackMisc::CStatusMessage ps_saveJson(bool selectedOnly = false, const QString &directory = {}) override; + virtual void onClicked(const QModelIndex &index) override; + virtual void onDoubleClicked(const QModelIndex &index) override; + virtual void onRowSelected(const QModelIndex &index) override; + virtual BlackMisc::CStatusMessage loadJson(const QString &directory = {}) override; + virtual BlackMisc::CStatusMessage saveJson(bool selectedOnly = false, const QString &directory = {}) override; //! @} }; } // namespace diff --git a/src/blackgui/views/viewbasenontemplate.cpp b/src/blackgui/views/viewbasenontemplate.cpp index 5f73814fa..826319a23 100644 --- a/src/blackgui/views/viewbasenontemplate.cpp +++ b/src/blackgui/views/viewbasenontemplate.cpp @@ -43,8 +43,8 @@ namespace BlackGui { this->setContextMenuPolicy(Qt::CustomContextMenu); connect(this, &QWidget::customContextMenuRequested, this, &CViewBaseNonTemplate::customMenuRequested); - connect(this, &QTableView::clicked, this, &CViewBaseNonTemplate::ps_clicked); - connect(this, &QTableView::doubleClicked, this, &CViewBaseNonTemplate::ps_doubleClicked); + connect(this, &QTableView::clicked, this, &CViewBaseNonTemplate::onClicked); + connect(this, &QTableView::doubleClicked, this, &CViewBaseNonTemplate::onDoubleClicked); this->horizontalHeader()->setSortIndicatorShown(true); // setting resize mode rowsResizeModeToContent() causes extremly slow views @@ -166,7 +166,7 @@ namespace BlackGui QTableView::setSelectionModel(model); if (this->selectionModel()) { - connect(this->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &CViewBaseNonTemplate::ps_rowSelected); + connect(this->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &CViewBaseNonTemplate::onRowSelected); } } @@ -177,12 +177,12 @@ namespace BlackGui CStatusMessage CViewBaseNonTemplate::showFileLoadDialog(const QString &directory) { - return this->ps_loadJson(directory); + return this->loadJson(directory); } CStatusMessage CViewBaseNonTemplate::showFileSaveDialog(bool selectedOnly, const QString &directory) { - return this->ps_saveJson(selectedOnly, directory); + return this->saveJson(selectedOnly, directory); } void CViewBaseNonTemplate::setHorizontalHeaderSectionResizeMode(QHeaderView::ResizeMode mode) @@ -616,7 +616,7 @@ namespace BlackGui void CViewBaseNonTemplate::loadJsonAction() { if (!m_menus.testFlag(MenuLoad)) { return; } - const CStatusMessage m = this->ps_loadJson(); + const CStatusMessage m = this->loadJson(); if (!m.isEmpty()) { CLogMessage::preformatted(m); @@ -627,7 +627,7 @@ namespace BlackGui { if (this->isEmpty()) { return; } if (!m_menus.testFlag(MenuSave)) { return; } - const CStatusMessage m = this->ps_saveJson(false); + const CStatusMessage m = this->saveJson(false); if (!m.isEmpty()) { CLogMessage::preformatted(m); @@ -638,7 +638,7 @@ namespace BlackGui { if (this->isEmpty()) { return; } if (!m_menus.testFlag(MenuSave)) { return; } - const CStatusMessage m = this->ps_saveJson(true); + const CStatusMessage m = this->saveJson(true); if (!m.isEmpty()) { CLogMessage::preformatted(m); @@ -712,6 +712,7 @@ namespace BlackGui if (!m_loadIndicator) { m_loadIndicator = new CLoadIndicator(64, 64, this); + connect(m_loadIndicator, &CLoadIndicator::timedOut, this, &CViewBaseNonTemplate::onLoadIndicatorTimedOut); } this->centerLoadIndicator(); return m_loadIndicator->startAnimation(timeoutMs > 0 ? timeoutMs : m_loadIndicatorTimeoutMsDefault, processEvents); @@ -808,6 +809,11 @@ namespace BlackGui menu.exec(globalPos); } + void CViewBaseNonTemplate::onLoadIndicatorTimedOut() + { + m_showingLoadIndicator = false; + } + void CViewBaseNonTemplate::toggleResizeMode(bool checked) { m_resizeMode = checked ? ResizingAuto : ResizingOff; @@ -848,11 +854,6 @@ namespace BlackGui this->removeSelectedRows(); } - void CViewBaseNonTemplate::updatedIndicator() - { - this->update(); - } - void CViewBaseNonTemplate::dragEnterEvent(QDragEnterEvent *event) { if (!event || !this->acceptDrop(event->mimeData())) { return; }