~ci-train-bot/unity8/unity8-ubuntu-zesty-2404

« back to all changes in this revision

Viewing changes to tests/mocks/libusermetrics/UserMetrics.cpp

  • Committer: Nick Dedekind
  • Date: 2016-11-28 13:46:55 UTC
  • mfrom: (2704 unity8)
  • mto: This revision was merged to the branch mainline in revision 2752.
  • Revision ID: nick.dedekind@canonical.com-20161128134655-vd70a64pbci1b4oc
merged with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
    void setUsername(const QString &username);
89
89
 
90
90
protected:
 
91
    void findAndSetUsername(const QString &username);
 
92
 
91
93
    void nextFakeData();
92
94
 
93
95
    void generateFakeData();
94
96
 
95
97
    void loadFakeData();
96
98
 
 
99
    void loadUserMetricsData();
 
100
 
97
101
    void finishSetFakeData();
98
102
 
99
103
private:
131
135
}
132
136
 
133
137
UserMetricsDataPrivate::UserMetricsDataPrivate(UserMetricsData *parent) :
134
 
        q_ptr(parent), m_firstColor(this), m_secondColor(this)
 
138
        q_ptr(parent), m_label(""), m_firstColor(this), m_secondColor(this)
135
139
{
136
140
    m_length = calculateLength();
137
141
}
229
233
{
230
234
}
231
235
 
232
 
void UserMetricsPrivate::setUsername(const QString &username)
 
236
void UserMetricsPrivate::findAndSetUsername(const QString &username)
233
237
{
234
 
    if (m_username == username && m_newData) {
235
 
        return;
236
 
    }
237
 
 
238
238
    m_username = username;
239
239
 
240
240
    m_dataIndex = m_fakeData.constFind(m_username);
243
243
        m_dataIndex = m_fakeData.constFind("");
244
244
    }
245
245
 
 
246
    m_newData = *m_dataIndex;
 
247
}
 
248
 
 
249
void UserMetricsPrivate::setUsername(const QString &username)
 
250
{
 
251
    if (m_username == username && m_newData) {
 
252
        return;
 
253
    }
 
254
 
 
255
    findAndSetUsername(username);
246
256
    loadFakeData();
247
257
 
248
258
    q_ptr->usernameChanged(m_username);
332
342
 
333
343
void UserMetricsPrivate::loadFakeData()
334
344
{
335
 
    m_newData = *m_dataIndex;
336
345
 
337
346
    bool oldLabelEmpty = m_label.isEmpty();
338
347
    bool newLabelEmpty = m_newData->label().isEmpty();
351
360
    // we emit no signal if the data has stayed empty
352
361
}
353
362
 
354
 
void UserMetricsPrivate::finishSetFakeData()
 
363
void UserMetricsPrivate::loadUserMetricsData()
355
364
{
356
 
    bool oldLabelEmpty = m_label.isEmpty();
357
 
    bool newLabelEmpty = m_newData->label().isEmpty();
358
 
 
359
365
    m_label = m_newData->label();
360
366
    m_firstColor = m_newData->firstColor();
361
367
    m_firstMonth.setVariantList(m_newData->firstMonth());
362
368
    m_secondColor = m_newData->secondColor();
363
369
    m_secondMonth.setVariantList(m_newData->secondMonth());
 
370
    m_currentDay = m_newData->length();
 
371
}
364
372
 
 
373
void UserMetricsPrivate::finishSetFakeData()
 
374
{
 
375
    bool oldLabelEmpty = m_label.isEmpty();
 
376
    bool newLabelEmpty = m_newData->label().isEmpty();
365
377
    bool currentDayChanged = m_currentDay != m_newData->length();
366
 
    m_currentDay = m_newData->length();
 
378
 
 
379
    loadUserMetricsData();
367
380
 
368
381
    q_ptr->labelChanged(m_label);
369
382
    if (currentDayChanged)
370
383
    {
371
 
        q_ptr->currentDayChanged(m_currentDay);
 
384
       q_ptr->currentDayChanged(m_currentDay);
372
385
    }
373
386
 
374
387
    if (oldLabelEmpty && !newLabelEmpty)
396
409
        }
397
410
    }
398
411
 
 
412
    m_newData = *m_dataIndex;
399
413
    loadFakeData();
400
414
}
401
415
 
464
478
    d_ptr->finishSetFakeData();
465
479
}
466
480
 
 
481
void UserMetrics::reset()
 
482
{
 
483
    d_ptr->findAndSetUsername("");
 
484
    d_ptr->loadUserMetricsData();
 
485
}
 
486
 
467
487
/**
468
488
 * Factory methods
469
489
 */