Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+146
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
**
|
||||
** @RDE_HEADER@
|
||||
** Simple DropEventManager to manage drop events in SituationMap Map Widget
|
||||
** $Id$
|
||||
** $HeadURL$
|
||||
** $Author$
|
||||
**
|
||||
** -----------------------------------------------------------------------------------------------
|
||||
**
|
||||
** Hardware-Environment: Intel-PC
|
||||
** Software-Environment: Windows 7, Linux, Qt 5.4. ArcGIS 10.2.5
|
||||
**
|
||||
** Language ........: C++ 11
|
||||
**
|
||||
** -----------------------------------------------------------------------------------------------
|
||||
**
|
||||
** Author ...........: Jörg Turla, SPD G, Tel. 3132
|
||||
**
|
||||
** -----------------------------------------------------------------------------------------------
|
||||
**
|
||||
** Notes .........:
|
||||
**
|
||||
** 18.12.2015, JT : First edition for use with Qt5
|
||||
**
|
||||
** -----------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Common/referenced.h>
|
||||
|
||||
#include <QtCore/QPoint>
|
||||
|
||||
class QMimeData;
|
||||
|
||||
namespace SituationMap
|
||||
{
|
||||
|
||||
/**
|
||||
@class DropEventManager drop_event_manager.h
|
||||
@brief Drop event manager interface class.
|
||||
@see SituationMap::Map, PBase::PDropHandler
|
||||
|
||||
To process drop events the map window has to decide accepting a drop when it gets a drag enter event or not, depending on the type of mime data. Later
|
||||
when receiving a drop event the dropped data has to be processed. The DropEventManager class provides information of mime data type to decide handling
|
||||
the type of drop event or not. The function mimeFormatString() should return a uniquely defined string. To handle a special drop event the map will call
|
||||
the manageDrop function. Both functions have to be implemented in the derived class.
|
||||
|
||||
Following example shows how to implement a drop event mamager.
|
||||
|
||||
@code
|
||||
|
||||
#include <Map/drop_event_manager.h>
|
||||
|
||||
class DropEventManager : public SituationMap::DropEventManager
|
||||
{
|
||||
public:
|
||||
|
||||
DropEventManager() = default;
|
||||
|
||||
virtual ~DropEventManager()
|
||||
{
|
||||
// delete all dropHandler
|
||||
for (auto key : m_dropHandlerMap.keys())
|
||||
{
|
||||
delete m_dropHandlerMap[key];
|
||||
m_dropHandlerMap[key] = nullptr;
|
||||
}
|
||||
} // ~DropEventManager()
|
||||
|
||||
QString mimeFormatString() const { return QLatin1String("DropHandlerPtr"); }
|
||||
|
||||
void manageDrop( QPoint windowPos, const QMimeData * mimeData ) override
|
||||
{
|
||||
bool ok = false;
|
||||
qulonglong dropHandlerKey = mimeData->data(mimeFormatString()).toULongLong(&ok);
|
||||
if (ok)
|
||||
{
|
||||
QMap<qulonglong,PBase::PDropHandler*>::iterator dropHandler;
|
||||
dropHandler = m_dropHandlerMap.find( dropHandlerKey );
|
||||
if (dropHandler != m_dropHandlerMap.end())
|
||||
{
|
||||
(*dropHandler)->doDrop( windowPos.x(), windowPos.y(), mimeData );
|
||||
}
|
||||
}
|
||||
} // manageDrop( const QMimeData * mimeData )
|
||||
|
||||
qulonglong add( PBase::PDropHandler * dropHandler )
|
||||
{
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// DropEvewntManager get ownership of dropHandler and delete them in dtor.
|
||||
// See dtor above.
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
qulonglong key = qulonglong(dropHandler);
|
||||
if (dropHandler)
|
||||
{
|
||||
m_dropHandlerMap[key] = dropHandler;
|
||||
}
|
||||
return key;
|
||||
} // add(PBase::PDropHandler * dropHandler)
|
||||
|
||||
protected:
|
||||
|
||||
QMap<qulonglong,PBase::PDropHandler*> m_dropHandlerMap;
|
||||
|
||||
}; // DropEventManager
|
||||
|
||||
|
||||
void installDropEventManager()
|
||||
{
|
||||
m_dropEventManager = new DropEventManager();
|
||||
m_map -> installDropEventManager( m_dropEventManager );
|
||||
}
|
||||
|
||||
@endcode
|
||||
|
||||
*/
|
||||
|
||||
|
||||
class DropEventManager : public Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
DropEventManager() = default;
|
||||
~DropEventManager() = default;
|
||||
|
||||
DropEventManager(const DropEventManager *) = delete;
|
||||
|
||||
/*
|
||||
The function \c mimeFormatString() returns a uniquely defined string to identify type of mime data. The string will be used to call \c QMimeData::hasFormat()
|
||||
@see QMimeData
|
||||
*/
|
||||
virtual QString mimeFormatString() const = 0;
|
||||
|
||||
/*
|
||||
The function \c manageDrop() will be called to process drop events
|
||||
@param windowPos Mouse cursor from drop event
|
||||
@param mimeData Data of drop event to process.
|
||||
*/
|
||||
virtual void manageDrop(QPoint windowPos, const QMimeData *mimeData) = 0;
|
||||
|
||||
}; // DropEventManager
|
||||
|
||||
|
||||
} // namespace SituationMap
|
||||
Reference in new issue
Block a user