示例#1
0
//private
void ReversiGame::setBoard(QSharedPointer<ReversiBoard> nBoard)
{
    if (nBoard.isNull())
        return;

    ReversiBoard * raw = nBoard.data();
    connect(raw,
            SIGNAL(moveMade(CELL_STATE,CELL_STATE)),
            this,
            SLOT(handleTurnTaken(CELL_STATE,CELL_STATE)));
    connect(raw,
            SIGNAL(moveMade(CELL_STATE,CELL_STATE)),
            this,
            SIGNAL(turnTaken(CELL_STATE,CELL_STATE)));
    connect(raw,
            SIGNAL(gameOver(CELL_STATE)),
            this,
            SLOT(handleGameOver(CELL_STATE)));
    connect(raw,
            SIGNAL(gameOver(CELL_STATE)),
            this,
            SIGNAL(gameOver(CELL_STATE)));
    connect(raw,
            SIGNAL(countChanged(quint16,quint16)),
            this,
            SLOT(handleScoreChanged(quint16,quint16)));
    connect(raw,
            SIGNAL(countChanged(quint16,quint16)),
            this,
            SIGNAL(scoreChanged(quint16,quint16)));

    this->board = nBoard;
}
示例#2
0
void PlaylistHistory::deleteCurrentPlaylist()
{
    if (!inRange(m_currentIndex))
        return;

    int count = m_playlists->count();

    if (count == 1) {
        delete m_playlists->takeAt(m_currentIndex);
        m_currentIndex = -1;
        emit countChanged();
        return;
    }
    // current playlist is the last one in list
    if (m_currentIndex == count - 1) {
        delete m_playlists->takeAt(m_currentIndex);
        m_currentIndex--;
        emit currentChanged(m_playlists->at(m_currentIndex));
        emit countChanged();
        return;
    }
    // current playlist is in the middle
    if ((m_currentIndex >= 0) && (m_currentIndex < (count - 1))) {
        delete m_playlists->takeAt(m_currentIndex);
        emit currentChanged(m_playlists->at(m_currentIndex));
        emit countChanged();
        return;
    }
}
SailorgramContactsModel::SailorgramContactsModel(QObject *parent) : QIdentityProxyModel(parent)
{
    this->_telegramcontactsmodel = new TelegramContactsModel(this);
    this->setSourceModel(this->_telegramcontactsmodel);

    connect(this->_telegramcontactsmodel, SIGNAL(telegramChanged()), this, SIGNAL(telegramChanged()));
    connect(this->_telegramcontactsmodel, SIGNAL(countChanged()), this, SIGNAL(countChanged()));
    connect(this->_telegramcontactsmodel, SIGNAL(initializingChanged()), this, SIGNAL(initializingChanged()));
}
void BooksCoverModel::setSource(QObject* aSrc)
{
    QAbstractItemModel* oldM = sourceModel();
    if (aSrc != oldM) {
        const int oldCount = count();
        if (oldM) {
            BooksShelf* oldShelf = qobject_cast<BooksShelf*>(oldM);
            if (oldShelf) {
                const int n = oldShelf->count();
                for (int i=0; i<n; i++) {
                    onBookRemoved(oldShelf->bookAt(i));
                }
            }
            oldM->disconnect(this);
        }
        if (aSrc) {
            QAbstractItemModel* newM = qobject_cast<QAbstractItemModel*>(aSrc);
            if (newM) {
                setSourceModel(newM);
                BooksShelf* newShelf = qobject_cast<BooksShelf*>(newM);
                if (newShelf) {
                    const int n = newShelf->count();
                    for (int i=0; i<n; i++) {
                        onBookAdded(newShelf->bookAt(i));
                    }
                    connect(newShelf,
                        SIGNAL(bookAdded(BooksBook*)),
                        SLOT(onBookAdded(BooksBook*)));
                    connect(newShelf,
                        SIGNAL(bookRemoved(BooksBook*)),
                        SLOT(onBookRemoved(BooksBook*)));
                }
                connect(newM,
                    SIGNAL(rowsInserted(QModelIndex,int,int)),
                    SIGNAL(countChanged()));
                connect(newM,
                    SIGNAL(rowsRemoved(QModelIndex,int,int)),
                    SIGNAL(countChanged()));
                connect(newM,
                    SIGNAL(modelReset()),
                    SIGNAL(countChanged()));
            } else {
                HDEBUG("unexpected source" << aSrc);
                setSourceModel(NULL);
            }
        } else {
            setSourceModel(NULL);
        }
        if (oldCount != count()) {
            Q_EMIT countChanged();
        }
    }
}
示例#5
0
SortFilterModel::SortFilterModel(QObject *parent)
    : QSortFilterProxyModel(parent)
{
    setObjectName(QStringLiteral("SortFilterModel"));
    setDynamicSortFilter(true);
    connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)),
            this, SIGNAL(countChanged()));
    connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)),
            this, SIGNAL(countChanged()));
    connect(this, SIGNAL(modelReset()),
            this, SIGNAL(countChanged()));
    connect(this,  SIGNAL(countChanged()), this, SLOT(syncRoleNames()));
}
示例#6
0
	void StatusSummaryItem::setCount(uint count) {
		if (m_count != count)
			emit countChanged();
		m_count = count;

		updateLabel();
	}
void ComicsModel::loadAll()
{
    clear();

    QStringList comicsList = idLoadList();

    Comic *comic;

    beginInsertRows(QModelIndex(), 0, comicsList.count() - 1);

    for (int i = 0; i < comicsList.size(); ++i) {
        comic = factory->create(comicsList.at(i), this);

        if (comic == NULL)
            return;

        comic->load();

        connect(comic, SIGNAL(favoriteChanged(Comic*)), this, SLOT(emitFavoriteChanged(Comic*)));
        connect(comic, SIGNAL(newStripChanged(Comic*)), this, SLOT(emitNewStripChanged(Comic*)));
        connect(comic, SIGNAL(errorChanged(Comic*)), this, SLOT(emitErrorChanged(Comic*)));
        connect(comic, SIGNAL(fetchingChanged(Comic*)), this, SLOT(emitFetchingChanged(Comic*)));
        connect(comic, SIGNAL(fetchingProgressChanged(Comic*)), this, SLOT(emitFetchingProgressChanged(Comic*)));

        m_list.append(comic);
    }

    endInsertRows();

    // hack to fix the initialization of the cover...
    emit countChanged();
}
bool DailymotionAccountModel::addAccount(const QString &userId, const QString &username, const QString &accessToken,
                                         const QString &refreshToken, const QString &scopes) {
                                     
    QSqlField userIdField("userId", QVariant::String);
    userIdField.setValue(userId);
    
    QSqlField usernameField("username", QVariant::String);
    usernameField.setValue(username);
        
    QSqlField accessTokenField("accessToken", QVariant::String);
    accessTokenField.setValue(accessToken);
    
    QSqlField refreshTokenField("refreshToken", QVariant::String);
    refreshTokenField.setValue(refreshToken);
    
    QSqlField scopesField("scopes", QVariant::String);
    scopesField.setValue(scopes);

    QSqlRecord record;
    record.append(userIdField);
    record.append(usernameField);
    record.append(accessTokenField);
    record.append(refreshTokenField);
    record.append(scopesField);
    
    if (insertRecord(-1, record)) {
        Dailymotion::instance()->setUserId(userId);
        const int count = rowCount();
        emit dataChanged(index(0, 0), index(count - 1, columnCount() - 1));
        emit countChanged(count);
        return true;
    }
    
    return false;
}
示例#9
0
void GameMovesRegistry::push(IMoveCommand::UPtr newMove)
{
    Q_ASSERT(newMove != nullptr && "Null pointer is not allowed");
    m_undoneCmnds.push_back(std::move(newMove));
    redo();
    emit countChanged(count());
}
示例#10
0
void ApplicationManager::add(ApplicationInfo *application) {
    if (!application || m_runningApplications.contains(application)) {
        return;
    }

    beginInsertRows(QModelIndex(), m_runningApplications.size(), m_runningApplications.size());
    m_runningApplications.append(application);
    endInsertRows();
    Q_EMIT applicationAdded(application->appId());
    Q_EMIT countChanged();
    if (count() == 1) Q_EMIT emptyChanged(isEmpty()); // was empty but not anymore

    connect(application, &ApplicationInfo::sessionChanged, this, [application, this]() {
        QModelIndex appIndex = findIndex(application);
        if (!appIndex.isValid()) return;
        Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleSession);
    });
    connect(application, &ApplicationInfo::focusedChanged, this, [application, this]() {
        QModelIndex appIndex = findIndex(application);
        if (!appIndex.isValid()) return;
        Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleFocused);
    });
    connect(application, &ApplicationInfo::stateChanged, this, [application, this]() {
        QModelIndex appIndex = findIndex(application);
        if (!appIndex.isValid()) return;
        Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleState);
    });
}
示例#11
0
void LauncherItem::setCount(int count)
{
    if (m_count != count) {
        m_count = count;
        Q_EMIT countChanged(count);
    }
}
示例#12
0
void FavoriteAppsModel::addFavorite(const QString &favoriteId)
{
    QString serviceId = serviceIdFromFavoriteId(favoriteId);
    if (serviceId.isEmpty()) {
        return;
    }
    KService::Ptr service = KService::serviceByStorageId(serviceId);
    if (service.isNull()) {
        kWarning() << "Could not find a service for" << serviceId;
        return;
    }
    int rank;
    if (!m_favoriteList.isEmpty()) {
        rank = m_favoriteList.last().rank + 1;
    } else {
        rank = 0;
    }
    FavoriteInfo info = { rank, service };

    int row = m_favoriteList.count();
    beginInsertRows(QModelIndex(), row, row);
    m_favoriteList << info;
    endInsertRows();
    countChanged();

    KConfigGroup baseGroup(m_config, "favorites");
    KConfigGroup group(&baseGroup, QString("favorite-%1").arg(rank));
    group.writeEntry("serviceId", serviceId);
    baseGroup.sync();
}
示例#13
0
void EntryListModel::clear(){
    beginResetModel();
    m_entries.clear();
    m_deleted.clear();
    endResetModel();
    emit countChanged(rowCount());
}
示例#14
0
void Transfers::addDownloadTransfer(const QString &service, const QString &trackId, const QString &streamId,
                                    const QUrl &streamUrl, const QString &title, const QString &category,
                                    const QString &customCommand, bool customCommandOverrideEnabled) {
    Logger::log(QString("Transfers::addDownloadTransfer(). Service: %1, Track ID: %2, Stream ID: %3, Stream URL: %4, Title: %5, Category: %6, Command: %7").arg(service).arg(trackId).arg(streamId).arg(streamUrl.toString())
                .arg(title).arg(category).arg(customCommand));
    Transfer *transfer = createTransfer(service, this);
    transfer->setNetworkAccessManager(m_nam);
    transfer->setId(Utils::createId());
    transfer->setDownloadPath(Settings::downloadPath() + ".incomplete/" + transfer->id());
    transfer->setFileName(title);
    transfer->setCategory(category);
    transfer->setTrackId(trackId);
    transfer->setStreamId(streamId);
    transfer->setStreamUrl(streamUrl);
    transfer->setTitle(title);
    transfer->setCustomCommand(customCommand);
    transfer->setCustomCommandOverrideEnabled(customCommandOverrideEnabled);
    
    connect(transfer, SIGNAL(statusChanged()), this, SLOT(onTransferStatusChanged()));
    
    m_transfers << transfer;
    emit countChanged(count());
    emit transferAdded(transfer);
    
    if (Settings::startTransfersAutomatically()) {
        transfer->queue();
    }
}
示例#15
0
void FavoriteAppsModel::setConfig(const KSharedConfig::Ptr &ptr)
{
    m_config = ptr;

    KConfigGroup baseGroup(m_config, "favorites");

    // get all the favorites
    QMap<int, KService::Ptr> favoriteMap;
    foreach (const QString &favoriteGroup, baseGroup.groupList()) {
        if (favoriteGroup.startsWith("favorite-")) {
            KConfigGroup favoriteConfig(&baseGroup, favoriteGroup);
            int rank = favoriteGroup.split("-").last().toInt();
            QString id = favoriteConfig.readEntry("serviceId");
            KService::Ptr service = KService::serviceByStorageId(id);
            if (!service.isNull()) {
                favoriteMap.insert(rank, service);
            }
        }
    }

    beginResetModel();
    m_favoriteList.clear();
    auto it = favoriteMap.constBegin(), end = favoriteMap.constEnd();
    for (; it != end; ++it) {
        FavoriteInfo info = { it.key(), it.value() };
        m_favoriteList << info;
    }
    endResetModel();
    countChanged();
}
/*!
    \qmlproperty int Ratings::count

    This property holds the total number of individual user ratings
    used in determining the overall ratings \l average.
*/
void QDeclarativeRatings::setCount(int count)
{
    if (m_ratings.count() != count) {
        m_ratings.setCount(count);
        emit countChanged();
    }
}
示例#17
0
// insert value at row
void ValueModel::insert(int row, const QJSValue &value)
{
    beginInsertRows(QModelIndex(), row, row);
    m_data.insert(row, value);
    endInsertRows();
    emit countChanged(m_data.count());
}
示例#18
0
void CUndoRedoStack::remove(QUndoCommand* cmd)
{
    if(!cmd)
        return;

    int inUndo = d->undoStack.indexOf(cmd);
    int inRedo = inUndo >= 0 ? -1 : d->redoStack.indexOf(cmd);

    CUndoRedoCmdBase* cmd2 = dynamic_cast<CUndoRedoCmdBase*>(cmd);
    if(cmd2)
        removeCommand(cmd2);

    if(inUndo >= 0)
    {
        d->undoStack.remove(inUndo);
        emit canUndoChanged(d->undoStack.count());
    }
    else if(inRedo >= 0)
    {
        d->redoStack.remove(inRedo);
        emit canRedoChanged(d->redoStack.count());
    }

    emit countChanged(count());
}
void TrackerDocumentProvider::searchFinished()
{
    QSparqlResult *r = qobject_cast<QSparqlResult*>(sender());
    if (!r->hasError()) {
        // d->model->clear();
        // Mark all current entries in the model dirty.
        d->model->setAllItemsDirty(true);
        while (r->next()) {
            // This will remove the dirty flag for already
            // existing entries.
            d->model->addItem(
                r->binding(0).value().toString(),
                r->binding(1).value().toString(),
                r->binding(1).value().toString().split('.').last(),
                r->binding(2).value().toInt(),
                r->binding(3).value().toDateTime(),
                r->binding(4).value().toString()
            );
        }
        // Remove all entries with the dirty mark.
        d->model->removeItemsDirty();
        if (!d->ready) {
            d->ready = true;
            emit readyChanged();
        }
    }

    emit countChanged();
}
void BackgroundListModel::reload(const QStringList &selected)
{
    if (!m_packages.isEmpty()) {
        beginRemoveRows(QModelIndex(), 0, m_packages.count() - 1);
        m_packages.clear();
        endRemoveRows();
        emit countChanged();
    }

    if (!m_wallpaper) {
        return;
    }

    if (!selected.isEmpty()) {
        qDebug() << "selected" << selected;
        processPaths(selected);
    }

    const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("wallpapers/"), QStandardPaths::LocateDirectory);
    qDebug() << " WP : -------" << dirs;

    BackgroundFinder *finder = new BackgroundFinder(m_wallpaper.data(), dirs);
    connect(finder, &BackgroundFinder::backgroundsFound, this, &BackgroundListModel::backgroundsFound);
    m_findToken = finder->token();
    finder->start();
    m_removableWallpapers = QSet<QString>::fromList(selected);
}
void DeclarativeTabModel::tabsAvailable(QList<Tab> tabs)
{
    beginResetModel();
    int oldCount = count();
    m_tabs.clear();
    m_tabs = tabs;

    if (m_tabs.count() > 0) {
        loadTabOrder();
        qSort(m_tabs.begin(), m_tabs.end(), DeclarativeTabModel::tabSort);
        m_activeTab = m_tabs.at(0);
        m_tabs.removeAt(0);
    } else {
        m_activeTab = Tab();
        emit tabsCleared();
    }

    endResetModel();

    if (count() != oldCount) {
        emit countChanged();
    }

    int maxTabId = DBManager::instance()->getMaxTabId();
    if (m_nextTabId != maxTabId + 1) {
        m_nextTabId = maxTabId + 1;
        emit nextTabIdChanged();
    }

    // Startup should be synced to this.
    if (!m_loaded) {
        m_loaded = true;
        emit loadedChanged();
    }
}
示例#22
0
void GamesListModel::insertListing(GameListing *item)
{
    beginInsertRows(QModelIndex(), items.count(), items.count());
    items.append(item);
    endInsertRows();
    emit countChanged(items.count());
}
/*!
    Called before visibleDateChanged() is emitted.

    This function is called even when just the day has changed, in which case
    it does nothing.

    The \a force parameter is used when the locale has changed; the month
    shown doesn't change, but the days displayed do.
    The \a previousDate parameter is ignored when \a force is true.
*/
void QQuickCalendarModel::populateFromVisibleDate(const QDate &previousDate, bool force)
{
    // We don't need to populate if the year and month haven't changed.
    if (!force && mVisibleDate.year() == previousDate.year() && mVisibleDate.month() == previousDate.month())
        return;

    // Since our model is of a fixed size, we fill it once and assign values each time
    // the month changes, instead of clearing and appending each time.
    bool isEmpty = mVisibleDates.isEmpty();
    if (isEmpty) {
        beginResetModel();
        mVisibleDates.fill(QDate(), daysOnACalendarMonth);
    }

    // The actual first (1st) day of the month.
    QDate firstDayOfMonthDate(mVisibleDate.year(), mVisibleDate.month(), 1);
    int difference = ((firstDayOfMonthDate.dayOfWeek() - mLocale.firstDayOfWeek()) + 7) % 7;
    // The first day to display should never be the 1st of the month, as we want some days from
    // the previous month to be visible.
    if (difference == 0)
        difference += daysInAWeek;
    QDate firstDateToDisplay = firstDayOfMonthDate.addDays(-difference);
    for (int i = 0; i < daysOnACalendarMonth; ++i)
        mVisibleDates[i] = firstDateToDisplay.addDays(i);

    mFirstVisibleDate = mVisibleDates.at(0);
    mLastVisibleDate = mVisibleDates.at(mVisibleDates.size() - 1);

    if (!isEmpty) {
        emit dataChanged(index(0, 0), index(rowCount() - 1, 0));
    } else {
        endResetModel();
        emit countChanged(rowCount());
    }
}
示例#24
0
void JobListWidget::execDeleteJob(JobListWidgetItem *jobItem)
{
    if(!jobItem)
    {
        DEBUG << "Null JobListWidgetItem passed.";
        return;
    }

    JobPtr job = jobItem->job();

    QMessageBox::StandardButton confirm =
        QMessageBox::question(this, tr("Confirm action"),
                              tr("Are you sure you want to delete job \"%1\" "
                                 "(this cannot be undone)?")
                                  .arg(job->name()));
    if(confirm != QMessageBox::Yes)
        return;

    bool purgeArchives = false;
    if(!job->archives().isEmpty())
    {
        QMessageBox::StandardButton delArchives =
            QMessageBox::question(this, tr("Confirm action"),
                                  tr("Also delete %1 archives "
                                     "belonging to this job "
                                     "(this cannot be undone)?")
                                      .arg(job->archives().count()));
        if(delArchives == QMessageBox::Yes)
            purgeArchives = true;
    }
    emit deleteJob(job, purgeArchives);
    delete jobItem;
    emit countChanged(count(), visibleItemsCount());
}
示例#25
0
void EntryListModel::add(Entry &entry){
    beginInsertRows(QModelIndex(), m_entries.length(), m_entries.length());
    entry.setId(m_entries.length());
    m_entries << entry;
    endInsertRows();
    emit countChanged(rowCount());
}
 void shouldUpdateCountWhenAddingTab()
 {
     QSignalSpy spy(model, SIGNAL(countChanged()));
     model->add(createTab());
     QCOMPARE(spy.count(), 1);
     QCOMPARE(model->rowCount(), 1);
 }
void DeclarativeTabModel::addTab(const QString& url, const QString &title) {
    if (!LinkValidator::navigable(QUrl(url))) {
        return;
    }
    int tabId = createTab();
    int linkId = createLink(tabId, url, title);

    Tab tab(tabId, Link(linkId, url, "", title), 0, 0);
#if DEBUG_LOGS
    qDebug() << "new tab data:" << &tab;
#endif
    int index = m_tabs.count();
    beginInsertRows(QModelIndex(), index, index);
    m_tabs.append(tab);
    endInsertRows();
    // We should trigger this only when
    // tab is added through new window request. In all other
    // case we should keep the new tab in background.
    updateActiveTab(tab, true);

    emit countChanged();
    emit tabAdded(tabId);

    m_nextTabId = ++tabId;
    emit nextTabIdChanged();

    setWaitingForNewTab(false);
}
示例#28
0
void SearchPluginConfigModel::reload() {
    clear();
    beginResetModel();
    m_items = SearchPluginManager::instance()->plugins();
    endResetModel();
    emit countChanged(rowCount());
}
示例#29
0
PowerModel::PowerModel(QObject *parent)
: QAbstractListModel(parent)
{
    QHash<int, QByteArray> roles;
    roles.insert(Qt::DisplayRole, "label");
    roles.insert(Qt::DecorationRole, "icon");
    setRoleNames(roles);

    PowerAction shutdown;
    shutdown.name = i18nc("an action", "Shutdown");
    shutdown.type = Shutdown;
    shutdown.iconName = "system-shutdown";
    m_powerList.append(shutdown);

    PowerAction restart;
    restart.name = i18nc("an action", "Restart");
    restart.type = Restart;
    restart.iconName = "system-reboot";
    m_powerList.append(restart);

    PowerAction suspend;
    suspend.name = i18nc("an action", "Suspend");
    suspend.type = Suspend;
    suspend.iconName = "system-suspend";
    m_powerList.append(suspend);

    PowerAction hibernate;
    hibernate.name = i18nc("an action", "Hibernate");
    hibernate.type = Hibernate;
    hibernate.iconName = "system-suspend-hibernate";
    m_powerList.append(hibernate);
    emit countChanged();
}
示例#30
0
void DjWidget::setDj(Dj* dj)
{
    qDebug() << Q_FUNC_INFO;
    p->dj = dj;

    connect(p->dj, SIGNAL(countChanged()), this, SLOT(updateView()));
    deactivateDJ();
}