mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 10:55:32 +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:
@@ -56,10 +56,6 @@ namespace BlackGui
|
|||||||
ui(new Ui::CDbStashComponent)
|
ui(new Ui::CDbStashComponent)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->tvp_StashAircraftModels->setAircraftModelMode(CAircraftModelListModel::StashModel);
|
|
||||||
ui->tvp_StashAircraftModels->allowDragDrop(false, true);
|
|
||||||
ui->tvp_StashAircraftModels->setAcceptedMetaTypeIds();
|
|
||||||
ui->tvp_StashAircraftModels->menuAddItems(CAircraftModelView::MenuLoadAndSave);
|
|
||||||
|
|
||||||
connect(ui->pb_Unstash, &QPushButton::pressed, this, &CDbStashComponent::onUnstashPressed);
|
connect(ui->pb_Unstash, &QPushButton::pressed, this, &CDbStashComponent::onUnstashPressed);
|
||||||
connect(ui->pb_Validate, &QPushButton::pressed, this, &CDbStashComponent::onValidatePressed);
|
connect(ui->pb_Validate, &QPushButton::pressed, this, &CDbStashComponent::onValidatePressed);
|
||||||
@@ -75,6 +71,10 @@ namespace BlackGui
|
|||||||
connect(ui->pb_Distributor, &QPushButton::pressed, this, &CDbStashComponent::copyOverValuesToSelectedModels);
|
connect(ui->pb_Distributor, &QPushButton::pressed, this, &CDbStashComponent::copyOverValuesToSelectedModels);
|
||||||
connect(ui->pb_Model, &QPushButton::pressed, this, &CDbStashComponent::modifyModelDialog);
|
connect(ui->pb_Model, &QPushButton::pressed, this, &CDbStashComponent::modifyModelDialog);
|
||||||
|
|
||||||
|
ui->tvp_StashAircraftModels->setAircraftModelMode(CAircraftModelListModel::StashModel);
|
||||||
|
ui->tvp_StashAircraftModels->allowDragDrop(false, true, true);
|
||||||
|
ui->tvp_StashAircraftModels->setAcceptedMetaTypeIds();
|
||||||
|
ui->tvp_StashAircraftModels->menuAddItems(CAircraftModelView::MenuLoadAndSave);
|
||||||
ui->tvp_StashAircraftModels->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows);
|
ui->tvp_StashAircraftModels->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows);
|
||||||
ui->tvp_StashAircraftModels->setHighlightModelStrings(true);
|
ui->tvp_StashAircraftModels->setHighlightModelStrings(true);
|
||||||
ui->tvp_StashAircraftModels->setHighlightModelStringsColor(Qt::red);
|
ui->tvp_StashAircraftModels->setHighlightModelStringsColor(Qt::red);
|
||||||
@@ -381,6 +381,7 @@ namespace BlackGui
|
|||||||
ui->pb_Validate->setEnabled(e);
|
ui->pb_Validate->setEnabled(e);
|
||||||
ui->pb_RemoveInvalid->setEnabled(e);
|
ui->pb_RemoveInvalid->setEnabled(e);
|
||||||
ui->pb_Model->setEnabled(e);
|
ui->pb_Model->setEnabled(e);
|
||||||
|
ui->pb_Publish->setEnabled(e);
|
||||||
this->onUserChanged();
|
this->onUserChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
|
|
||||||
@@ -30,21 +31,19 @@ namespace BlackGui
|
|||||||
m_acceptedMetaTypes.append(id);
|
m_acceptedMetaTypes.append(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDropBase::isDropAllowed() const
|
|
||||||
{
|
|
||||||
return m_allowDrop;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDropBase::allowDrop(bool allowed)
|
|
||||||
{
|
|
||||||
this->m_allowDrop = allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CDropBase::acceptDrop(const QMimeData *mime) const
|
bool CDropBase::acceptDrop(const QMimeData *mime) const
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(!this->m_acceptedMetaTypes.isEmpty(), Q_FUNC_INFO, "no accepted meta type ids");
|
if (!mime) { return false; }
|
||||||
|
if (!m_allowDrop) { return false; }
|
||||||
if (m_acceptedMetaTypes.isEmpty()) { return false; }
|
if (m_acceptedMetaTypes.isEmpty()) { return false; }
|
||||||
if (!m_allowDrop || !CGuiUtility::hasSwiftVariantMimeType(mime)) { return false; }
|
|
||||||
|
if (m_acceptJsonFile && CGuiUtility::isMimeRepresentingReadableJsonFile(mime))
|
||||||
|
{
|
||||||
|
// further checks could go here
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CGuiUtility::hasSwiftVariantMimeType(mime)) { return false; }
|
||||||
const int metaTypeId = CGuiUtility::metaTypeIdFromSwiftDragAndDropData(mime);
|
const int metaTypeId = CGuiUtility::metaTypeIdFromSwiftDragAndDropData(mime);
|
||||||
if (metaTypeId == QMetaType::UnknownType) { return false; }
|
if (metaTypeId == QMetaType::UnknownType) { return false; }
|
||||||
const bool accept = m_acceptedMetaTypes.contains(metaTypeId);
|
const bool accept = m_acceptedMetaTypes.contains(metaTypeId);
|
||||||
@@ -55,5 +54,4 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
return CGuiUtility::fromSwiftDragAndDropData(mime);
|
return CGuiUtility::fromSwiftDragAndDropData(mime);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
#include "blackmisc/variant.h"
|
#include "blackmisc/variant.h"
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QFileInfo>
|
||||||
class QMimeData;
|
#include <QMimeData>
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
@@ -30,11 +30,17 @@ namespace BlackGui
|
|||||||
//! Accepted ids
|
//! Accepted ids
|
||||||
void addAcceptedMetaTypeId(int id);
|
void addAcceptedMetaTypeId(int id);
|
||||||
|
|
||||||
//! Drop allowed
|
//! Drop allowed?
|
||||||
virtual bool isDropAllowed() const;
|
virtual bool isDropAllowed() const { return m_allowDrop; }
|
||||||
|
|
||||||
|
//! File drop allowed?
|
||||||
|
virtual bool isJsonFileDropAllowed() const { return m_acceptJsonFile; }
|
||||||
|
|
||||||
//! Drop allowed
|
//! Drop allowed
|
||||||
virtual void allowDrop(bool allowed);
|
virtual void allowDrop(bool allowed) { m_allowDrop = allowed; }
|
||||||
|
|
||||||
|
//! Allow JSON file drop
|
||||||
|
virtual void allowFileDrop(bool allow) { m_acceptJsonFile = allow; }
|
||||||
|
|
||||||
//! Accept drop?
|
//! Accept drop?
|
||||||
bool acceptDrop(const QMimeData *mime) const;
|
bool acceptDrop(const QMimeData *mime) const;
|
||||||
@@ -42,11 +48,16 @@ namespace BlackGui
|
|||||||
//! Mime data to CVariant (normally encapsulating a value object)
|
//! Mime data to CVariant (normally encapsulating a value object)
|
||||||
BlackMisc::CVariant toCVariant(const QMimeData *mime) const;
|
BlackMisc::CVariant toCVariant(const QMimeData *mime) const;
|
||||||
|
|
||||||
|
//! Dtor
|
||||||
|
virtual ~CDropBase() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
//! Ctor
|
||||||
CDropBase();
|
CDropBase();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_allowDrop = true; //!< dropping allowed?
|
bool m_allowDrop = true; //!< dropping allowed?
|
||||||
|
bool m_acceptJsonFile = false; //!< accept JSON files
|
||||||
QList<int> m_acceptedMetaTypes; //!< accepted meta types
|
QList<int> m_acceptedMetaTypes; //!< accepted meta types
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -32,13 +32,13 @@ namespace BlackGui
|
|||||||
this->setAcceptDrops(true);
|
this->setAcceptDrops(true);
|
||||||
this->setTextFormat(Qt::RichText);
|
this->setTextFormat(Qt::RichText);
|
||||||
this->setInfoText("drop data here");
|
this->setInfoText("drop data here");
|
||||||
this->ps_onStyleSheetsChanged();
|
this->onStyleSheetsChanged();
|
||||||
connect(sGui, &CGuiApplication::styleSheetsChanged, this, &CDropSite::ps_onStyleSheetsChanged);
|
connect(sGui, &CGuiApplication::styleSheetsChanged, this, &CDropSite::onStyleSheetsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDropSite::setInfoText(const QString &dropSiteText)
|
void CDropSite::setInfoText(const QString &dropSiteText)
|
||||||
{
|
{
|
||||||
this->m_infoText = dropSiteText;
|
m_infoText = dropSiteText;
|
||||||
this->resetText();
|
this->resetText();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CDropSite::resetText()
|
void CDropSite::resetText()
|
||||||
{
|
{
|
||||||
const QString html = "<img src=':/own/icons/own/drophere16.png'> " + this->m_infoText.toHtmlEscaped();
|
const QString html = "<img src=':/own/icons/own/drophere16.png'> " + m_infoText.toHtmlEscaped();
|
||||||
setText(html);
|
setText(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ namespace BlackGui
|
|||||||
this->resetText();
|
this->resetText();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDropSite::ps_onStyleSheetsChanged()
|
void CDropSite::onStyleSheetsChanged()
|
||||||
{
|
{
|
||||||
// style sheet changes go here
|
// style sheet changes go here
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,11 +67,10 @@ namespace BlackGui
|
|||||||
//! \copydoc QWidget::dropEvent
|
//! \copydoc QWidget::dropEvent
|
||||||
virtual void dropEvent(QDropEvent *event) override;
|
virtual void dropEvent(QDropEvent *event) override;
|
||||||
|
|
||||||
private slots:
|
|
||||||
//! Style has been changed
|
|
||||||
void ps_onStyleSheetsChanged();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
//! Style has been changed
|
||||||
|
void onStyleSheetsChanged();
|
||||||
|
|
||||||
//! Clear
|
//! Clear
|
||||||
void resetText();
|
void resetText();
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "blackgui/enableforframelesswindow.h"
|
#include "blackgui/enableforframelesswindow.h"
|
||||||
#include "blackgui/guiutility.h"
|
#include "blackgui/guiutility.h"
|
||||||
#include "blackgui/overlaymessagesframe.h"
|
#include "blackgui/overlaymessagesframe.h"
|
||||||
|
#include "blackmisc/icon.h"
|
||||||
#include "blackmisc/verify.h"
|
#include "blackmisc/verify.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@@ -225,6 +226,31 @@ namespace BlackGui
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QFileInfo CGuiUtility::representedMimeFile(const QMimeData *mime)
|
||||||
|
{
|
||||||
|
if (!mime->hasText()) { return QFileInfo(); }
|
||||||
|
const QString candidate = mime->text();
|
||||||
|
if (candidate.isEmpty()) { return QFileInfo(); }
|
||||||
|
if (!candidate.contains("://")) { return QFileInfo(candidate); }
|
||||||
|
QUrl url(candidate);
|
||||||
|
const QString localFile = url.toLocalFile();
|
||||||
|
return QFileInfo(localFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CGuiUtility::isMimeRepresentingReadableFile(const QMimeData *mime)
|
||||||
|
{
|
||||||
|
const QFileInfo fi = CGuiUtility::representedMimeFile(mime);
|
||||||
|
return fi.isReadable();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CGuiUtility::isMimeRepresentingReadableJsonFile(const QMimeData *mime)
|
||||||
|
{
|
||||||
|
const QFileInfo fi = CGuiUtility::representedMimeFile(mime);
|
||||||
|
if (!fi.isReadable()) { return false; }
|
||||||
|
const QString fn = fi.fileName();
|
||||||
|
return fn.endsWith("json", Qt::CaseInsensitive);
|
||||||
|
}
|
||||||
|
|
||||||
void CGuiUtility::checkBoxReadOnly(QCheckBox *checkBox, bool readOnly)
|
void CGuiUtility::checkBoxReadOnly(QCheckBox *checkBox, bool readOnly)
|
||||||
{
|
{
|
||||||
static const QCheckBox defaultBox;
|
static const QCheckBox defaultBox;
|
||||||
@@ -519,4 +545,26 @@ namespace BlackGui
|
|||||||
w->setMinimumWidth(qMin(minW, w->minimumWidth()));
|
w->setMinimumWidth(qMin(minW, w->minimumWidth()));
|
||||||
w->setMinimumHeight(qMin(minH, w->minimumHeight()));
|
w->setMinimumHeight(qMin(minH, w->minimumHeight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CGuiUtility::asSimpleHtmlImageWidth(const CIcon &icon, int width)
|
||||||
|
{
|
||||||
|
if (!icon.hasFileResourcePath()) return QStringLiteral("");
|
||||||
|
const QString p = icon.getFileResourcePath();
|
||||||
|
|
||||||
|
static const QString htmlNoWidth("<img src=\"%1\">");
|
||||||
|
static const QString htmlWidth("<img src=\"%1\" width=%2>");
|
||||||
|
|
||||||
|
if (width < 0) { return htmlNoWidth.arg(p); }
|
||||||
|
return htmlWidth.arg(p, QString::number(width));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CGuiUtility::asSimpleHtmlImageHeight(const CIcon &icon, int height)
|
||||||
|
{
|
||||||
|
if (height < 0) { return CGuiUtility::asSimpleHtmlImageWidth(icon); }
|
||||||
|
if (!icon.hasFileResourcePath()) return QStringLiteral("");
|
||||||
|
const QString p = icon.getFileResourcePath();
|
||||||
|
|
||||||
|
static const QString htmlHeight("<img src=\"%1\" height=%2>");
|
||||||
|
return htmlHeight.arg(p, QString::number(height));
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class QMimeData;
|
|||||||
class QTabWidget;
|
class QTabWidget;
|
||||||
class QGraphicsOpacityEffect;
|
class QGraphicsOpacityEffect;
|
||||||
|
|
||||||
|
namespace BlackMisc { class CIcon; }
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
class CEnableForFramelessWindow;
|
class CEnableForFramelessWindow;
|
||||||
@@ -92,6 +93,15 @@ namespace BlackGui
|
|||||||
//! Meta type id from dropped data
|
//! Meta type id from dropped data
|
||||||
static int metaTypeIdFromSwiftDragAndDropData(const QMimeData *mime);
|
static int metaTypeIdFromSwiftDragAndDropData(const QMimeData *mime);
|
||||||
|
|
||||||
|
//! Represented file if any
|
||||||
|
static QFileInfo representedMimeFile(const QMimeData *mime);
|
||||||
|
|
||||||
|
//! Is representing existing file
|
||||||
|
static bool isMimeRepresentingReadableFile(const QMimeData *mime);
|
||||||
|
|
||||||
|
//! Is representing existing JSON file
|
||||||
|
static bool isMimeRepresentingReadableJsonFile(const QMimeData *mime);
|
||||||
|
|
||||||
//! Find next BlackGui::COverlayMessages QFrame
|
//! Find next BlackGui::COverlayMessages QFrame
|
||||||
static COverlayMessagesFrame *nextOverlayMessageFrame(QWidget *widget, int maxLevels = 10);
|
static COverlayMessagesFrame *nextOverlayMessageFrame(QWidget *widget, int maxLevels = 10);
|
||||||
|
|
||||||
@@ -173,6 +183,12 @@ namespace BlackGui
|
|||||||
//! Make sure that the min.sizes to not exceed the screen resolution
|
//! Make sure that the min.sizes to not exceed the screen resolution
|
||||||
static void superviseMainWindowMinSizes(qreal wRatio = 0.85, qreal hRatio = 0.85);
|
static void superviseMainWindowMinSizes(qreal wRatio = 0.85, qreal hRatio = 0.85);
|
||||||
|
|
||||||
|
//! CIcon as simple HTML image code segment
|
||||||
|
static QString asSimpleHtmlImageWidth(const BlackMisc::CIcon &icon, int width = -1);
|
||||||
|
|
||||||
|
//! CIcon as simple HTML image code segment
|
||||||
|
static QString asSimpleHtmlImageHeight(const BlackMisc::CIcon &icon, int height = -1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! No constructor, use static functions only
|
//! No constructor, use static functions only
|
||||||
CGuiUtility() {}
|
CGuiUtility() {}
|
||||||
|
|||||||
@@ -10,13 +10,14 @@
|
|||||||
// Drag and drop docu:
|
// Drag and drop docu:
|
||||||
// http://doc.qt.io/qt-5/model-view-programming.html#using-drag-and-drop-with-item-views
|
// http://doc.qt.io/qt-5/model-view-programming.html#using-drag-and-drop-with-item-views
|
||||||
|
|
||||||
#include "blackgui/guiutility.h"
|
|
||||||
#include "blackgui/models/columnformatters.h"
|
#include "blackgui/models/columnformatters.h"
|
||||||
#include "blackgui/models/listmodelbase.h"
|
#include "blackgui/models/listmodelbase.h"
|
||||||
#include "blackgui/models/allmodelcontainers.h"
|
#include "blackgui/models/allmodelcontainers.h"
|
||||||
|
#include "blackgui/guiutility.h"
|
||||||
#include "blackmisc/compare.h"
|
#include "blackmisc/compare.h"
|
||||||
#include "blackmisc/predicates.h"
|
#include "blackmisc/predicates.h"
|
||||||
#include "blackmisc/propertyindex.h"
|
#include "blackmisc/propertyindex.h"
|
||||||
|
#include "blackmisc/fileutils.h"
|
||||||
#include "blackmisc/sequence.h"
|
#include "blackmisc/sequence.h"
|
||||||
#include "blackmisc/variant.h"
|
#include "blackmisc/variant.h"
|
||||||
#include "blackmisc/verify.h"
|
#include "blackmisc/verify.h"
|
||||||
@@ -27,6 +28,7 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
@@ -193,7 +195,7 @@ namespace BlackGui
|
|||||||
this->setObjectName(translationContext);
|
this->setObjectName(translationContext);
|
||||||
|
|
||||||
// connect
|
// connect
|
||||||
connect(this, &CListModelBaseNonTemplate::dataChanged, this, &CListModelBaseNonTemplate::ps_onDataChanged);
|
connect(this, &CListModelBaseNonTemplate::dataChanged, this, &CListModelBaseNonTemplate::onDataChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
@@ -221,12 +223,13 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
bool CListModelBase<ObjectType, ContainerType, UseCompare>::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
bool CListModelBase<ObjectType, ContainerType, UseCompare>::dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
Q_UNUSED(row);
|
Q_UNUSED(row);
|
||||||
Q_UNUSED(column);
|
Q_UNUSED(column);
|
||||||
if (!this->isOrderable() || !this->acceptDrop(data)) { return false; }
|
|
||||||
const CVariant valueVariant(this->toCVariant(data));
|
if (!this->isOrderable() || !this->acceptDrop(mimeData)) { return false; }
|
||||||
|
const CVariant valueVariant(this->toCVariant(mimeData));
|
||||||
if (valueVariant.isValid())
|
if (valueVariant.isValid())
|
||||||
{
|
{
|
||||||
if (action == Qt::MoveAction)
|
if (action == Qt::MoveAction)
|
||||||
@@ -621,7 +624,7 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::ps_onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
void CListModelBase<ObjectType, ContainerType, UseCompare>::onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
||||||
{
|
{
|
||||||
// underlying base class changed
|
// underlying base class changed
|
||||||
Q_UNUSED(topLeft);
|
Q_UNUSED(topLeft);
|
||||||
@@ -631,7 +634,7 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::ps_onChangedDigest()
|
void CListModelBase<ObjectType, ContainerType, UseCompare>::onChangedDigest()
|
||||||
{
|
{
|
||||||
const int n = this->containerOrFilteredContainer().size();
|
const int n = this->containerOrFilteredContainer().size();
|
||||||
emit this->changedDigest();
|
emit this->changedDigest();
|
||||||
|
|||||||
@@ -152,14 +152,13 @@ namespace BlackGui
|
|||||||
//! Template free information, that object changed
|
//! Template free information, that object changed
|
||||||
void objectChanged(const BlackMisc::CVariant &object, const BlackMisc::CPropertyIndex &changedIndex);
|
void objectChanged(const BlackMisc::CVariant &object, const BlackMisc::CPropertyIndex &changedIndex);
|
||||||
|
|
||||||
protected slots:
|
protected:
|
||||||
//! Feedback when QStandardItemModel::dataChanged was called
|
//! Feedback when QStandardItemModel::dataChanged was called
|
||||||
virtual void ps_onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) = 0;
|
virtual void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) = 0;
|
||||||
|
|
||||||
//! Digest signal
|
//! Digest signal
|
||||||
virtual void ps_onChangedDigest() = 0;
|
virtual void onChangedDigest() = 0;
|
||||||
|
|
||||||
protected:
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
//! \param translationContext I18N context
|
//! \param translationContext I18N context
|
||||||
//! \param parent
|
//! \param parent
|
||||||
@@ -172,7 +171,7 @@ namespace BlackGui
|
|||||||
Qt::DropActions m_dropActions = Qt::IgnoreAction; //!< drop actions
|
Qt::DropActions m_dropActions = Qt::IgnoreAction; //!< drop actions
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BlackMisc::CDigestSignal m_dsModelsChanged { this, &CListModelBaseNonTemplate::changed, &CListModelBaseNonTemplate::ps_onChangedDigest, 500, 10 };
|
BlackMisc::CDigestSignal m_dsModelsChanged { this, &CListModelBaseNonTemplate::changed, &CListModelBaseNonTemplate::onChangedDigest, 500, 10 };
|
||||||
};
|
};
|
||||||
|
|
||||||
//! List model
|
//! List model
|
||||||
@@ -190,7 +189,7 @@ namespace BlackGui
|
|||||||
virtual void sort(int column, Qt::SortOrder order) final override;
|
virtual void sort(int column, Qt::SortOrder order) final override;
|
||||||
virtual int rowCount(const QModelIndex &parentIndex = QModelIndex()) const final override;
|
virtual int rowCount(const QModelIndex &parentIndex = QModelIndex()) const final override;
|
||||||
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const final override;
|
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const final override;
|
||||||
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) final override;
|
virtual bool dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent) final override;
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
//! \name Functions from CListModelBaseNonTemplate
|
//! \name Functions from CListModelBaseNonTemplate
|
||||||
@@ -295,10 +294,7 @@ namespace BlackGui
|
|||||||
void takeFilterOwnership(std::unique_ptr<IModelFilter<ContainerType> > &filter);
|
void takeFilterOwnership(std::unique_ptr<IModelFilter<ContainerType> > &filter);
|
||||||
|
|
||||||
//! Set the selection model
|
//! Set the selection model
|
||||||
void setSelectionModel(BlackGui::Models::ISelectionModel<ContainerType> *selectionModel)
|
void setSelectionModel(BlackGui::Models::ISelectionModel<ContainerType> *selectionModel) { m_selectionModel = selectionModel; }
|
||||||
{
|
|
||||||
m_selectionModel = selectionModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
@@ -306,8 +302,8 @@ namespace BlackGui
|
|||||||
|
|
||||||
//! \name Base class overrides
|
//! \name Base class overrides
|
||||||
//! @{
|
//! @{
|
||||||
virtual void ps_onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomLeft, const QVector<int> &roles) override;
|
virtual void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomLeft, const QVector<int> &roles) override;
|
||||||
virtual void ps_onChangedDigest() override;
|
virtual void onChangedDigest() override;
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
//! Update filtered container
|
//! Update filtered container
|
||||||
|
|||||||
@@ -277,7 +277,11 @@ namespace BlackGui
|
|||||||
emit requestHandlingOfStashDrop(airline); // I need to convert to stanard livery, which I can`t do here
|
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)
|
void CAircraftModelView::customMenu(CMenuActions &menuActions)
|
||||||
|
|||||||
@@ -1264,7 +1264,7 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class ModelClass, class ContainerType, class ObjectType>
|
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);
|
Q_ASSERT(m_model);
|
||||||
|
|
||||||
@@ -1273,6 +1273,7 @@ namespace BlackGui
|
|||||||
this->setDragEnabled(allowDrag);
|
this->setDragEnabled(allowDrag);
|
||||||
this->setDropIndicatorShown(allowDrag || allowDrop);
|
this->setDropIndicatorShown(allowDrag || allowDrop);
|
||||||
m_model->allowDrop(allowDrop);
|
m_model->allowDrop(allowDrop);
|
||||||
|
m_model->allowFileDrop(allowDropJsonFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ModelClass, class ContainerType, class ObjectType>
|
template <class ModelClass, class ContainerType, class ObjectType>
|
||||||
@@ -1282,6 +1283,19 @@ namespace BlackGui
|
|||||||
return m_model->isDropAllowed();
|
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>
|
template <class ModelClass, class ContainerType, class ObjectType>
|
||||||
bool CViewBase<ModelClass, ContainerType, ObjectType>::acceptDrop(const QMimeData *mimeData) const
|
bool CViewBase<ModelClass, ContainerType, ObjectType>::acceptDrop(const QMimeData *mimeData) const
|
||||||
{
|
{
|
||||||
@@ -1501,14 +1515,11 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class ModelClass, class ContainerType, class ObjectType>
|
template<class ModelClass, class ContainerType, class ObjectType>
|
||||||
CStatusMessage CViewBase<ModelClass, ContainerType, ObjectType>::ps_loadJson()
|
CStatusMessage CViewBase<ModelClass, ContainerType, ObjectType>::loadJsonFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
CStatusMessage m;
|
CStatusMessage m;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
const QString fileName = QFileDialog::getOpenFileName(nullptr,
|
|
||||||
tr("Load data file"), this->getFileDialogFileName(true),
|
|
||||||
tr("swift (*.json *.txt)"));
|
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
{
|
{
|
||||||
m = CStatusMessage(this).error("Load canceled, no file name");
|
m = CStatusMessage(this).error("Load canceled, no file name");
|
||||||
@@ -1569,6 +1580,15 @@ namespace BlackGui
|
|||||||
return m;
|
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>
|
template <class ModelClass, class ContainerType, class ObjectType>
|
||||||
CStatusMessage CViewBase<ModelClass, ContainerType, ObjectType>::ps_saveJson()
|
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
|
//! Non templated base class, allows Q_OBJECT and signals / slots to be used
|
||||||
class BLACKGUI_EXPORT CViewBaseNonTemplate :
|
class BLACKGUI_EXPORT CViewBaseNonTemplate :
|
||||||
public QTableView,
|
public QTableView,
|
||||||
public BlackGui::Components::CEnableForDockWidgetInfoArea
|
public Components::CEnableForDockWidgetInfoArea
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ namespace BlackGui
|
|||||||
virtual void sortByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) = 0;
|
virtual void sortByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) = 0;
|
||||||
|
|
||||||
//! Allow to drag and/or drop value objects
|
//! 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?
|
//! Drop allowed?
|
||||||
virtual bool isDropAllowed() const = 0;
|
virtual bool isDropAllowed() const = 0;
|
||||||
@@ -444,6 +444,9 @@ namespace BlackGui
|
|||||||
//! Load JSON for action/menu, void return signatur
|
//! Load JSON for action/menu, void return signatur
|
||||||
void loadJsonAction();
|
void loadJsonAction();
|
||||||
|
|
||||||
|
//! Load JSON file
|
||||||
|
virtual BlackMisc::CStatusMessage loadJsonFile(const QString &filePath) = 0;
|
||||||
|
|
||||||
//! Display the filter dialog
|
//! Display the filter dialog
|
||||||
void displayFilterDialog();
|
void displayFilterDialog();
|
||||||
|
|
||||||
@@ -667,8 +670,9 @@ namespace BlackGui
|
|||||||
virtual int rowCount() const override;
|
virtual int rowCount() const override;
|
||||||
virtual bool isEmpty() const override;
|
virtual bool isEmpty() const override;
|
||||||
virtual bool isOrderable() 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 bool isDropAllowed() const override;
|
||||||
|
virtual void dropEvent(QDropEvent *event) override;
|
||||||
virtual bool acceptDrop(const QMimeData *mimeData) const override;
|
virtual bool acceptDrop(const QMimeData *mimeData) const override;
|
||||||
virtual void setSorting(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) 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;
|
virtual void sortByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||||
@@ -739,6 +743,9 @@ namespace BlackGui
|
|||||||
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::customMenu
|
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::customMenu
|
||||||
virtual void customMenu(Menus::CMenuActions &menuActions) override;
|
virtual void customMenu(Menus::CMenuActions &menuActions) override;
|
||||||
|
|
||||||
|
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::customMenu
|
||||||
|
virtual BlackMisc::CStatusMessage loadJsonFile(const QString &fileName) override;
|
||||||
|
|
||||||
// --------------------------------------------- SLOTS start here -----------------------------------------
|
// --------------------------------------------- SLOTS start here -----------------------------------------
|
||||||
|
|
||||||
//! \name Slot overrides from base class
|
//! \name Slot overrides from base class
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ namespace BlackGui
|
|||||||
this->m_leOrder->setValidator(this->m_validator);
|
this->m_leOrder->setValidator(this->m_validator);
|
||||||
QWidgetAction *orderAction = new QWidgetAction(this);
|
QWidgetAction *orderAction = new QWidgetAction(this);
|
||||||
orderAction->setDefaultWidget(this->m_frame);
|
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;
|
this->m_menuActions[0] = orderAction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,9 +171,9 @@ namespace BlackGui
|
|||||||
this->m_leOrder->setPlaceholderText("New order 0-" + QString::number(maxOrder));
|
this->m_leOrder->setPlaceholderText("New order 0-" + QString::number(maxOrder));
|
||||||
|
|
||||||
menuActions.addAction(this->m_menuActions[0], CMenuAction::pathViewOrder());
|
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[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>::ps_orderToBottom });
|
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>::ps_freezeCurrentOrder });
|
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);
|
CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::customMenu(menuActions);
|
||||||
}
|
}
|
||||||
@@ -197,13 +197,13 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
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);
|
this->moveSelectedItems(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
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;
|
int c = this->model()->rowCount() - 1;
|
||||||
if (c >= 0)
|
if (c >= 0)
|
||||||
@@ -213,7 +213,7 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
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; }
|
if (this->isEmpty()) { return; }
|
||||||
QLineEdit *le = qobject_cast<QLineEdit *>(QObject::sender());
|
QLineEdit *le = qobject_cast<QLineEdit *>(QObject::sender());
|
||||||
@@ -223,7 +223,7 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
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();
|
ContainerType objects = this->container();
|
||||||
objects.freezeOrder();
|
objects.freezeOrder();
|
||||||
|
|||||||
@@ -80,18 +80,17 @@ namespace BlackGui
|
|||||||
//! Move selected items
|
//! Move selected items
|
||||||
void moveSelectedItems(int order);
|
void moveSelectedItems(int order);
|
||||||
|
|
||||||
protected slots:
|
|
||||||
//! Order to top
|
//! Order to top
|
||||||
void ps_orderToTop();
|
void orderToTop();
|
||||||
|
|
||||||
//! Order to bottom
|
//! Order to bottom
|
||||||
void ps_orderToBottom();
|
void orderToBottom();
|
||||||
|
|
||||||
//! Order to line edit
|
//! Order to line edit
|
||||||
void ps_orderToLineEdit();
|
void orderToLineEdit();
|
||||||
|
|
||||||
//! Current order set as order
|
//! Current order set as order
|
||||||
void ps_freezeCurrentOrder();
|
void freezeCurrentOrder();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QAction *> m_menuActions;
|
QList<QAction *> m_menuActions;
|
||||||
|
|||||||
Reference in New Issue
Block a user