qskinny/src/common/QskLabelData.cpp

108 lines
2.1 KiB
C++
Raw Normal View History

2023-03-09 15:30:40 +01:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#include "QskLabelData.h"
#include "QskGraphicProvider.h"
#include <qvariant.h>
#include <qhashfunctions.h>
static void qskRegisterLabelData()
{
qRegisterMetaType< QskLabelData >();
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
QMetaType::registerEqualsComparator< QskLabelData >();
#endif
}
Q_CONSTRUCTOR_FUNCTION( qskRegisterLabelData )
2023-03-09 17:59:54 +01:00
QskLabelData::QskLabelData( const char* text )
: m_text( text )
{
}
2023-03-09 15:30:40 +01:00
QskLabelData::QskLabelData( const QString& text )
: m_text( text )
{
}
QskLabelData::QskLabelData( const QskIcon& icon )
: m_icon( icon )
{
}
QskLabelData::QskLabelData( const QString& text, const QskIcon& icon )
: m_text( text )
, m_icon( icon )
{
}
bool QskLabelData::operator==( const QskLabelData& other ) const noexcept
{
return ( m_text == other.m_text )
&& ( m_icon == other.m_icon );
}
void QskLabelData::setText( const QString& text )
{
m_text = text;
}
void QskLabelData::setIconSource( const QUrl& source )
{
m_icon.setSource( source );
}
void QskLabelData::setIcon( const QskIcon& icon )
{
m_icon = icon;
}
QskHashValue QskLabelData::hash( QskHashValue seed ) const
{
const auto hash = qHash( m_text, seed );
return m_icon.hash( hash );
}
#ifndef QT_NO_DEBUG_STREAM
#include <qdebug.h>
QDebug operator<<( QDebug debug, const QskLabelData& labelData )
{
QDebugStateSaver saver( debug );
debug.nospace();
const auto icon = labelData.icon();
const auto text = labelData.text();
debug << "Label" << "( ";
if ( !text.isEmpty() )
{
debug << text;
if ( !icon.isNull() )
debug << ", ";
}
if ( !icon.source().isEmpty() )
{
debug << icon.source();
}
else if ( !icon.maybeGraphic().isNull() )
{
debug << "I:" << icon.maybeGraphic().hash( 0 );
}
debug << " )";
return debug;
}
#endif
#include "moc_QskLabelData.cpp"