mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 15:25:35 +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->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_Validate, &QPushButton::pressed, this, &CDbStashComponent::onValidatePressed);
|
||||
@@ -75,6 +71,10 @@ namespace BlackGui
|
||||
connect(ui->pb_Distributor, &QPushButton::pressed, this, &CDbStashComponent::copyOverValuesToSelectedModels);
|
||||
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->setHighlightModelStrings(true);
|
||||
ui->tvp_StashAircraftModels->setHighlightModelStringsColor(Qt::red);
|
||||
@@ -381,6 +381,7 @@ namespace BlackGui
|
||||
ui->pb_Validate->setEnabled(e);
|
||||
ui->pb_RemoveInvalid->setEnabled(e);
|
||||
ui->pb_Model->setEnabled(e);
|
||||
ui->pb_Publish->setEnabled(e);
|
||||
this->onUserChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QtGlobal>
|
||||
#include <QUrl>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
@@ -30,24 +31,22 @@ namespace BlackGui
|
||||
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
|
||||
{
|
||||
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_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);
|
||||
if (metaTypeId == QMetaType::UnknownType) { return false; }
|
||||
const bool accept = m_acceptedMetaTypes.contains(metaTypeId);
|
||||
const bool accept = m_acceptedMetaTypes.contains(metaTypeId);
|
||||
return accept;
|
||||
}
|
||||
|
||||
@@ -55,5 +54,4 @@ namespace BlackGui
|
||||
{
|
||||
return CGuiUtility::fromSwiftDragAndDropData(mime);
|
||||
}
|
||||
|
||||
} // ns
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include <QList>
|
||||
|
||||
class QMimeData;
|
||||
#include <QFileInfo>
|
||||
#include <QMimeData>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -30,11 +30,17 @@ namespace BlackGui
|
||||
//! Accepted ids
|
||||
void addAcceptedMetaTypeId(int id);
|
||||
|
||||
//! Drop allowed
|
||||
virtual bool isDropAllowed() const;
|
||||
//! Drop allowed?
|
||||
virtual bool isDropAllowed() const { return m_allowDrop; }
|
||||
|
||||
//! File drop allowed?
|
||||
virtual bool isJsonFileDropAllowed() const { return m_acceptJsonFile; }
|
||||
|
||||
//! 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?
|
||||
bool acceptDrop(const QMimeData *mime) const;
|
||||
@@ -42,12 +48,17 @@ namespace BlackGui
|
||||
//! Mime data to CVariant (normally encapsulating a value object)
|
||||
BlackMisc::CVariant toCVariant(const QMimeData *mime) const;
|
||||
|
||||
//! Dtor
|
||||
virtual ~CDropBase() {}
|
||||
|
||||
protected:
|
||||
//! Ctor
|
||||
CDropBase();
|
||||
|
||||
private:
|
||||
bool m_allowDrop = true; //!< dropping allowed?
|
||||
QList<int> m_acceptedMetaTypes; //!< accepted meta types
|
||||
bool m_allowDrop = true; //!< dropping allowed?
|
||||
bool m_acceptJsonFile = false; //!< accept JSON files
|
||||
QList<int> m_acceptedMetaTypes; //!< accepted meta types
|
||||
};
|
||||
} // ns
|
||||
|
||||
|
||||
@@ -32,13 +32,13 @@ namespace BlackGui
|
||||
this->setAcceptDrops(true);
|
||||
this->setTextFormat(Qt::RichText);
|
||||
this->setInfoText("drop data here");
|
||||
this->ps_onStyleSheetsChanged();
|
||||
connect(sGui, &CGuiApplication::styleSheetsChanged, this, &CDropSite::ps_onStyleSheetsChanged);
|
||||
this->onStyleSheetsChanged();
|
||||
connect(sGui, &CGuiApplication::styleSheetsChanged, this, &CDropSite::onStyleSheetsChanged);
|
||||
}
|
||||
|
||||
void CDropSite::setInfoText(const QString &dropSiteText)
|
||||
{
|
||||
this->m_infoText = dropSiteText;
|
||||
m_infoText = dropSiteText;
|
||||
this->resetText();
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace BlackGui
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace BlackGui
|
||||
this->resetText();
|
||||
}
|
||||
|
||||
void CDropSite::ps_onStyleSheetsChanged()
|
||||
void CDropSite::onStyleSheetsChanged()
|
||||
{
|
||||
// style sheet changes go here
|
||||
}
|
||||
|
||||
@@ -67,11 +67,10 @@ namespace BlackGui
|
||||
//! \copydoc QWidget::dropEvent
|
||||
virtual void dropEvent(QDropEvent *event) override;
|
||||
|
||||
private slots:
|
||||
//! Style has been changed
|
||||
void ps_onStyleSheetsChanged();
|
||||
|
||||
private:
|
||||
//! Style has been changed
|
||||
void onStyleSheetsChanged();
|
||||
|
||||
//! Clear
|
||||
void resetText();
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "blackgui/enableforframelesswindow.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackgui/overlaymessagesframe.h"
|
||||
#include "blackmisc/icon.h"
|
||||
#include "blackmisc/verify.h"
|
||||
|
||||
#include <QApplication>
|
||||
@@ -225,6 +226,31 @@ namespace BlackGui
|
||||
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)
|
||||
{
|
||||
static const QCheckBox defaultBox;
|
||||
@@ -519,4 +545,26 @@ namespace BlackGui
|
||||
w->setMinimumWidth(qMin(minW, w->minimumWidth()));
|
||||
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
|
||||
|
||||
@@ -33,6 +33,7 @@ class QMimeData;
|
||||
class QTabWidget;
|
||||
class QGraphicsOpacityEffect;
|
||||
|
||||
namespace BlackMisc { class CIcon; }
|
||||
namespace BlackGui
|
||||
{
|
||||
class CEnableForFramelessWindow;
|
||||
@@ -92,6 +93,15 @@ namespace BlackGui
|
||||
//! Meta type id from dropped data
|
||||
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
|
||||
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
|
||||
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:
|
||||
//! No constructor, use static functions only
|
||||
CGuiUtility() {}
|
||||
|
||||
@@ -10,13 +10,14 @@
|
||||
// Drag and drop docu:
|
||||
// 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/listmodelbase.h"
|
||||
#include "blackgui/models/allmodelcontainers.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackmisc/compare.h"
|
||||
#include "blackmisc/predicates.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/fileutils.h"
|
||||
#include "blackmisc/sequence.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/verify.h"
|
||||
@@ -27,6 +28,7 @@
|
||||
#include <QList>
|
||||
#include <QMimeData>
|
||||
#include <QtGlobal>
|
||||
#include <QFileInfo>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
@@ -193,7 +195,7 @@ namespace BlackGui
|
||||
this->setObjectName(translationContext);
|
||||
|
||||
// connect
|
||||
connect(this, &CListModelBaseNonTemplate::dataChanged, this, &CListModelBaseNonTemplate::ps_onDataChanged);
|
||||
connect(this, &CListModelBaseNonTemplate::dataChanged, this, &CListModelBaseNonTemplate::onDataChanged);
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
@@ -221,12 +223,13 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
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(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 (action == Qt::MoveAction)
|
||||
@@ -621,7 +624,7 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
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
|
||||
Q_UNUSED(topLeft);
|
||||
@@ -631,7 +634,7 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
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();
|
||||
emit this->changedDigest();
|
||||
|
||||
@@ -152,14 +152,13 @@ namespace BlackGui
|
||||
//! Template free information, that object changed
|
||||
void objectChanged(const BlackMisc::CVariant &object, const BlackMisc::CPropertyIndex &changedIndex);
|
||||
|
||||
protected slots:
|
||||
protected:
|
||||
//! 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
|
||||
virtual void ps_onChangedDigest() = 0;
|
||||
virtual void onChangedDigest() = 0;
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
//! \param translationContext I18N context
|
||||
//! \param parent
|
||||
@@ -172,7 +171,7 @@ namespace BlackGui
|
||||
Qt::DropActions m_dropActions = Qt::IgnoreAction; //!< drop actions
|
||||
|
||||
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
|
||||
@@ -190,7 +189,7 @@ namespace BlackGui
|
||||
virtual void sort(int column, Qt::SortOrder order) 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 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
|
||||
@@ -295,10 +294,7 @@ namespace BlackGui
|
||||
void takeFilterOwnership(std::unique_ptr<IModelFilter<ContainerType> > &filter);
|
||||
|
||||
//! Set the selection model
|
||||
void setSelectionModel(BlackGui::Models::ISelectionModel<ContainerType> *selectionModel)
|
||||
{
|
||||
m_selectionModel = selectionModel;
|
||||
}
|
||||
void setSelectionModel(BlackGui::Models::ISelectionModel<ContainerType> *selectionModel) { m_selectionModel = selectionModel; }
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
@@ -306,8 +302,8 @@ namespace BlackGui
|
||||
|
||||
//! \name Base class overrides
|
||||
//! @{
|
||||
virtual void ps_onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomLeft, const QVector<int> &roles) override;
|
||||
virtual void ps_onChangedDigest() override;
|
||||
virtual void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomLeft, const QVector<int> &roles) override;
|
||||
virtual void onChangedDigest() override;
|
||||
//! @}
|
||||
|
||||
//! 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
|
||||
}
|
||||
}
|
||||
} // 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