Fixed up and cleaned up Qt variant of wxDataFormat.
Kept "mime type" and "id" conceptually separate in the interface in case they need to diverge later. Got rid of the odd "wxChar *" variants and the QString one. Implemented unimplemented "type" functions. Implemented "!=" in terms of "==", to keep from having two places to keep in sync.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: wx/qt/toolbar.h
|
// Name: wx/qt/dataform.h
|
||||||
// Author: Sean D'Epagnier
|
// Author: Sean D'Epagnier
|
||||||
// Copyright: (c) Sean D'Epagnier 2014
|
// Copyright: (c) Sean D'Epagnier 2014
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
@@ -8,34 +8,34 @@
|
|||||||
#ifndef _WX_QT_DATAFORM_H_
|
#ifndef _WX_QT_DATAFORM_H_
|
||||||
#define _WX_QT_DATAFORM_H_
|
#define _WX_QT_DATAFORM_H_
|
||||||
|
|
||||||
class QString;
|
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxDataFormat
|
class WXDLLIMPEXP_CORE wxDataFormat
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxDataFormat();
|
wxDataFormat(wxDataFormatId formatId = wxDF_INVALID);
|
||||||
wxDataFormat( wxDataFormatId formatId );
|
|
||||||
wxDataFormat(const wxString &id);
|
wxDataFormat(const wxString &id);
|
||||||
wxDataFormat(const QString &id);
|
|
||||||
wxDataFormat(const wxChar *id);
|
|
||||||
|
|
||||||
void SetId( const wxChar *id );
|
// Standard methods
|
||||||
|
const wxString& GetId() const;
|
||||||
|
void SetId(const wxString& id);
|
||||||
|
|
||||||
|
wxDataFormatId GetType() const;
|
||||||
|
void SetType(wxDataFormatId type);
|
||||||
|
|
||||||
bool operator==(wxDataFormatId format) const;
|
bool operator==(wxDataFormatId format) const;
|
||||||
bool operator!=(wxDataFormatId format) const;
|
bool operator!=(wxDataFormatId format) const;
|
||||||
bool operator==(const wxDataFormat& format) const;
|
bool operator==(const wxDataFormat& format) const;
|
||||||
bool operator!=(const wxDataFormat& format) const;
|
bool operator!=(const wxDataFormat& format) const;
|
||||||
|
|
||||||
// string ids are used for custom types - this SetId() must be used for
|
// Direct access to the underlying mime type.
|
||||||
// application-specific formats
|
// Equivalent to "id", except "id" is supposed to be
|
||||||
wxString GetId() const;
|
// invalid for standard types, whereas this should
|
||||||
void SetId( const wxString& id );
|
// always be valid (if meaningful).
|
||||||
|
const wxString& GetMimeType() const;
|
||||||
|
void SetMimeType(const wxString& mimeType);
|
||||||
|
|
||||||
// implementation
|
private:
|
||||||
wxDataFormatId GetType() const;
|
wxString m_mimeType;
|
||||||
void SetType( wxDataFormatId type );
|
wxDataFormatId m_formatId;
|
||||||
|
|
||||||
wxString m_MimeType;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _WX_QT_DATAFORM_H_
|
#endif // _WX_QT_DATAFORM_H_
|
||||||
|
@@ -109,7 +109,7 @@ bool wxClipboard::AddData( wxDataObject *data )
|
|||||||
|
|
||||||
QByteArray bytearray(size, 0);
|
QByteArray bytearray(size, 0);
|
||||||
data->GetDataHere(format, bytearray.data());
|
data->GetDataHere(format, bytearray.data());
|
||||||
MimeData->setData(wxQtConvertString(format.m_MimeType), bytearray);
|
MimeData->setData(wxQtConvertString(format.GetMimeType()), bytearray);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete data;
|
delete data;
|
||||||
@@ -144,7 +144,7 @@ bool wxClipboard::GetData( wxDataObject& data )
|
|||||||
const wxDataFormat format(formats[i]);
|
const wxDataFormat format(formats[i]);
|
||||||
|
|
||||||
// is this format supported by clipboard ?
|
// is this format supported by clipboard ?
|
||||||
if( !MimeData->hasFormat(wxQtConvertString(format.m_MimeType)) )
|
if( !MimeData->hasFormat(wxQtConvertString(format.GetMimeType())) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
wxTextDataObject *textdata = dynamic_cast<wxTextDataObject*>(&data);
|
wxTextDataObject *textdata = dynamic_cast<wxTextDataObject*>(&data);
|
||||||
@@ -152,7 +152,7 @@ bool wxClipboard::GetData( wxDataObject& data )
|
|||||||
textdata->SetText(wxQtConvertString(MimeData->text()));
|
textdata->SetText(wxQtConvertString(MimeData->text()));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QByteArray bytearray = MimeData->data( wxQtConvertString(format.m_MimeType) ).data();
|
QByteArray bytearray = MimeData->data( wxQtConvertString(format.GetMimeType()) ).data();
|
||||||
data.SetData(format, bytearray.size(), bytearray.constData());
|
data.SetData(format, bytearray.size(), bytearray.constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ void wxClipboard::Clear()
|
|||||||
bool wxClipboard::IsSupported( const wxDataFormat& format )
|
bool wxClipboard::IsSupported( const wxDataFormat& format )
|
||||||
{
|
{
|
||||||
const QMimeData *data = QtClipboard->mimeData( (QClipboard::Mode)Mode() );
|
const QMimeData *data = QtClipboard->mimeData( (QClipboard::Mode)Mode() );
|
||||||
return data->hasFormat(wxQtConvertString(format.m_MimeType));
|
return data->hasFormat(wxQtConvertString(format.GetMimeType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxClipboard::IsSupportedAsync(wxEvtHandler *sink)
|
bool wxClipboard::IsSupportedAsync(wxEvtHandler *sink)
|
||||||
|
@@ -18,13 +18,12 @@
|
|||||||
|
|
||||||
#include <QtCore/QMimeData>
|
#include <QtCore/QMimeData>
|
||||||
|
|
||||||
wxDataFormat::wxDataFormat()
|
namespace
|
||||||
{
|
{
|
||||||
}
|
wxString DataFormatIdToMimeType(wxDataFormatId formatId)
|
||||||
|
{
|
||||||
static wxString DataFormatIdToMimeType( wxDataFormatId formatId )
|
switch ( formatId )
|
||||||
{
|
{
|
||||||
switch(formatId) {
|
|
||||||
case wxDF_TEXT: return "text/plain";
|
case wxDF_TEXT: return "text/plain";
|
||||||
case wxDF_BITMAP: return "image/bmp";
|
case wxDF_BITMAP: return "image/bmp";
|
||||||
case wxDF_TIFF: return "image/tiff";
|
case wxDF_TIFF: return "image/tiff";
|
||||||
@@ -45,75 +44,74 @@ static wxString DataFormatIdToMimeType( wxDataFormatId formatId )
|
|||||||
case wxDF_PRIVATE:
|
case wxDF_PRIVATE:
|
||||||
case wxDF_INVALID:
|
case wxDF_INVALID:
|
||||||
case wxDF_MAX:
|
case wxDF_MAX:
|
||||||
break;
|
default:
|
||||||
}
|
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataFormat::wxDataFormat( wxDataFormatId formatId )
|
wxDataFormat::wxDataFormat(wxDataFormatId formatId)
|
||||||
{
|
{
|
||||||
m_MimeType = DataFormatIdToMimeType(formatId);
|
SetType(formatId);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataFormat::wxDataFormat(const wxString &id)
|
wxDataFormat::wxDataFormat(const wxString &id)
|
||||||
{
|
{
|
||||||
m_MimeType = id;
|
SetId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataFormat::wxDataFormat(const wxChar *id)
|
const wxString& wxDataFormat::GetMimeType() const
|
||||||
{
|
{
|
||||||
m_MimeType = id;
|
return m_mimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataFormat::wxDataFormat(const QString &id)
|
void wxDataFormat::SetMimeType(const wxString& mimeType)
|
||||||
{
|
{
|
||||||
m_MimeType = wxQtConvertString(id);
|
m_mimeType = mimeType;
|
||||||
|
m_formatId = wxDF_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataFormat::SetId( const wxChar *id )
|
void wxDataFormat::SetId(const wxString& id)
|
||||||
{
|
{
|
||||||
m_MimeType = id;
|
SetMimeType(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataFormat::SetId( const wxString& id )
|
const wxString& wxDataFormat::GetId() const
|
||||||
{
|
{
|
||||||
m_MimeType = id;
|
return m_mimeType;
|
||||||
}
|
|
||||||
|
|
||||||
wxString wxDataFormat::GetId() const
|
|
||||||
{
|
|
||||||
return m_MimeType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataFormatId wxDataFormat::GetType() const
|
wxDataFormatId wxDataFormat::GetType() const
|
||||||
{
|
{
|
||||||
wxMISSING_IMPLEMENTATION( "wxDataFormat GetType" );
|
return m_formatId;
|
||||||
return wxDataFormatId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataFormat::SetType( wxDataFormatId WXUNUSED(type) )
|
void wxDataFormat::SetType(wxDataFormatId formatId)
|
||||||
{
|
{
|
||||||
wxMISSING_IMPLEMENTATION( "wxDataFormat SetType" );
|
m_mimeType = DataFormatIdToMimeType(formatId);
|
||||||
|
m_formatId = formatId;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataFormat::operator==(wxDataFormatId format) const
|
bool wxDataFormat::operator==(wxDataFormatId format) const
|
||||||
{
|
{
|
||||||
return m_MimeType == DataFormatIdToMimeType(format);
|
return m_mimeType == DataFormatIdToMimeType(format)
|
||||||
|
&& m_formatId == format;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataFormat::operator!=(wxDataFormatId format) const
|
bool wxDataFormat::operator!=(wxDataFormatId format) const
|
||||||
{
|
{
|
||||||
return m_MimeType != DataFormatIdToMimeType(format);
|
return !operator==(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataFormat::operator==(const wxDataFormat& format) const
|
bool wxDataFormat::operator==(const wxDataFormat& format) const
|
||||||
{
|
{
|
||||||
return m_MimeType == format.m_MimeType;
|
return m_mimeType == format.m_mimeType
|
||||||
|
&& m_formatId == format.m_formatId;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataFormat::operator!=(const wxDataFormat& format) const
|
bool wxDataFormat::operator!=(const wxDataFormat& format) const
|
||||||
{
|
{
|
||||||
return m_MimeType != format.m_MimeType;
|
return !operator==(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
|
Reference in New Issue
Block a user