Esempio n. 1
0
void MYIMGTOOL::ExportFiles(const QString &dest)
{
	QModelIndexList indexes = ui.tableView->selectionModel()->selectedRows();

	if (dest.isEmpty() || indexes.isEmpty())
		return;

	MapIndexesToSource(indexes);

	m_pProgressDialog->setWindowTitle("正在导出");

	m_pProgressDialog->setRange(0, indexes.size());

	m_pProgressDialog->setValue(0);

	m_pProgressDialog->open();

	m_pIMGClass->ExportFiles(dest, indexes);

	m_pProgressDialog->close();
}
void EngineManagementWidget::removeEngine()
{
	const QItemSelection selection =
		m_filteredModel->mapSelectionToSource(ui->m_enginesList->selectionModel()->selection());
	QModelIndexList selected = selection.indexes();

	// Can't use std::greater because operator> isn't implemented
	// for QModelIndex.
	std::sort(selected.begin(), selected.end(),
	[](const QModelIndex &a, const QModelIndex &b)
	{
		return b < a;
	});

	if (!selected.isEmpty())
	{
		for (const QModelIndex& index : qAsConst(selected))
			m_engineManager->removeEngineAt(index.row());
		m_hasChanged = true;
	}
}
void TankInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& thisindex) const
{
	CylindersModel *mymodel = qobject_cast<CylindersModel *>(currCombo.model);
	TankInfoModel *tanks = TankInfoModel::instance();
	QModelIndexList matches = tanks->match(tanks->index(0,0), Qt::DisplayRole, currCombo.activeText);
	int row;
	if (matches.isEmpty()) {
		// we need to add this
		tanks->insertRows(tanks->rowCount(), 1);
		tanks->setData(tanks->index(tanks->rowCount() -1, 0), currCombo.activeText);
		row = tanks->rowCount() - 1;
	} else {
		row = matches.first().row();
	}
	int tankSize = tanks->data(tanks->index(row, TankInfoModel::ML)).toInt();
	int tankPressure = tanks->data(tanks->index(row, TankInfoModel::BAR)).toInt();

	mymodel->setData(IDX(CylindersModel::TYPE), currCombo.activeText, Qt::EditRole);
	mymodel->passInData(IDX(CylindersModel::WORKINGPRESS), tankPressure);
	mymodel->passInData(IDX(CylindersModel::SIZE), tankSize);
}
Esempio n. 4
0
void ObjectInspector::objectSelected(QObject *object)
{
  const QAbstractItemModel *model = m_selectionModel->model();
  const QModelIndexList indexList =
  model->match(model->index(0, 0),
               ObjectModel::ObjectRole,
               QVariant::fromValue<QObject*>(object), 1,
               Qt::MatchExactly | Qt::MatchRecursive);
  if (indexList.isEmpty()) {
    return;
  }

  const QModelIndex index = indexList.first();
  m_selectionModel->select(
    index,
    QItemSelectionModel::Select | QItemSelectionModel::Clear |
    QItemSelectionModel::Rows | QItemSelectionModel::Current);
  // TODO: move this to the client side!
  //ui->objectTreeView->scrollTo(index);
  objectSelected(index);
}
Esempio n. 5
0
void RequestsTableWidget::setStateSelected(int state, QDate date, int docId)
{
    QModelIndexList rows = m_view->selectionModel()->selectedRows();

    if (rows.isEmpty()) {
        return;
    }

    QListIterator<QModelIndex> iter(rows);

    while(iter.hasNext()) {
        QModelIndex index = iter.next();
        Request req(index.sibling(index.row(), RequestsModel::IdCol).data().toInt());

        if (!req.setState(state, date, docId)) {
            QMessageBox::critical(this, tr("State"), req.lastError());
        }
    }

    updateFilter();
}
Esempio n. 6
0
void EditTagDialog::ResetPlayCounts() {
  const QModelIndexList sel =
      ui_->song_list->selectionModel()->selectedIndexes();
  if (sel.isEmpty()) return;
  Song* song = &data_[sel.first().row()].original_;
  if (!song->is_valid() || song->id() == -1) return;

  if (QMessageBox::question(
          this, tr("Reset play counts"),
          tr("Are you sure you want to reset this song's statistics?"),
          QMessageBox::Reset, QMessageBox::Cancel) != QMessageBox::Reset) {
    return;
  }

  song->set_playcount(0);
  song->set_skipcount(0);
  song->set_lastplayed(-1);
  song->set_score(0);
  app_->library_backend()->ResetStatisticsAsync(song->id());
  UpdateStatisticsTab(*song);
}
Esempio n. 7
0
void TableGroupBox::cellSelected()//const QModelIndex & /* current */, const QModelIndex & /*previous*/)
{
    QModelIndexList selectedRows = m_table->selectionModel()->selectedRows();

    if (!selectedRows.isEmpty()) {
        // Enable the insert button if the entire row is selected
        m_insertButton->setEnabled(true);

        // If the last row is set to be fixed, then the remove button is
        // disabled for the final row.
        if ( m_lastRowFixed && selectedRows.last().row() == m_table->model()->rowCount() - 1 )
            m_removeButton->setEnabled(false);
        else
            m_removeButton->setEnabled(true);

    } else {
        // Disable the buttons
        m_insertButton->setEnabled(false);
        m_removeButton->setEnabled(false);
    }
}
Esempio n. 8
0
/*
 * QPoint &pos is not used due to when it's used
 * it returns the context menu a bit above the cursor.
 * QCursor::pos is used instead.
 */
void MainWindow::on_systemsTable_customContextMenuRequested(const QPoint &pos){
    // Get row
    QModelIndexList selection = ui->systemsTable->selectionModel()->selectedRows();

    // No rows
    if (selection.isEmpty()) {
        return;
    }
    // Multiple rows
    else if(selection.count() > 1){
        // Disable Edit option
        systemContextMenu.actions().at(1)->setEnabled(false);
    }
    else{
        // Enable Edit option
        systemContextMenu.actions().at(1)->setEnabled(true);
    }

    // Display menu
    systemContextMenu.exec(QCursor::pos());
}
Esempio n. 9
0
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);
}
Esempio n. 10
0
void BtTreeModel::deleteSelected(QModelIndexList victims)
{
   QModelIndexList toBeDeleted = victims; // trust me

   while ( ! toBeDeleted.isEmpty() ) 
   {
      QModelIndex ndx = toBeDeleted.takeFirst();
      switch ( type(ndx) ) 
      {
         case BtTreeItem::RECIPE:
            Database::instance().remove( recipe(ndx) );
            break;
         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::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)));
      }
   }
}
Esempio n. 11
0
void TransactionView::editLabel()
{
    if (!transactionView->selectionModel() || !model)
        return;
    QModelIndexList selection = transactionView->selectionModel()->selectedRows();
    if (!selection.isEmpty()) {
        AddressTableModel* addressBook = model->getAddressTableModel();
        if (!addressBook)
            return;
        QString address = selection.at(0).data(TransactionTableModel::AddressRole).toString();
        if (address.isEmpty()) {

            return;
        }

        int idx = addressBook->lookupAddress(address);
        if (idx != -1) {

            QModelIndex modelIdx = addressBook->index(idx, 0, QModelIndex());

            QString type = modelIdx.data(AddressTableModel::TypeRole).toString();

            EditAddressDialog dlg(
                type == AddressTableModel::Receive
                    ? EditAddressDialog::EditReceivingAddress
                    : EditAddressDialog::EditSendingAddress,
                this);
            dlg.setModel(addressBook);
            dlg.loadRow(idx);
            dlg.exec();
        } else {

            EditAddressDialog dlg(EditAddressDialog::NewSendingAddress,
                                  this);
            dlg.setModel(addressBook);
            dlg.setAddress(address);
            dlg.exec();
        }
    }
}
Esempio n. 12
0
void FilterWidget::filterTextChanged(const QString &s)
{
	emit textChanged(s);

	if (!View)
		return;

#ifdef Q_OS_MAC
	if (text().isEmpty())
#else
	if (NameFilterEdit->text().isEmpty())
#endif
	{
		QModelIndexList selection = View->selectionModel()->selectedIndexes();
		if (!selection.isEmpty())
		{
			qSort(selection);
			View->scrollTo(selection.at(0));
		}
		// clearFocus() is needed to ensure that focus on View wiil be restored
		// even if this function had been called at time KaduWindow was not active
		clearFocus();
		// from qdocs: "[It works] if this widget or one of its parents is the active window"
		View->setFocus(Qt::OtherFocusReason);
#ifndef Q_OS_MAC
		hide();
#endif
	}
	else
	{
		if (!isVisible() || View->selectionModel()->selectedIndexes().count() == 0)
		{
			View->setCurrentIndex(View->model()->index(0, 0));
			View->selectionModel()->select(View->model()->index(0, 0), QItemSelectionModel::SelectCurrent);
		}
#ifndef Q_OS_MAC
		show();
#endif
	}
}
Esempio n. 13
0
void QTableViewCp::copySelected()
{
	QItemSelectionModel * selection = selectionModel();
	QModelIndexList indexes = selection->selectedIndexes();

	if(indexes.size() < 1)
		return;

	// QModelIndex::operator < sorts first by row, then by column.
	// this is what we need
	std::sort(indexes.begin(), indexes.end());

	// You need a pair of indexes to find the row changes
	QModelIndex previous = indexes.first();
	QModelIndex current;
	indexes.removeFirst();
	QString selected_text;

	if(indexes.isEmpty())
	{
		QVariant data = model()->data(previous);
		selected_text.append(data.toString());
	}
	else
	{
		Q_FOREACH(current, indexes)
		{
			QVariant data = model()->data(previous);
			selected_text.append(data.toString());
			if (current.row() != previous.row())
			{
				selected_text.append(QLatin1Char('\n'));
			}
			else
			{
				selected_text.append(QLatin1Char('\t'));
			}
			previous = current;
		}
	}
Esempio n. 14
0
void ManageNamesPage::on_renewNameButton_clicked ()
{
    if(!ui->tableView->selectionModel())
        return;
    QModelIndexList indexes = ui->tableView->selectionModel()->selectedRows(NameTableModel::Name);
    if(indexes.isEmpty())
        return;

    QModelIndex index = indexes.at(0);

    QString name = index.data(Qt::EditRole).toString();
    QString value = index.sibling(index.row(), NameTableModel::Value).data(Qt::EditRole).toString();

    // TODO: Warn if the "expires in" value is still high
    const QString msg
        = tr ("Are you sure you want to renew the name <b>%1</b>?")
        .arg (GUIUtil::HtmlEscape (name));
    const QString title = tr ("Confirm name renewal");

    QMessageBox::StandardButton res;
    res = QMessageBox::question (this, title, msg,
                                 QMessageBox::Yes | QMessageBox::Cancel,
                                 QMessageBox::Cancel);
    if (res != QMessageBox::Yes)
        return;

    WalletModel::UnlockContext ctx(walletModel->requestUnlock ());
    if (!ctx.isValid ())
        return;

    const QString err_msg = walletModel->nameUpdate(name, value, "");

    if (!err_msg.isEmpty())
    {
        if (err_msg == "ABORTED")
            return;

        QMessageBox::critical(this, tr("Name update error"), err_msg);
    }
}
Esempio n. 15
0
void PjModeler::regionViewerSelectionChanged()
{
    QModelIndexList list = regionViewer->selectionModel()->selectedIndexes();
    highlightIndexs(list);

    if(editor->isReadOnly()) return;

    if(list.isEmpty())
    {
        deleteAction->setDisabled(true);
        return;
    }

    bool disable = false;
    foreach (const QModelIndex &it, list)
        if(it.row() < 2)
        {
            disable = true;
            break;
        }
    deleteAction->setDisabled(disable);
}
Esempio n. 16
0
void PublicHubs::slotContextMenu(){
    QItemSelectionModel *sel_model = treeView->selectionModel();
    QModelIndexList indexes = sel_model->selectedRows(0);

    if (indexes.isEmpty())
        return;

    if (proxy){
        QModelIndexList list;
        foreach (QModelIndex i, indexes)
            list.push_back(proxy->mapToSource(i));
        indexes = list;
    }

    WulforUtil *WU = WulforUtil::getInstance();

    QMenu *m = new QMenu();
    QAction *connect = new QAction(WU->getPixmap(WulforUtil::eiCONNECT), tr("Connect"), m);
    QAction *add_fav = new QAction(WU->getPixmap(WulforUtil::eiBOOKMARK_ADD), tr("Add to favorites"), m);
    QAction *copy    = new QAction(WU->getPixmap(WulforUtil::eiEDITCOPY), tr("Copy &address to clipboard"), m);

    m->addActions(QList<QAction*>() << connect << add_fav << copy);

    QAction *ret = m->exec(QCursor::pos());

    m->deleteLater();

    if (ret == connect){
        PublicHubItem * item = NULL;
        MainWindow *MW = MainWindow::getInstance();

        foreach (QModelIndex i, indexes){
            item = reinterpret_cast<PublicHubItem*>(i.internalPointer());

            if (item)
                MW->newHubFrame(item->data(COLUMN_PHUB_ADDRESS).toString(), "");

            item = NULL;
        }
Esempio n. 17
0
void QgsFeatureListView::editSelectionChanged( const QItemSelection &deselected, const QItemSelection &selected )
{
  if ( isVisible() && updatesEnabled() )
  {
    QItemSelection localDeselected = mModel->mapSelectionFromMaster( deselected );
    QItemSelection localSelected = mModel->mapSelectionFromMaster( selected );
    viewport()->update( visualRegionForSelection( localDeselected ) | visualRegionForSelection( localSelected ) );
  }

  QItemSelection currentSelection = mCurrentEditSelectionModel->selection();
  if ( currentSelection.size() == 1 )
  {
    QModelIndexList indexList = currentSelection.indexes();
    if ( !indexList.isEmpty() )
    {
      QgsFeature feat;
      mModel->featureByIndex( mModel->mapFromMaster( indexList.first() ), feat );

      emit currentEditSelectionChanged( feat );
    }
  }
}
Esempio n. 18
0
void NamespaceListView::slotDeleteSelected()
{
    QModelIndexList sel = this->selectionModel()->selectedIndexes();

    if (sel.isEmpty())
    {
        return;
    }

    QStandardItemModel* const model = dynamic_cast<QStandardItemModel*>(this->model());

    if (!model)
    {
        qCDebug(DIGIKAM_GENERAL_LOG) << "Error! no model available!";
        return;
    }

    foreach (const QModelIndex& index, sel)
    {
        QStandardItem* const root = model->invisibleRootItem();
        root->removeRow(index.row());
    }
QModelIndexList CartesianDiagramDataCompressor::indexesAt( const CachePosition& position ) const
{
    if ( isValidCachePosition( position ) ) {
        CachePosition posPrev( position );
        if( m_datasetDimension == 2 ){
            if(posPrev.second)
                --posPrev.second;
        }else{
            if(posPrev.first)
                --posPrev.first;
        }
        const QModelIndexList indPrev = mapToModel( posPrev );
        const QModelIndexList indCur  = mapToModel( position );

        QModelIndexList indexes;
        if( m_datasetDimension == 2 )
        {
            const int iStart = (indPrev.empty() || indPrev==indCur) ? indCur.first().column()
                             : indPrev.first().column() + 1;
            const int iEnd   = indCur.last().column();
            for( int i=iStart; i<=iEnd; ++i){
                indexes << m_model->index( position.first, i, m_rootIndex );
            }
        }
        else
        {
            const int iStart = (indPrev.empty() || indPrev==indCur)  ? indCur.first().row()
                             : indPrev.first().row() + 1;
            const int iEnd   = (indCur.isEmpty()) ? iStart : indCur.first().row();
            //qDebug()<<iStart<<iEnd << iEnd-iStart;
            for( int i=iStart; i<=iEnd; ++i){
                indexes << m_model->index( i, position.second, m_rootIndex );
            }
        }
        return indexes;
    } else {
        return QModelIndexList();
    }
}
Esempio n. 20
0
void TilesetEditor::selectionChanged()
{
    TilesetView *view = currentTilesetView();
    if (!view)
        return;

    updateAddRemoveActions();

    const QItemSelectionModel *s = view->selectionModel();
    const QModelIndexList indexes = s->selection().indexes();
    if (indexes.isEmpty())
        return;

    const TilesetModel *model = view->tilesetModel();
    QList<Tile*> selectedTiles;

    for (const QModelIndex &index : indexes)
        if (Tile *tile = model->tileAt(index))
            selectedTiles.append(tile);

    mCurrentTilesetDocument->setSelectedTiles(selectedTiles);
}
Esempio n. 21
0
void AddressBookPage::onEditAction()
{
    if(!model)
        return;

    if(!ui->tableView->selectionModel())
        return;

    QModelIndexList indexes = ui->tableView->selectionModel()->selectedRows();
    if(indexes.isEmpty())
        return;
    QModelIndex origIndex = proxyModel->mapToSource(indexes.at(0));

    EditAddressDialog dlg(
        tab == SendingTab ?
        EditAddressDialog::EditSendingAddress :
        EditAddressDialog::EditReceivingAddress, this);
    dlg.setModel(model);

    dlg.loadRow(origIndex.row());
    dlg.exec();
}
Esempio n. 22
0
void MainWindow::on_tableView_customContextMenuRequested(QPoint pos)
{
    QModelIndex index = ui->tableView->indexAt(pos);
    if(index.isValid()) {
        QModelIndexList selection = ui->tableView->selectionModel()->selectedRows(4);
        QString status, privKey, pubKey;
        if(!selection.isEmpty()) {
            status = selection.at(0).data(0).toString();
            pubKey = ui->tableView->selectionModel()->selectedRows(3).at(0).data(0).toString();
            privKey = ui->tableView->selectionModel()->selectedRows(2).at(0).data(0).toString();

            if (pubKey.isEmpty())
                copyPubkAction->setVisible(false);
            else
                copyPubkAction->setVisible(true);

            if(privKey.isEmpty())
                copyPkAction->setVisible(false);
            else
                copyPkAction->setVisible(true);

            if (status == tr("Solved")) {
                copyPrefixAction->setVisible(false);
                showSolveDialogAction->setVisible(false);
                copyBtcAdAction->setVisible(true);
                if (!privKey.isEmpty())
                    copyPkBase58Action->setVisible(true);
            } else {
                copyPrefixAction->setVisible(true);
                showSolveDialogAction->setVisible(true);
                copyBtcAdAction->setVisible(false);
                copyPkBase58Action->setVisible(false);
            }

            contextMenu->exec(QCursor::pos());
        }
    }
}
Esempio n. 23
0
void MainWindow::on_btnRemove_clicked()
{
    QModelIndexList selected = ui->listView->selectionModel()->selectedIndexes();
    if (!selected.isEmpty())
    {
        QString str = list.at(selected.first().row());

        QVector<QString> vRemove = readFile(str);

        for(int i = 0; i < vGlobal.length(); i++)
            for(int k = 0; k < vRemove.length(); k++)
            {
                if(vGlobal.at(i) == vRemove.at(k))
                {
                    vGlobal.removeAt(i);
                    showDataInTableView(tvModel, vGlobal);
                    ui->tableView->setModel(tvModel);
                }
            }

        QStandardItemModel *tModel = new QStandardItemModel(0,0,this);
        tModel->setHorizontalHeaderItem(0, new QStandardItem(QString("Site A")));
        tModel->setHorizontalHeaderItem(1, new QStandardItem(QString("Site B")));

        showDataInTableView(tModel, vGlobal);
        ui->tableView->setModel(tModel);

        list.removeAt(selected.first().row());
        ((QStringListModel*) ui->listView->model())->setStringList(list);

        vRemove.clear();

        if(list.isEmpty())
            ui->btnRemove->setEnabled(false);

        ui->btnStart->setEnabled(false);
    }
}
Esempio n. 24
0
bool CQParameterSetsDM::removeRows(QModelIndexList rows, const QModelIndex & /* index */)
{
  if (rows.isEmpty()) return false;

  if (mpListOfParameterSets == NULL) return false;

  //  Build the list of pointers to items to be deleted
  //  before actually deleting any item.
  QList< CModelParameterSet * > ModelParameterSets;
  QModelIndexList::const_iterator i;

  for (i = rows.begin(); i != rows.end(); ++i)
    {
      ModelParameterSets.append((*mpListOfParameterSets)[(*i).row()]);
    }

  QList< CModelParameterSet * >::const_iterator j;

  for (j = ModelParameterSets.begin(); j != ModelParameterSets.end(); ++j)
    {
      CModelParameterSet * pModelParameterSet = *j;

      size_t delRow = mpListOfParameterSets->CCopasiVector< CModelParameterSet >::getIndex(pModelParameterSet);

      if (delRow != C_INVALID_INDEX)
        {
          QMessageBox::StandardButton choice =
            CQMessageBox::confirmDelete(NULL, "layout",
                                        FROM_UTF8(pModelParameterSet->getObjectName()),
                                        std::set< const CCopasiObject * >());

          if (choice == QMessageBox::Ok)
            removeRow((int) delRow);
        }
    }

  return true;
}
Esempio n. 25
0
void TransactionView::editLabel()
{
    if (!transactionView->selectionModel() || !model)
        return;
    QModelIndexList selection = transactionView->selectionModel()->selectedRows();
    if (!selection.isEmpty()) {
        AddressTableModel* addressBook = model->getAddressTableModel();
        if (!addressBook)
            return;
        QString address = selection.at(0).data(TransactionTableModel::AddressRole).toString();
        if (address.isEmpty()) {
            // If this transaction has no associated address, exit
            return;
        }
        // Is address in address book? Address book can miss address when a transaction is
        // sent from outside the UI.
        int idx = addressBook->lookupAddress(address);
        if (idx != -1) {
            // Edit sending / receiving address
            QModelIndex modelIdx = addressBook->index(idx, 0, QModelIndex());
            // Determine type of address, launch appropriate editor dialog type
            QString type = modelIdx.data(AddressTableModel::TypeRole).toString();

            EditAddressDialog dlg(
                type == AddressTableModel::Receive ? EditAddressDialog::EditReceivingAddress : EditAddressDialog::EditSendingAddress, this);
            dlg.setModel(addressBook);
            dlg.loadRow(idx);
            dlg.exec();
        } else {
            // Add sending address
            EditAddressDialog dlg(EditAddressDialog::NewSendingAddress,
                this);
            dlg.setModel(addressBook);
            dlg.setAddress(address);
            dlg.exec();
        }
    }
}
Esempio n. 26
0
void
ColumnView::startDrag( Qt::DropActions supportedActions )
{
    QList<QPersistentModelIndex> pindexes;
    QModelIndexList indexes;
    foreach( const QModelIndex& idx, selectedIndexes() )
    {
        if ( ( m_proxyModel->flags( idx ) & Qt::ItemIsDragEnabled ) )
        {
            indexes << idx;
            pindexes << idx;
        }
    }

    if ( indexes.isEmpty() )
        return;

    tDebug( LOGVERBOSE ) << "Dragging" << indexes.count() << "indexes";
    QMimeData* data = m_proxyModel->mimeData( indexes );
    if ( !data )
        return;

    QDrag* drag = new QDrag( this );
    drag->setMimeData( data );

    QPixmap p;
    if ( data->hasFormat( "application/tomahawk.metadata.artist" ) )
        p = TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeArtist, indexes.count() );
    else if ( data->hasFormat( "application/tomahawk.metadata.album" ) )
        p = TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeAlbum, indexes.count() );
    else
        p = TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeTrack, indexes.count() );

    drag->setPixmap( p );
    drag->setHotSpot( QPoint( -20, -20 ) );

    drag->exec( supportedActions, Qt::CopyAction );
}
Esempio n. 27
0
bool WeightModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
	QString vString = value.toString();
	weightsystem_t *ws = &displayed_dive.weightsystem[index.row()];
	switch (index.column()) {
	case TYPE:
		if (!value.isNull()) {
			//TODO: C-function weigth_system_set_description ?
			if (!ws->description || gettextFromC::instance()->tr(ws->description) != vString) {
				// loop over translations to see if one matches
				int i = -1;
				while (ws_info[++i].name) {
					if (gettextFromC::instance()->tr(ws_info[i].name) == vString) {
						ws->description = ws_info[i].name;
						break;
					}
				}
				if (ws_info[i].name == NULL) // didn't find a match
					ws->description = strdup(vString.toUtf8().constData());
				changed = true;
			}
		}
		break;
	case WEIGHT:
		if (CHANGED()) {
			ws->weight = string_to_weight(vString.toUtf8().data());
			// now update the ws_info
			changed = true;
			WSInfoModel *wsim = WSInfoModel::instance();
			QModelIndexList matches = wsim->match(wsim->index(0, 0), Qt::DisplayRole, gettextFromC::instance()->tr(ws->description));
			if (!matches.isEmpty())
				wsim->setData(wsim->index(matches.first().row(), WSInfoModel::GR), ws->weight.grams);
		}
		break;
	}
	dataChanged(index, index);
	return true;
}
Esempio n. 28
0
QMimeData *ContactListFrontModel::mimeData(const QModelIndexList &indexes) const
{
	QModelIndexList filteredList;
	QObject *contact = NULL;
	foreach (const QModelIndex &index, indexes) {
		switch (index.data(ItemTypeRole).toInt()) {
		case ContactType:
			contact = index.data(ContactRole).value<QObject*>();
			Q_ASSERT(qobject_cast<Contact*>(contact));
			// fall through
		case TagType:
			filteredList << index;
		default:
			break;
		}
	}
	if (filteredList.isEmpty())
		return NULL;
	ContactListMimeData *mimeData = new ContactListMimeData();
	mimeData->setIndexes(filteredList);
	mimeData->setObject(contact);
	return mimeData;
}
Esempio n. 29
0
void QueryView::copyc()
{
    QItemSelectionModel *s = qview->selectionModel();
    QModelIndexList indices = s->selectedIndexes();
    if(indices.isEmpty()) {
        return;
    }
    qSort(indices);
    QModelIndex prev = indices.first();
    QModelIndex last = indices.last();
    indices.removeFirst();
    QModelIndex current;
    QString selectedText;

    foreach(current, indices) {
        QVariant data = qview->model()->data(prev);
        selectedText.append(data.toString());
        if(current.row() != prev.row())
            selectedText.append(QLatin1Char('\n'));
        else
            selectedText.append(QLatin1Char('\t'));
        prev = current;
    }
Esempio n. 30
0
void AddressBookPage::on_newAddressButton_clicked()
{
    if(!model)
        return;
    EditAddressDialog dlg(
            tab == SendingTab ?
            EditAddressDialog::NewSendingAddress :
            EditAddressDialog::NewReceivingAddress);
    dlg.setModel(model);
    if(dlg.exec())
    {
        // Select row for newly created address
        QString address = dlg.getAddress();
        QModelIndexList lst = proxyModel->match(proxyModel->index(0,
                          AddressTableModel::Address, QModelIndex()),
                          Qt::EditRole, address, 1, Qt::MatchExactly);
        if(!lst.isEmpty())
        {
            ui->tableView->setFocus();
            ui->tableView->selectRow(lst.at(0).row());
        }
    }
}