mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
Stashed data file can be dropped to model view
* utility functions * style changes / renamings / slots -> normal functions * extra flag to enable file drop (and changed signatures) * split view load function into 2 parts, one can use passed file parameter
This commit is contained in:
@@ -277,7 +277,11 @@ namespace BlackGui
|
||||
emit requestHandlingOfStashDrop(airline); // I need to convert to stanard livery, which I can`t do here
|
||||
}
|
||||
}
|
||||
} // valid mime?
|
||||
}
|
||||
else
|
||||
{
|
||||
CViewBase::dropEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void CAircraftModelView::customMenu(CMenuActions &menuActions)
|
||||
|
||||
@@ -1264,7 +1264,7 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
void CViewBase<ModelClass, ContainerType, ObjectType>::allowDragDrop(bool allowDrag, bool allowDrop)
|
||||
void CViewBase<ModelClass, ContainerType, ObjectType>::allowDragDrop(bool allowDrag, bool allowDrop, bool allowDropJsonFile)
|
||||
{
|
||||
Q_ASSERT(m_model);
|
||||
|
||||
@@ -1273,6 +1273,7 @@ namespace BlackGui
|
||||
this->setDragEnabled(allowDrag);
|
||||
this->setDropIndicatorShown(allowDrag || allowDrop);
|
||||
m_model->allowDrop(allowDrop);
|
||||
m_model->allowFileDrop(allowDropJsonFile);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
@@ -1282,6 +1283,19 @@ namespace BlackGui
|
||||
return m_model->isDropAllowed();
|
||||
}
|
||||
|
||||
template<class ModelClass, class ContainerType, class ObjectType>
|
||||
void CViewBase<ModelClass, ContainerType, ObjectType>::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if (m_model && m_model->isJsonFileDropAllowed() && CGuiUtility::isMimeRepresentingReadableJsonFile(event->mimeData()))
|
||||
{
|
||||
const QFileInfo fi = CGuiUtility::representedMimeFile(event->mimeData());
|
||||
const CStatusMessage msgs = this->loadJsonFile(fi.absoluteFilePath());
|
||||
Q_UNUSED(msgs);
|
||||
return;
|
||||
}
|
||||
CViewBaseNonTemplate::dropEvent(event);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
bool CViewBase<ModelClass, ContainerType, ObjectType>::acceptDrop(const QMimeData *mimeData) const
|
||||
{
|
||||
@@ -1500,15 +1514,12 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
CStatusMessage CViewBase<ModelClass, ContainerType, ObjectType>::ps_loadJson()
|
||||
template<class ModelClass, class ContainerType, class ObjectType>
|
||||
CStatusMessage CViewBase<ModelClass, ContainerType, ObjectType>::loadJsonFile(const QString &fileName)
|
||||
{
|
||||
CStatusMessage m;
|
||||
do
|
||||
{
|
||||
const QString fileName = QFileDialog::getOpenFileName(nullptr,
|
||||
tr("Load data file"), this->getFileDialogFileName(true),
|
||||
tr("swift (*.json *.txt)"));
|
||||
if (fileName.isEmpty())
|
||||
{
|
||||
m = CStatusMessage(this).error("Load canceled, no file name");
|
||||
@@ -1569,6 +1580,15 @@ namespace BlackGui
|
||||
return m;
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
CStatusMessage CViewBase<ModelClass, ContainerType, ObjectType>::ps_loadJson()
|
||||
{
|
||||
const QString fileName = QFileDialog::getOpenFileName(nullptr,
|
||||
tr("Load data file"), this->getFileDialogFileName(true),
|
||||
tr("swift (*.json *.txt)"));
|
||||
return this->loadJsonFile(fileName);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
CStatusMessage CViewBase<ModelClass, ContainerType, ObjectType>::ps_saveJson()
|
||||
{
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace BlackGui
|
||||
//! Non templated base class, allows Q_OBJECT and signals / slots to be used
|
||||
class BLACKGUI_EXPORT CViewBaseNonTemplate :
|
||||
public QTableView,
|
||||
public BlackGui::Components::CEnableForDockWidgetInfoArea
|
||||
public Components::CEnableForDockWidgetInfoArea
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace BlackGui
|
||||
virtual void sortByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) = 0;
|
||||
|
||||
//! Allow to drag and/or drop value objects
|
||||
virtual void allowDragDrop(bool allowDrag, bool allowDrop) = 0;
|
||||
virtual void allowDragDrop(bool allowDrag, bool allowDrop, bool allowDropJsonFile = false) = 0;
|
||||
|
||||
//! Drop allowed?
|
||||
virtual bool isDropAllowed() const = 0;
|
||||
@@ -444,6 +444,9 @@ namespace BlackGui
|
||||
//! Load JSON for action/menu, void return signatur
|
||||
void loadJsonAction();
|
||||
|
||||
//! Load JSON file
|
||||
virtual BlackMisc::CStatusMessage loadJsonFile(const QString &filePath) = 0;
|
||||
|
||||
//! Display the filter dialog
|
||||
void displayFilterDialog();
|
||||
|
||||
@@ -667,8 +670,9 @@ namespace BlackGui
|
||||
virtual int rowCount() const override;
|
||||
virtual bool isEmpty() const override;
|
||||
virtual bool isOrderable() const override;
|
||||
virtual void allowDragDrop(bool allowDrag, bool allowDrop) override;
|
||||
virtual void allowDragDrop(bool allowDrag, bool allowDrop, bool allowDropJsonFile = false) override;
|
||||
virtual bool isDropAllowed() const override;
|
||||
virtual void dropEvent(QDropEvent *event) override;
|
||||
virtual bool acceptDrop(const QMimeData *mimeData) const override;
|
||||
virtual void setSorting(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||
virtual void sortByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||
@@ -739,6 +743,9 @@ namespace BlackGui
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::customMenu
|
||||
virtual void customMenu(Menus::CMenuActions &menuActions) override;
|
||||
|
||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::customMenu
|
||||
virtual BlackMisc::CStatusMessage loadJsonFile(const QString &fileName) override;
|
||||
|
||||
// --------------------------------------------- SLOTS start here -----------------------------------------
|
||||
|
||||
//! \name Slot overrides from base class
|
||||
|
||||
@@ -162,7 +162,7 @@ namespace BlackGui
|
||||
this->m_leOrder->setValidator(this->m_validator);
|
||||
QWidgetAction *orderAction = new QWidgetAction(this);
|
||||
orderAction->setDefaultWidget(this->m_frame);
|
||||
QObject::connect(this->m_leOrder, &QLineEdit::returnPressed, this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_orderToLineEdit);
|
||||
QObject::connect(this->m_leOrder, &QLineEdit::returnPressed, this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::orderToLineEdit);
|
||||
this->m_menuActions[0] = orderAction;
|
||||
}
|
||||
}
|
||||
@@ -171,9 +171,9 @@ namespace BlackGui
|
||||
this->m_leOrder->setPlaceholderText("New order 0-" + QString::number(maxOrder));
|
||||
|
||||
menuActions.addAction(this->m_menuActions[0], CMenuAction::pathViewOrder());
|
||||
this->m_menuActions[1] = menuActions.addAction(CIcons::arrowMediumNorth16(), "To top", CMenuAction::pathViewOrder(), { this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_orderToTop });
|
||||
this->m_menuActions[2] = menuActions.addAction(CIcons::arrowMediumSouth16(), "To bottom", CMenuAction::pathViewOrder(), { this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_orderToBottom });
|
||||
this->m_menuActions[3] = menuActions.addAction(CIcons::arrowMediumWest16(), "Freeze current order", CMenuAction::pathViewOrder(), { this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_freezeCurrentOrder });
|
||||
this->m_menuActions[1] = menuActions.addAction(CIcons::arrowMediumNorth16(), "To top", CMenuAction::pathViewOrder(), { this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::orderToTop });
|
||||
this->m_menuActions[2] = menuActions.addAction(CIcons::arrowMediumSouth16(), "To bottom", CMenuAction::pathViewOrder(), { this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::orderToBottom });
|
||||
this->m_menuActions[3] = menuActions.addAction(CIcons::arrowMediumWest16(), "Freeze current order", CMenuAction::pathViewOrder(), { this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::freezeCurrentOrder });
|
||||
}
|
||||
CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::customMenu(menuActions);
|
||||
}
|
||||
@@ -197,13 +197,13 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_orderToTop()
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::orderToTop()
|
||||
{
|
||||
this->moveSelectedItems(0);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_orderToBottom()
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::orderToBottom()
|
||||
{
|
||||
int c = this->model()->rowCount() - 1;
|
||||
if (c >= 0)
|
||||
@@ -213,7 +213,7 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_orderToLineEdit()
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::orderToLineEdit()
|
||||
{
|
||||
if (this->isEmpty()) { return; }
|
||||
QLineEdit *le = qobject_cast<QLineEdit *>(QObject::sender());
|
||||
@@ -223,7 +223,7 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_freezeCurrentOrder()
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::freezeCurrentOrder()
|
||||
{
|
||||
ContainerType objects = this->container();
|
||||
objects.freezeOrder();
|
||||
|
||||
@@ -80,18 +80,17 @@ namespace BlackGui
|
||||
//! Move selected items
|
||||
void moveSelectedItems(int order);
|
||||
|
||||
protected slots:
|
||||
//! Order to top
|
||||
void ps_orderToTop();
|
||||
void orderToTop();
|
||||
|
||||
//! Order to bottom
|
||||
void ps_orderToBottom();
|
||||
void orderToBottom();
|
||||
|
||||
//! Order to line edit
|
||||
void ps_orderToLineEdit();
|
||||
void orderToLineEdit();
|
||||
|
||||
//! Current order set as order
|
||||
void ps_freezeCurrentOrder();
|
||||
void freezeCurrentOrder();
|
||||
|
||||
private:
|
||||
QList<QAction *> m_menuActions;
|
||||
|
||||
Reference in New Issue
Block a user