mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 12:55:31 +08:00
refs #488, allow to select items in views and clear the console
This commit is contained in:
committed by
Mathew Sutcliffe
parent
54ed4140d3
commit
1b75f068be
@@ -21,8 +21,8 @@ namespace BlackGui
|
||||
CStatusMessageView::CStatusMessageView(QWidget *parent) : CViewBase(parent)
|
||||
{
|
||||
m_withMenuItemClear = true;
|
||||
m_acceptRowSelected = true;
|
||||
this->standardInit(new CStatusMessageListModel(this));
|
||||
connect(this, &CStatusMessageView::clicked, this, &CStatusMessageView::ps_messageSelected);
|
||||
}
|
||||
|
||||
void CStatusMessageView::setMode(CStatusMessageListModel::Mode mode)
|
||||
@@ -30,13 +30,5 @@ namespace BlackGui
|
||||
this->derivedModel()->setMode(mode);
|
||||
}
|
||||
|
||||
void CStatusMessageView::ps_messageSelected(const QModelIndex &index)
|
||||
{
|
||||
if (!index.isValid()) { return; }
|
||||
emit messageSelected(
|
||||
this->at(index)
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -32,14 +32,6 @@ namespace BlackGui
|
||||
|
||||
//! Set mode
|
||||
void setMode(BlackGui::Models::CStatusMessageListModel::Mode mode);
|
||||
|
||||
signals:
|
||||
//! Message has been selected
|
||||
void messageSelected(const BlackMisc::CStatusMessage &statusMessage);
|
||||
|
||||
private:
|
||||
//! Message selected
|
||||
void ps_messageSelected(const QModelIndex &index);
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -36,6 +36,8 @@ namespace BlackGui
|
||||
{
|
||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, &QWidget::customContextMenuRequested, this, &CViewBaseNonTemplate::ps_customMenuRequested);
|
||||
connect(this, &QTableView::clicked, this, &CViewBaseNonTemplate::ps_clicked);
|
||||
connect(this, &QTableView::doubleClicked, this, &CViewBaseNonTemplate::ps_doubleClicked);
|
||||
|
||||
// scroll modes
|
||||
this->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
@@ -100,6 +102,16 @@ namespace BlackGui
|
||||
return m_enabledLoadIndicator && m_showingLoadIndicator;
|
||||
}
|
||||
|
||||
void CViewBaseNonTemplate::setSelectionModel(QItemSelectionModel *model)
|
||||
{
|
||||
if (this->selectionModel()) { disconnect(this->selectionModel()); }
|
||||
QTableView::setSelectionModel(model);
|
||||
if (this->selectionModel())
|
||||
{
|
||||
connect(this->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &CViewBaseNonTemplate::ps_rowSelected);
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *CViewBaseNonTemplate::mainApplicationWindowWidget() const
|
||||
{
|
||||
return CGuiUtility::mainApplicationWindowWidget();
|
||||
@@ -601,6 +613,30 @@ namespace BlackGui
|
||||
this->derivedModel()->removeFilter();
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
void CViewBase<ModelClass, ContainerType, ObjectType>::ps_clicked(const QModelIndex &index)
|
||||
{
|
||||
if (!m_acceptClickSelection) { return; }
|
||||
if (!index.isValid()) { return; }
|
||||
emit objectClicked(CVariant::fromValue(at(index)));
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
void CViewBase<ModelClass, ContainerType, ObjectType>::ps_doubleClicked(const QModelIndex &index)
|
||||
{
|
||||
if (!m_acceptDoubleClickSelection) { return; }
|
||||
if (!index.isValid()) { return; }
|
||||
emit objectDoubleClicked(CVariant::fromValue(at(index)));
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
void CViewBase<ModelClass, ContainerType, ObjectType>::ps_rowSelected(const QModelIndex &index)
|
||||
{
|
||||
if (!m_acceptRowSelected) { return; }
|
||||
if (!index.isValid()) { return; }
|
||||
emit objectSelected(CVariant::fromValue(at(index)));
|
||||
}
|
||||
|
||||
// see here for the reason of thess forward instantiations
|
||||
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
||||
template class CViewBase<BlackGui::Models::CAircraftIcaoCodeListModel, BlackMisc::Aviation::CAircraftIcaoCodeList, BlackMisc::Aviation::CAircraftIcaoCode>;
|
||||
|
||||
@@ -108,6 +108,15 @@ namespace BlackGui
|
||||
//! Showing load indicator
|
||||
bool isShowingLoadIndicator() const;
|
||||
|
||||
//! Accept click selection
|
||||
void acceptClickSelection(bool accept) { m_acceptClickSelection = accept; }
|
||||
|
||||
//! Accept double click selection
|
||||
void acceptDoubleClickSelection(bool accept) { m_acceptDoubleClickSelection = accept; }
|
||||
|
||||
//! \copydoc QTableView::setSelectionModel();
|
||||
virtual void setSelectionModel(QItemSelectionModel *model) override;
|
||||
|
||||
//! Main application window widget if any
|
||||
QWidget *mainApplicationWindowWidget() const;
|
||||
|
||||
@@ -130,6 +139,15 @@ namespace BlackGui
|
||||
//! Single object was changed in model
|
||||
void objectChanged(const BlackMisc::CVariant &object, const BlackMisc::CPropertyIndex &changedIndex);
|
||||
|
||||
//! Object has been clicked
|
||||
void objectClicked(const BlackMisc::CVariant &object);
|
||||
|
||||
//! Object has been double clicked
|
||||
void objectDoubleClicked(const BlackMisc::CVariant &object);
|
||||
|
||||
//! Object has been double clicked
|
||||
void objectSelected(const BlackMisc::CVariant &object);
|
||||
|
||||
public slots:
|
||||
//! Resize to contents, strategy depends on container size
|
||||
virtual void resizeToContents();
|
||||
@@ -190,14 +208,17 @@ namespace BlackGui
|
||||
int m_skipResizeThreshold = 40; //!< when to skip resize (rows count)
|
||||
int m_resizeAutoNthTime = 1; //!< with ResizeAuto, resize every n-th time
|
||||
bool m_forceStretchLastColumnWhenResized = false; //!< a small table might (few columns) might to fail stretching, force again
|
||||
bool m_withMenuItemClear = false; //!< allow clearing the view via menu
|
||||
bool m_withMenuItemRefresh = false; //!< allow refreshing the view via menu
|
||||
bool m_withMenuItemBackend = false; //!< allow to request data from backend
|
||||
bool m_withMenuFilter = false; //!< filter can be opened
|
||||
bool m_showingLoadIndicator = false; //!< showing loading indicator
|
||||
bool m_enabledLoadIndicator = true; //!< loading indicator enabled/disabled
|
||||
QWidget *m_filterWidget = nullptr; //!< filter widget if any
|
||||
BlackGui::IMenuDelegate *m_menu = nullptr; //!< custom menu if any
|
||||
bool m_withMenuItemClear = false; //!< allow clearing the view via menu
|
||||
bool m_withMenuItemRefresh = false; //!< allow refreshing the view via menu
|
||||
bool m_withMenuItemBackend = false; //!< allow to request data from backend
|
||||
bool m_withMenuFilter = false; //!< filter can be opened
|
||||
bool m_showingLoadIndicator = false; //!< showing loading indicator
|
||||
bool m_enabledLoadIndicator = true; //!< loading indicator enabled/disabled
|
||||
bool m_acceptClickSelection = false; //!< clicked
|
||||
bool m_acceptRowSelected = false; //!< selection changed
|
||||
bool m_acceptDoubleClickSelection = false; //!< double clicked
|
||||
QWidget *m_filterWidget = nullptr; //!< filter widget if any
|
||||
BlackGui::IMenuDelegate *m_menu = nullptr; //!< custom menu if any
|
||||
BlackGui::CLoadIndicator *m_loadIndicator = nullptr; //!< load indicator if neeeded
|
||||
|
||||
protected slots:
|
||||
@@ -216,6 +237,15 @@ namespace BlackGui
|
||||
//! Filter changed in filter widget
|
||||
virtual bool ps_filterWidgetChangedFilter(bool enabled) = 0;
|
||||
|
||||
//! 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;
|
||||
|
||||
private slots:
|
||||
//! Custom menu was requested
|
||||
void ps_customMenuRequested(QPoint pos);
|
||||
@@ -323,6 +353,18 @@ namespace BlackGui
|
||||
//! \copydoc CViewBaseNonTemplate::ps_removeFilter
|
||||
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
|
||||
virtual void ps_removeFilter() override;
|
||||
|
||||
//! \copydoc CViewBaseNonTemplate::ps_clicked
|
||||
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
|
||||
virtual void ps_clicked(const QModelIndex &index) override;
|
||||
|
||||
//! \copydoc CViewBaseNonTemplate::ps_doubleClicked
|
||||
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
|
||||
virtual void ps_doubleClicked(const QModelIndex &index) override;
|
||||
|
||||
//! \copydoc CViewBaseNonTemplate::ps_doubleClicked
|
||||
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
|
||||
virtual void ps_rowSelected(const QModelIndex &index) override;
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user