void History::add(int x, int y, int color, const std::vector<Coordinate> &stones) { if(m_curr_idx < (int)(m_history.size() - 1)) m_history.erase(m_history.begin() + m_curr_idx + 1, m_history.end()); m_history.push_back(HistoryItem(x, y, color, stones)); m_curr_idx++; }
void HistoryManager::addHistoryEntry(const QString &url) { QWebSettings *globalSettings = QWebSettings::globalSettings(); if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) return; QUrl cleanUrl(url); // don't store about: urls (home page related) if (cleanUrl.scheme() == QString("about")) return; cleanUrl.setPassword(QString()); cleanUrl.setHost(cleanUrl.host().toLower()); QString checkUrlString = cleanUrl.toString(); HistoryItem item; // NOTE // check if the url has just been visited. // if so, remove previous entry from history, update and prepend it if(historyContains(checkUrlString)) { int index = m_historyFilterModel->historyLocation(checkUrlString); item = m_history.at(index); m_history.removeOne(item); emit entryRemoved(item); item.dateTime = QDateTime::currentDateTime(); item.visitCount++; } else { item = HistoryItem(checkUrlString, QDateTime::currentDateTime()); } m_history.prepend(item); emit entryAdded(item); if (m_history.count() == 1) checkForExpired(); }
fixed ClimbAverageCalculator::GetAverage(fixed time, fixed altitude, fixed average_time) { assert(average_time <= fixed(MAX_HISTORY)); int bestHistory; // Don't update newestValIndex if the time didn't move forward if (newestValIndex < 0 || !history[newestValIndex].IsDefined() || time > history[newestValIndex].time) newestValIndex = newestValIndex < MAX_HISTORY - 1 ? newestValIndex + 1 : 0; // add the new sample history[newestValIndex] = HistoryItem(time, altitude); // initially bestHistory is the current... bestHistory = newestValIndex; // now run through the history and find the best sample // for average period within the average time period for (int i = 0; i < MAX_HISTORY; i++) { if (!history[i].IsDefined()) continue; // outside the period -> skip value if (history[i].time + average_time < time) continue; // is the sample older (and therefore better) than the current found ? if (history[i].time < history[bestHistory].time) bestHistory = i; } // calculate the average ! if (bestHistory != newestValIndex) return (altitude - history[bestHistory].altitude) / (time - history[bestHistory].time); return fixed(0); }
void Player::play(int tid, bool play, bool add_to_history) { cur_artist = artist_list->currentItem(); cur_album = album_list->currentRow() > 0 ? album_list->currentRow() : 0; cur_title = titles_list->currentRow() > 0 ? titles_list->currentRow() : 0; if (add_to_history) { history.push_back(HistoryItem(cur_artist, cur_album, cur_title, tid)); if (history.count() > 100) history.pop_front(); } sqlite3_stmt *trackQuery = 0; char *query = sqlite3_mprintf("SELECT `artist`, `year`, `album`, `track_number`, `title`, `path` FROM `tracks` WHERE `tid`=%u LIMIT 1", tid); prepare(query, &trackQuery, "Failed to Prepare `path` query: "); bool done = false; do { if (step(trackQuery, done, true, "Failed to Step `path` in play: ")) { char *path = sqlite3_mprintf("%s", sqlite3_column_text(trackQuery, 5)); //NOTE: why does sqlite3_column_text return an `unsigned char *`? who uses that?! QString qpath(path); sqlite3_free(path); if (play) { now_playing->setCurrentSource(qpath); now_playing->play(); tick(0); } else now_playing->enqueue(qpath); setQLabelText("%s", trackQuery, 0, mw_artist); setQLabelText("%s", trackQuery, 1, mw_year); setQLabelText("%s", trackQuery, 2, mw_album); setQLabelText("%s", trackQuery, 3, mw_track_number); setQLabelText("%s", trackQuery, 4, mw_title); mw_path->setText(qpath); setWindowTitle(mw_artist->text() + " - " + mw_title->text() + " | Projekt 7"); if (add_to_history) tray_icon->showMessage("Projekt 7 | Now Playing:", mw_artist->text() + " - " + mw_title->text(), QSystemTrayIcon::NoIcon, 5000); } } while (!done); }