void SpriteEditor::onSelectionChanged(const QItemSelection& item1, const QItemSelection& item2)
{
    QModelIndexList indexes = item1.indexes();
    QModelIndex index = indexes.takeFirst();

    QString path = mResourceTreeViewModel.filePath(index);
    QFileInfo fileInfo = QFileInfo (path);
    if (fileInfo.isFile())
    {
        QString filePath = fileInfo.absoluteFilePath();
        filePath.replace(mSpriteData.mResourceDirPath, "");

        mSpriteData.selectSpriteDef(filePath);

        m_ui->infoBox->setEnabled(true);
        QString imagePath = mSpriteData.mResourceDirPath;
        imagePath.append("/").append(mSpriteData.getSelectedImageID());

        blockWidgetSignals(true);
        mpImageViewer->setGridX(mSpriteData.getGridX());
        mpImageViewer->setGridY(mSpriteData.getGridY());
        mpImageViewer->setCenterX(mSpriteData.getCenterX());
        mpImageViewer->setCenterY(mSpriteData.getCenterY());
        mpImageViewer->setImage(imagePath);
        blockWidgetSignals(false);
    }
}
Exemple #2
0
void KateFileTree::switchDocument( const QString &doc )
{
  if (doc.isEmpty()) {
    // no argument: switch to the previous document
    slotDocumentPrev();
  } else if (doc.toInt() > 0 &&
             doc.toInt() <= model()->rowCount( model()->parent(currentIndex()) )) {
    // numerical argument: switch to the nth document
    int i = doc.toInt() - 1;
    KTextEditor::Document *doc =
      model()->data(model()->index(i - 1, 0),
                    KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>();
    if (doc) {
      emit activateDocument(doc);
    }
  } else {
    // string argument: switch to the given file
    QModelIndexList matches =
      model()->match(model()->index(0, 0), Qt::DisplayRole, QVariant(doc), 1, Qt::MatchContains);
    if (!matches.isEmpty()) {
      KTextEditor::Document *doc =
        model()->data(matches.takeFirst(),
                      KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>();
      if (doc) {
        emit activateDocument(doc);
      }
    }
  }
}
/*!
 * This function returns a list of all the selected row indices, in the same
 * order returned by our internal selectedIndexes() function. If nothing is
 * selected, an empty list is returned instead.
 */
QList<int> CSIconListWidget::getSelectedRows() const
{
	QModelIndexList idx = selectedIndexes();
	QList<int> r;

	while(!idx.isEmpty())
		r.append(idx.takeFirst().row());

	return r;
}
Exemple #4
0
void ImagePaletDialog::onSelectionChanged(const QItemSelection& item1, const QItemSelection& item2)
{
    QModelIndexList indexes = item1.indexes();
    QModelIndex index = indexes.takeFirst();

    QString path = mSourceFileTreeViewModel.filePath(index);
    QString rootPath = ResourceManager::GetDirectoryPath(mCurrentFileType);
    rootPath.append("/");
    // we don't want to store absolute path
    path.replace(rootPath, "", Qt::CaseInsensitive);

    mpAnimationModel->setSelectedSourcePath(path);
}
void BtBookshelfTreeModel::resetData() {
    QModelIndexList queue;
    queue.append(QModelIndex());
    do {
        QModelIndex parent(queue.takeFirst());
        emit dataChanged(index(0, 0, parent),
                         index(rowCount(parent) - 1, columnCount() - 1, parent));
        for (int i = 0; i < rowCount(parent); i++) {
            const QModelIndex childIndex(index(i, 0, parent));
            if (rowCount(childIndex) > 0)
                queue.append(childIndex);
        }
    } while (!queue.isEmpty());
}
Exemple #6
0
void CommandDataModel::removeRows(QModelIndexList indices)
{
    while (!indices.empty()) {
        const int row = indices.takeFirst().row();
        if (row >= mCommands.size())
            continue;

        beginRemoveRows(QModelIndex(), row, row);
        mCommands.removeAt(row);

        // Decrement later indices since we removed a row
        for (QModelIndex &index : indices)
            if (index.row() > row)
                index = index.sibling(index.row() - 1, index.column());

        endRemoveRows();
    }
}
void BtTreeModel::deleteSelected(QModelIndexList victims)
{
   QModelIndexList toBeDeleted = victims; // trust me

   while ( ! toBeDeleted.isEmpty() ) 
   {
      QModelIndex ndx = toBeDeleted.takeFirst();
      switch ( type(ndx) ) 
      {
         case BtTreeItem::EQUIPMENT:
            Database::instance().remove( equipment(ndx) );
            break;
         case BtTreeItem::FERMENTABLE:
            Database::instance().remove( fermentable(ndx) );
            break;
         case BtTreeItem::HOP:
            Database::instance().remove( hop(ndx) );
            break;
         case BtTreeItem::MISC:
            Database::instance().remove( misc(ndx) );
            break;
         case BtTreeItem::RECIPE:
            Database::instance().remove( recipe(ndx) );
            break;
         case BtTreeItem::STYLE:
            Database::instance().remove( style(ndx) );
            break;
         case BtTreeItem::YEAST:
            Database::instance().remove( yeast(ndx) );
            break;
         case BtTreeItem::BREWNOTE:
            Database::instance().remove( brewNote(ndx) );
            break;
         case BtTreeItem::FOLDER:
            // This one is weird.
            toBeDeleted += allChildren(ndx);
            removeFolder(ndx);
            break;
         default:
            Brewtarget::logW(QString("deleteSelected:: unknown type %1").arg(type(ndx)));
      }
   }
}
Exemple #8
0
void CommandDataModel::removeRows(QModelIndexList indices)
{
    while (!indices.empty()) {
        const int row = indices.takeFirst().row();
        if (row >= mCommands.size())
            continue;

        beginRemoveRows(QModelIndex(), row, row);
        mCommands.removeAt(row);

        // Decrement later indices since we removed a row
        for (QModelIndexList::iterator i = indices.begin(); i != indices.end();
                                                                            ++i)
            if (i->row() > row)
                *i = i->sibling(i->row() - 1, i->column());

        endRemoveRows();
    }
}
void QQBoardsSettings::deleteBouchot()
{
	QModelIndexList indexes = ui->bouchotListView->selectionModel()->selectedIndexes();
	QStringListModel *model = (QStringListModel *) ui->bouchotListView->model();
	QModelIndex first;

	while(!indexes.isEmpty())
	{
		first = indexes.takeFirst();

		QString bouchotName = first.data().toString();
		if(! m_oldBouchots.contains(bouchotName))
			m_oldBouchots.append(bouchotName);
		m_newBouchots.remove(bouchotName);
		m_bouchots.remove(bouchotName);
		m_listNames.removeOne(bouchotName);

		model->removeRow(first.row());
	}
}
void BookmarksWidget::openInTabsTriggered()
{
    QList<QUrl> urls;
    QModelIndex index = selectedIndex();
    if (!index.isValid())
        return;
    QModelIndexList indexes;
    indexes.append(index);
    while (!indexes.isEmpty()) {
        index = indexes.takeFirst();
        for (int i = 0; i < d->model->rowCount(index); i++) {
            QModelIndex idx = d->model->index(i, 0, index);
            if (d->model->isFolder(idx)) {
                indexes.append(idx);
            } else {
                urls.append(d->model->data(idx, BookmarksModel::UrlRole).toUrl());
            }
        }
    }
    emit open(urls);
}
Exemple #11
0
void QQBoardsSettings::editBouchot()
{
	QModelIndexList indexes = ui->bouchotListView->selectionModel()->selectedIndexes();
	QModelIndex first;

	while(!indexes.isEmpty())
	{
		first = indexes.takeFirst();

		QString bouchotName = first.data().toString();

		QMap<QString, QQBouchot::QQBouchotSettings> *refMap = NULL;
		if(m_newBouchots.contains(bouchotName))
			refMap = &m_newBouchots; // nouveaux
		else if(m_modifBouchots.contains(bouchotName))
			refMap = &m_modifBouchots; // existants deja modifies
		else
			refMap = &m_bouchots; // existants non modifies

		QQBouchotSettingsDialog bouchotSettingsDialog(bouchotName, refMap->value(bouchotName), this);
		bouchotSettingsDialog.setGroups(m_listGroups);

		if(bouchotSettingsDialog.exec() == QDialog::Accepted)
		{
			if(m_newBouchots.contains(bouchotName))
				refMap = &m_newBouchots;
			else
				refMap = &m_modifBouchots;
			QQBouchot::QQBouchotSettings bSettings = bouchotSettingsDialog.bouchotSettings();
			refMap->insert(bouchotName, bSettings);

			//si on a ajoute un nouveau groupe, il faut le prendre en compte
			if(!m_listGroups.contains(bSettings.group()))
				m_listGroups.append(bSettings.group());
		}
	}
}