9#include "datasource/ChartDataSource.h"
14 setFlag(ItemHasContents,
true);
31 Q_EMIT nameSourceChanged();
36 return m_shortNameSource;
47 Q_EMIT shortNameSourceChanged();
62 disconnect(m_colorSource, &ChartDataSource::dataChanged,
this, &Chart::dataChanged);
68 connect(m_colorSource, &ChartDataSource::dataChanged,
this, &Chart::dataChanged);
72 Q_EMIT colorSourceChanged();
77 return DataSourcesProperty{
84 &Chart::replaceSource,
85 &Chart::removeLastSource,
91 return m_valueSources;
100 m_valueSources.
insert(index, source);
102 connect(source, &ChartDataSource::dataChanged,
this, &Chart::dataChanged);
105 Q_EMIT valueSourcesChanged();
108void Chart::removeValueSource(
int index)
110 if (index < 0 || index >= m_valueSources.
count()) {
114 m_valueSources.
at(index)->disconnect(
this);
115 m_valueSources.
remove(index);
118 Q_EMIT valueSourcesChanged();
121void Chart::removeValueSource(
QObject *source)
123 auto itr = std::find_if(m_valueSources.
begin(), m_valueSources.
end(), [source](
QObject *dataSource) {
124 return dataSource == source;
127 if (itr != m_valueSources.
end()) {
128 (*itr)->disconnect(
this);
129 m_valueSources.
erase(itr);
133 Q_EMIT valueSourcesChanged();
138 return m_indexingMode;
141void Chart::setIndexingMode(IndexingMode newIndexingMode)
143 if (newIndexingMode == m_indexingMode) {
147 m_indexingMode = newIndexingMode;
149 Q_EMIT indexingModeChanged();
157void Chart::setHighlight(
int newHighlight)
159 if (newHighlight == m_highlight) {
163 m_highlight = newHighlight;
165 Q_EMIT highlightChanged();
168void Chart::resetHighlight()
173void Chart::componentComplete()
182 color.
setHslF(color.hueF(), color.saturationF() * 0.5, color.lightnessF() * 0.5, color.alphaF() * 0.5);
188 auto chart =
reinterpret_cast<Chart *
>(list->
data);
189 chart->insertValueSource(chart->valueSources().size(), source);
198 return reinterpret_cast<Chart *
>(
list->
data)->m_valueSources.
at(index);
204 std::for_each(chart->m_valueSources.cbegin(), chart->m_valueSources.cend(), [chart](
ChartDataSource *source) {
205 source->disconnect(chart);
207 chart->m_valueSources.clear();
208 Q_EMIT chart->dataChanged();
211void Chart::replaceSource(DataSourcesProperty *list, qsizetype index,
ChartDataSource *source)
214 Q_ASSERT(index > 0 && index < chart->m_valueSources.
size());
215 chart->m_valueSources.at(index)->disconnect(chart);
216 chart->m_valueSources.replace(index, source);
218 connect(source, &ChartDataSource::dataChanged, chart, &Chart::dataChanged);
219 Q_EMIT chart->dataChanged();
222void Chart::removeLastSource(DataSourcesProperty *list)
225 chart->removeValueSource(chart->m_valueSources.size() - 1);
228#include "moc_Chart.cpp"
Abstract base class for data sources.
Abstract base class for all charts.
QColor desaturate(const QColor &input)
Desaturate and de-emphasise a color.
ChartDataSource * shortNameSource
The data source to use for short names of chart items.
QQmlListProperty< ChartDataSource > valueSources
The data sources providing the data this chart needs to render.
ChartDataSource * nameSource
The data source to use for names of chart items.
ChartDataSource * colorSource
The data source to use for colors of chart items.
int highlight
The index of a value source to highlight.
virtual void onDataChanged()=0
Called when the data of a value source changes.
IndexingMode
How to index color and name sources relative to the different value sources.
IndexingMode indexingMode
The indexing mode used for indexing colors and names.
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QColor convertTo(Spec colorSpec) const const
void setHslF(float h, float s, float l, float a)
const_reference at(qsizetype i) const const
qsizetype count() const const
iterator erase(const_iterator begin, const_iterator end)
iterator insert(const_iterator before, parameter_type value)
void remove(qsizetype i, qsizetype n)
qsizetype size() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void destroyed(QObject *obj)
bool disconnect(const QMetaObject::Connection &connection)
virtual void componentComplete() override
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)