QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskLabelData.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskLabelData.h"
7#include "QskGraphicProvider.h"
8
9#include <qvariant.h>
10#include <qhashfunctions.h>
11
12static void qskRegisterLabelData()
13{
14 qRegisterMetaType< QskLabelData >();
15
16#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
17 QMetaType::registerEqualsComparator< QskLabelData >();
18#endif
19}
20
21Q_CONSTRUCTOR_FUNCTION( qskRegisterLabelData )
22
23QskLabelData::QskLabelData( const char* text )
24 : m_text( text )
25{
26}
27
28QskLabelData::QskLabelData( const QString& text )
29 : m_text( text )
30{
31}
32
33QskLabelData::QskLabelData( const QskIcon& icon )
34 : m_icon( icon )
35{
36}
37
38QskLabelData::QskLabelData( const QString& text, const QskIcon& icon )
39 : m_text( text )
40 , m_icon( icon )
41{
42}
43
44bool QskLabelData::operator==( const QskLabelData& other ) const noexcept
45{
46 return ( m_text == other.m_text )
47 && ( m_icon == other.m_icon );
48}
49
50void QskLabelData::setText( const QString& text )
51{
52 m_text = text;
53}
54
55void QskLabelData::setIconSource( const QUrl& source )
56{
57 m_icon.setSource( source );
58}
59
60void QskLabelData::setIcon( const QskIcon& icon )
61{
62 m_icon = icon;
63}
64
65QskHashValue QskLabelData::hash( QskHashValue seed ) const
66{
67 const auto hash = qHash( m_text, seed );
68 return m_icon.hash( hash );
69}
70
71QVector< QskLabelData > qskCreateLabelData( const QStringList& list )
72{
73 QVector< QskLabelData > labelData;
74 labelData.reserve( list.size() );
75
76 for ( const auto& text : list )
77 labelData += QskLabelData( text );
78
79 return labelData;
80}
81
82#ifndef QT_NO_DEBUG_STREAM
83
84#include <qdebug.h>
85
86QDebug operator<<( QDebug debug, const QskLabelData& labelData )
87{
88 QDebugStateSaver saver( debug );
89 debug.nospace();
90
91 const auto icon = labelData.icon();
92 const auto text = labelData.text();
93
94 debug << "Label" << "( ";
95 if ( !text.isEmpty() )
96 {
97 debug << text;
98 if ( !icon.isNull() )
99 debug << ", ";
100 }
101
102 if ( !icon.source().isEmpty() )
103 {
104 debug << icon.source();
105 }
106 else if ( !icon.maybeGraphic().isNull() )
107 {
108 debug << "I:" << icon.maybeGraphic().hash( 0 );
109 }
110
111 debug << " )";
112
113 return debug;
114}
115
116#endif
117
118#include "moc_QskLabelData.cpp"