Esempio n. 1
0
TagModelItem *TagFilterModel::findItem(const QString &tag)
{
    const int row = findRow(tag);
    if (!isValidRow(row))
        return nullptr;
    return &m_tagItems[row];
}
Esempio n. 2
0
SimpleListModelBase::SimpleListModelBase(int columns, QObject *parent)
    : QAbstractListModel(parent), d(new Data)
{
    d->columns = columns;
    connect(this, &QAbstractItemModel::dataChanged,
            this, [this] (const QModelIndex &tl, const QModelIndex &br)
    {
        emit rowChanged(tl.row());
        if (tl.row() != br.row())
            emit rowChanged(br.row());
    });

    connect(this, &SimpleListModelBase::dataChanged, this,
            [=] (int row, const QVector<int> &roles)
    {
        if (!isValidRow(row))
            return;
        const auto tl = index(row, 0), br = index(row, d->columns - 1);
        emit QAbstractListModel::dataChanged(tl, br, roles);
    });

    auto signal = &SimpleListModelBase::contentsChanged;
    using M = QAbstractItemModel;
    connect(this, &M::modelReset, this, signal);
    connect(this, &M::dataChanged, this, signal);
    connect(this, &M::rowsInserted, this, signal);
    connect(this, &M::rowsRemoved, this, signal);
    connect(this, &M::rowsMoved, this, signal);
    connect(this, &M::layoutChanged, this, signal);
}
Esempio n. 3
0
QModelIndex TagFilterModel::index(const QString &tag) const
{
    const int row = findRow(tag);
    if (!isValidRow(row))
        return {};
    return index(row, 0, QModelIndex());
}
Esempio n. 4
0
QString TagFilterModel::tag(const QModelIndex &index) const
{
    if (!index.isValid())
        return {};
    const int row = index.internalId();
    Q_ASSERT(isValidRow(row));
    return m_tagItems[row].tag();
}
Esempio n. 5
0
void SubCompModel::setCurrentCaption(const SubCapt *caption) {
	if (!d->visible) {
		d->pended = caption;
	} else {
		d->pended = 0;
		const int row = caption ? caption->index : -1;
		if (d->curRow == row)
			return;
		const int old = d->curRow;
		d->curRow = row;
		if (isValidRow(d->curRow))
			ITEM(d->curRow)->setFont(d->curFont);
		if (isValidRow(old))
			ITEM(old)->setFont(d->defFont);
		emit currentRowChanged(d->curRow);
	}
}
Esempio n. 6
0
void TagFilterModel::torrentTagAdded(BitTorrent::TorrentHandle *const torrent, const QString &tag)
{
    if (torrent->tags().count() == 1)
        untaggedItem()->decreaseTorrentsCount();

    const int row = findRow(tag);
    Q_ASSERT(isValidRow(row));
    TagModelItem &item = m_tagItems[row];

    item.increaseTorrentsCount();
    const QModelIndex i = index(row, 0, QModelIndex());
    emit dataChanged(i, i);
}
void Abstract_Widget_List::remove(int i)
{
    if ( isValidRow(i) )
    {
        p->widgets.removeAt(i);
        p->table->removeRow(i);
        if ( i == 0 && !p->widgets.isEmpty() )
            p->table->cellWidget(0,1)->setEnabled(false);
        else if ( i != 0 && i == count() )
            p->table->cellWidget(count()-1,2)->setEnabled(false);

        emit removed(i);
    }
}
Esempio n. 8
0
 bool isValidSudoku(vector<vector<char>>& board) {
     for(int i = 0; i < 9; i++){
         if( !isValidRow(board, i) ) return false;
     }
     for(int i = 0; i < 9; i++){
         if( !isValidColumn(board, i) ) return false;
     }
     for(int i = 0; i < 9; i += 3){
         for(int j = 0; j < 9; j += 3){
             if( !isValidSubMatrix(board, i, j) ) return false;
         }
     }
     return true;
 }
Esempio n. 9
0
 bool search(vector<vector<char> > &board, int x, int y, const string & word, int cur, 
             vector<vector<bool > > &visited) {
     if ( word[cur] == board[x][y]) {
         if ( cur == word.length()-1) return true;
         visited[x][y] = true;
         for(int i=0; i < numDirs; ++i) {
             int n_x = x + delta_x[i];
             int n_y = y + delta_y[i];//BUG TYPO x + delta_y
             if ( isValidRow(n_x, board) && isValidCol(n_y, board)) {
                 if (!visited[n_x][n_y] && search(board, n_x, n_y, word, cur+1, visited) ) { //BUG: missing visited
                     return true;
                 }
             }
         }
         visited[x][y] = false;
     }
     return false;
 }
Esempio n. 10
0
    bool isValidSudoku(vector<vector<char>>& board) {
        for (int i = 0; i < 9; ++i) {
            if (!isValidRow(board, i))
                return false;
        }

        for (int j = 0; j < 9; ++j) {
            if (!isValidCol(board, j))
                return false;
        }

        for (int r = 0; r < 7; r += 3) {
            for (int c = 0; c < 7; c += 3) {
                if (!isValidSubBox(board, r, c))
                    return false;
            }
        }

        return true;
    }
Esempio n. 11
0
QVariant TagFilterModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid() || (index.column() != 0))
        return {};

    const int row = index.internalId();
    Q_ASSERT(isValidRow(row));
    const TagModelItem &item = m_tagItems[row];

    switch (role) {
    case Qt::DecorationRole:
        return GuiIconProvider::instance()->getIcon("inode-directory");
    case Qt::DisplayRole:
        return QString(QLatin1String("%1 (%2)"))
               .arg(tagDisplayName(item.tag())).arg(item.torrentsCount());
    case Qt::UserRole:
        return item.torrentsCount();
    default:
        return {};
    }
}
QWidget *Abstract_Widget_List::widget(int i)
{
    if ( isValidRow(i) )
        return p->widgets[i];
    return 0;
}
		TITANIUM_FUNCTION(ResultSet, isValidRow)
		{
			TITANIUM_ASSERT(arguments.size() == 0);
			return get_context().CreateBoolean(isValidRow());
		}
Esempio n. 14
0
 bool hasNext() const {
     return isValidRow(next());
 }
Esempio n. 15
0
void TagFilterModel::removeFromModel(int row)
{
    Q_ASSERT(isValidRow(row));
    m_tagItems.removeAt(row);
}
Esempio n. 16
0
 bool hasPrevious() const {
     return isValidRow(previous());
 }
Esempio n. 17
0
QModelIndex TagFilterModel::index(int row, int, const QModelIndex &) const
{
    if (!isValidRow(row))
        return {};
    return createIndex(row, 0, row);
}