本文整理汇总了C++中QList::move方法的典型用法代码示例。如果您正苦于以下问题:C++ QList::move方法的具体用法?C++ QList::move怎么用?C++ QList::move使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QList
的用法示例。
在下文中一共展示了QList::move方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convertToIndexed8
QImage convertToIndexed8(const QImage & img, bool * uses_alpha = nullptr)
{
QList<QRgb> colors;
QImage image(img.width(), img.height(), QImage::Format_Indexed8);
image.fill(0);
for(int x = 0; x < img.width(); x++){
for(int y = 0; y < img.height(); y++){
QRgb c = img.pixel(x, y);
if(!colors.contains(c)){
colors << c;
if(qAlpha(c) == 0 && uses_alpha){
*uses_alpha = true;
colors.move(colors.size()-1, 0);
}
}
}
}
if(colors.size() > 255) return img.convertToFormat(QImage::Format_Indexed8);
for(int i = 0; i < colors.size(); i++){
image.setColor(i, colors[i]);
}
for(int x = 0; x < img.width(); x++){
for(int y = 0; y < img.height(); y++){
QRgb pix = img.pixel(x, y);
image.setPixel(x, y, colors.indexOf(pix));
}
}
return image;
}
示例2: dropMimeData
bool pOpenedFileModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent )
{
if ( parent.isValid() || ( row == -1 && column == -1 ) || action != Qt::MoveAction || !data || !data->hasFormat( mimeTypes().first() ) )
{
return false;
}
const int fromRow = data->data( mimeTypes().first() ).toInt();
if ( row >= mDocuments.count() )
{
row--;
}
else if ( fromRow < row )
{
row--;
}
QList<pAbstractChild*> newDocuments = mDocuments;
newDocuments.move( fromRow, row );
rebuildMapping( mDocuments, newDocuments );
if ( mSortMode != pOpenedFileModel::Custom )
{
setSortMode( pOpenedFileModel::Custom );
}
return true;
}
示例3: move
void tst_QList::move() const
{
QList<QString> list;
list << "foo" << "bar" << "baz";
// move an item
list.move(0, list.count() - 1);
QCOMPARE(list, QList<QString>() << "bar" << "baz" << "foo");
// move it back
list.move(list.count() - 1, 0);
QCOMPARE(list, QList<QString>() << "foo" << "bar" << "baz");
// move an item in the middle
list.move(1, 0);
QCOMPARE(list, QList<QString>() << "bar" << "foo" << "baz");
}
示例4: moveRow
void moveRow( int from, int to ) {
if ( from == to ) return;
if ( from >= m_tasks.size() || to >= m_tasks.size()+1 ) return;
if ( beginMoveRows( QModelIndex(), from, from, QModelIndex(), to ) ) {
m_tasks.move( from, to );
endMoveRows();
} else {
assert( 0 );
}
}
示例5: slotOpenAVDisk
void MountTray::slotOpenAVDisk(QString type){
if(MTINIT){ return; } //don't open the launcher during program initialization
//Get the list of all AudioVideo Applications on the sytem
QList<XDGFile> apps = XDGUtils::allApplications();
apps = XDGUtils::filterAppsByCategory("AudioVideo", apps);
apps = XDGUtils::sortAppsByName(apps);
//Now generate the QStringList of application names
QStringList names;
for(int i=0; i<apps.length(); i++){
//Filter out "invalid" applications (mixers, etc..)
QString rname = apps[i].RawName();
if(rname.contains("mixer", Qt::CaseInsensitive) || rname.contains("control", Qt::CaseInsensitive) ){
//skip it
apps.removeAt(i);
i--;
}else{
QString txt;
if( apps[i].Comment().isEmpty() ){ txt = apps[i].Name(); }
else{ txt = apps[i].Name() +" ("+apps[i].Comment()+")"; }
//Make sure that UMPlayer is listed first and recommended
if(apps[i].RawName().toLower()=="umplayer"){
txt = apps[i].Name()+ " **"+tr("Recommended")+"**";
names.prepend(txt); //put at the top
apps.move(i,0); //move the file to the front as well
}else{
names << txt;
}
}
}
//Prompt for the user to select an application
bool ok = false;
QString appname = QInputDialog::getItem(0, QString(tr("%1 Disk")).arg(type) , tr("Open With:"), names,0, false, &ok);
if(!ok || appname.isEmpty()){ return; }
int index = names.indexOf(appname);
if(index == -1){ return; }
//Now start the application
qDebug() << "Open "+type.toLower()+" disk:";
qDebug() << " -- With:"<<appname;
QString cmd = apps[index].Exec();
//Only auto-start the disk with UMPlayer - no guarantee this method works for other apps
if(apps[index].RawName().toLower()=="umplayer"){
if(type.toLower()=="audio"){
cmd.append(" cdda://1"); //audio cd
}else{ //video DVD
cmd.append(" dvd://1"); //video dvd
}
}
qDebug() << " -- Exec:" << cmd;
QProcess::startDetached( cmd );
}
示例6: loadSelectionState
void MainWindow::loadSelectionState(bool selectNote) {
QSqlQuery query;
if (!query.exec("SELECT option, value FROM syncStatus WHERE option IN ('selNotebook', 'selTab', 'selNote', 'selTag')"))
LOG_ERROR("SQL: " + query.lastError().text());
QHash<QString, QString> status;
while (query.next())
status[query.value(0).toString()] = query.value(1).toString();
if (!status.contains("selTab"))
return;
int tab = status["selTab"].toInt();
ui->toolBox->setCurrentIndex(tab);
ui->NotesList->blockSignals(true);
QList<QString> array;
array.append("selNotebook");
array.append("selTag");
array.append("selSearch");
array.append("selReminders");
array.move(tab, array.size()-1);
for (int i = 0; i< array.size(); i++) {
QString name = array.at(i);
if (!status.contains(name))
continue;
if (name == "selNotebook")
ui->notebooks->selectNotebookWithName(status["selNotebook"]);
if (name == "selTag")
ui->tags->selectTagWithGUID(status["selTag"]);
}
if (selectNote && status.contains("selNote")) {
ListItem* note = ui->NotesList->getNoteWithGuid(status["selNote"]);
if (note != NULL )
ui->NotesList->setCurrentItem(note);
}
ui->NotesList->blockSignals(false);
}
示例7: handleMoveLayer
void LayerListModel::handleMoveLayer(int oldIdx, int newIdx)
{
// Need at least two layers for this to make sense
const int count = _items.count();
if(count < 2)
return;
QList<uint16_t> layers;
layers.reserve(count);
foreach(const LayerListItem &li, _items)
layers.append(li.id);
if(newIdx>oldIdx)
--newIdx;
layers.move(oldIdx, newIdx);
// Layers are shown topmost first in the list but
// are sent bottom first in the protocol.
for(int i=0;i<count/2;++i)
layers.swap(i,count-(1+i));
emit layerOrderChanged(layers);
}
示例8: dynUpdateTopolSort
//.........这里部分代码省略.........
q.enqueue(tmpnode);
visited[tmpidx] = true;
// Add the node to the deltaF
deltaB.prepend(tmpnode); // IMPORTANT!!! PREpend!
deltaBIdx.prepend(tmpidx);
}
}
}
*/
// Move elements of deltaB to the left and the elements of deltaF to the right until the backward ark does not disappear
//int posB = 0;
//out << "Shifting deltaF to the right..." << endl;
int posF = ar.size() - 1;
// Move elements in deltaF to the right
while (!deltaF.isEmpty()) {
// Find the first element in ar starting from posB that is in deltaB
tmpidx = -1;
for (int l = posF; l >= 0; l--) {
if (deltaF.contains(ar[l])) {
tmpidx = l;
break;
}
}
if (tmpidx == -1) {
Debugger::err << "ProcessModel::dynUpdateTopolSort : tmpidx = -1 while shifting deltaF. Probably the graph is NOT DAG! " << ENDL;
}
// Erase this element from deltaF
deltaF.removeOne(ar[tmpidx]);
// Move this element to the left
ar.move(tmpidx, posF);
posF--;
}
//out << "Shifted deltaF to the right." << endl;
// Moving elements of deltaB is not necessary, since they are automatically found before any element of deltaF, since these were moved to the right
/*
// Move elements in deltaB to the left so that the last element of deltaB is on the position posF (right before elements of deltaF)
while (!deltaB.isEmpty()) {
// Find the first element in ar starting from posB that is in deltaB
tmpidx = -1;
for (int l = posB; l < ar.size(); l++) {
if (deltaB.contains(ar[l])) {
tmpidx = l;
break;
}
}
// Erase this element from deltaB
deltaB.removeOne(ar[tmpidx]);
// Move this element to the left
ar.move(tmpidx, posB);
posB++;
}
*/
// Modify the final topological ordering
示例9: playItemAt
//----------------------------------------
//--- Primary playback control methods ---
//----------------------------------------
void Playlist::playItemAt(int row, Model model)
{
bool isQueue = (model == QueueModel);
MediaItem nextMediaItem = isQueue ? m_queue->mediaItemAt(row) :
m_currentPlaylist->mediaItemAt(row);
if (!isQueue) {
nextMediaItem.playlistIndex = row;
}
nextMediaItem.nowPlaying = true;
//Update Queue Model
if (!m_shuffle) {
//Just build a new queue from the row of the item in the playlist
buildQueueFrom(nextMediaItem.playlistIndex);
} else {
int rowInQueue = isQueue ? row : m_queue->rowOfUrl(nextMediaItem.url);
//Add currently playing item to history
if (rowInQueue > 0 && m_nowPlaying->rowCount() > 0) {
if (m_nowPlaying->mediaItemAt(0).type == "Audio" || m_nowPlaying->mediaItemAt(0).type == "Video") {
int nowPlayingIndex = m_nowPlaying->mediaItemAt(0).playlistIndex;
m_playlistIndicesHistory.append(nowPlayingIndex);
m_playlistUrlHistory.append(m_nowPlaying->mediaItemAt(0).url);
if (m_queue->rowCount() > 1) {
m_queue->removeMediaItemAt(0);
rowInQueue--;
}
}
}
//Remove requested item from history
bool inHistory = (m_playlistIndicesHistory.indexOf(nextMediaItem.playlistIndex) != -1);
if ( inHistory ) { //remove from history
int idx = m_playlistIndicesHistory.indexOf(row);
m_playlistIndicesHistory.removeAt(idx);
m_playlistUrlHistory.removeAt(idx);
}
//Place requested item at front of queue
QList<MediaItem> queueMediaList = m_queue->mediaList();
if ( rowInQueue > 0 ) { //in queue, but not at first place, so move it
queueMediaList.move(rowInQueue, 0);
} else if (rowInQueue < 0) { //not in queue, so add it at first place
queueMediaList.insert(0, nextMediaItem);
if (queueMediaList.count() > m_queueDepth) {
queueMediaList.removeLast();
}
} //else it is already at first place in the queue
m_queue->clearMediaListData();
m_queue->loadMediaList(queueMediaList, true);
//Fill out queue
shuffle();
}
//Play media Item
m_mediaObject->clearQueue();
m_currentStream.clear();
QString subType;
if (nextMediaItem.type == "Audio") {
subType = nextMediaItem.fields["audioType"].toString();
} else if(nextMediaItem.type == "Video") {
subType = nextMediaItem.fields["videoType"].toString();
}
m_currentUrl = nextMediaItem.url;
bool isDiscTitle = Utilities::isDisc( nextMediaItem.url );
if (isDiscTitle) {
Solid::Device device = Solid::Device( Utilities::deviceUdiFromUrl(nextMediaItem.url) );
if (!device.isValid()) {
stop();
return;
}
const Solid::Block* block = device.as<const Solid::Block>();
Phonon::DiscType discType = (subType == "CD Track") ? Phonon::Cd : Phonon::Dvd;
Phonon::MediaSource src = Phonon::MediaSource(discType, block->device());
int title = nextMediaItem.fields["trackNumber"].toInt();
if (m_mediaObject->currentSource().discType() != src.discType() ||
m_mediaObject->currentSource().deviceName() != src.deviceName()) {
m_mediaObject->setCurrentSource(src);
}
if (title != -1) {
m_mediaController->setCurrentTitle(title);
m_mediaController->setAutoplayTitles(true);
}
m_mediaObject->play();
} else if (subType == "Audio Stream") {
m_currentStream = nextMediaItem.url;
m_streamListUrls.clear();
if (Utilities::isPls(nextMediaItem.url) || Utilities::isM3u(nextMediaItem.url)) {
QList<MediaItem> streamList = Utilities::mediaListFromSavedList(nextMediaItem);
for (int i = 0; i < streamList.count(); i++) {
m_streamListUrls << streamList.at(i).url;
if (i == 0) {
m_currentUrl = streamList.at(i).url;
} else {
m_mediaObject->enqueue(Phonon::MediaSource(QUrl::fromPercentEncoding(streamList.at(i).url.toUtf8())));
}
//.........这里部分代码省略.........
示例10: handleKeyPress
bool UIGChooserHandlerKeyboard::handleKeyPress(QKeyEvent *pEvent) const
{
/* Which key it was? */
switch (pEvent->key())
{
/* Key UP? */
case Qt::Key_Up:
{
/* Not during sliding: */
if (model()->isSlidingInProgress())
return false;
/* Was control modifier pressed? */
#ifdef Q_WS_MAC
if (pEvent->modifiers() & Qt::ControlModifier &&
pEvent->modifiers() & Qt::KeypadModifier)
#else /* Q_WS_MAC */
if (pEvent->modifiers() == Qt::ControlModifier)
#endif /* !Q_WS_MAC */
{
/* Get focus and his parent: */
UIGChooserItem *pFocusItem = model()->focusItem();
UIGChooserItem *pParentItem = pFocusItem->parentItem();
UIGChooserItemType type = (UIGChooserItemType)pFocusItem->type();
QList<UIGChooserItem*> items = pParentItem->items(type);
int iFocusPosition = items.indexOf(pFocusItem);
if (iFocusPosition > 0)
{
items.move(iFocusPosition, iFocusPosition - 1);
pParentItem->setItems(items, type);
model()->updateNavigation();
model()->updateLayout();
}
/* Filter-out this event: */
return true;
}
/* Was shift modifier pressed? */
#ifdef Q_WS_MAC
else if (pEvent->modifiers() & Qt::ShiftModifier &&
pEvent->modifiers() & Qt::KeypadModifier)
#else /* Q_WS_MAC */
else if (pEvent->modifiers() == Qt::ShiftModifier)
#endif /* !Q_WS_MAC */
{
/* Determine focus item position: */
int iPosition = model()->navigationList().indexOf(model()->focusItem());
/* Determine 'previous' item: */
UIGChooserItem *pPreviousItem = iPosition > 0 ?
model()->navigationList().at(iPosition - 1) : 0;
if (pPreviousItem)
{
/* Make sure 'previous' item is visible: */
pPreviousItem->makeSureItsVisible();
/* Move focus to 'previous' item: */
model()->setFocusItem(pPreviousItem);
/* Calculate positions: */
UIGChooserItem *pFirstItem = model()->selectionList().first();
int iFirstPosition = model()->navigationList().indexOf(pFirstItem);
int iPreviousPosition = model()->navigationList().indexOf(pPreviousItem);
/* Clear selection: */
model()->clearSelectionList();
/* Select all the items from 'first' to 'previous': */
if (iFirstPosition <= iPreviousPosition)
for (int i = iFirstPosition; i <= iPreviousPosition; ++i)
model()->addToSelectionList(model()->navigationList().at(i));
else
for (int i = iFirstPosition; i >= iPreviousPosition; --i)
model()->addToSelectionList(model()->navigationList().at(i));
/* Notify selection changed: */
model()->notifySelectionChanged();
/* Filter-out this event: */
return true;
}
}
/* There is no modifiers pressed? */
#ifdef Q_WS_MAC
else if (pEvent->modifiers() == Qt::KeypadModifier)
#else /* Q_WS_MAC */
else if (pEvent->modifiers() == Qt::NoModifier)
#endif /* !Q_WS_MAC */
{
/* Determine focus item position: */
int iPosition = model()->navigationList().indexOf(model()->focusItem());
/* Determine 'previous' item: */
UIGChooserItem *pPreviousItem = iPosition > 0 ?
model()->navigationList().at(iPosition - 1) : 0;
if (pPreviousItem)
{
/* Make sure 'previous' item is visible: */
pPreviousItem->makeSureItsVisible();
/* Move focus to 'previous' item: */
model()->setFocusItem(pPreviousItem);
/* Move selection to 'previous' item: */
model()->clearSelectionList();
model()->addToSelectionList(pPreviousItem);
/* Notify selection changed: */
model()->notifySelectionChanged();
/* Filter-out this event: */
return true;
}
//.........这里部分代码省略.........
示例11: sizeof
static QList<Item> get_audio_items(int type)
{
QList<Item> out;
int nb_devices = 0;
UInt32 size = 0;
if(AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &size, NULL) != 0)
return out;
nb_devices = size / sizeof(AudioDeviceID);
// Get the devices
AudioDeviceID devices[nb_devices];
AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &size, devices);
for(int i = 0; i < nb_devices; i++)
{
// Get the device name
char name[1024];
size = sizeof(name);
if(AudioDeviceGetProperty(devices[i], 0, 0, kAudioDevicePropertyDeviceName, &size, name) != 0)
continue;
QString qname = QString::fromLatin1(name);
// Query the input streams
if(AudioDeviceGetPropertyInfo(devices[i], 0, 1, kAudioDevicePropertyStreams, &size, NULL) != 0)
continue;
bool input = (size > 0);
// Query the output streams
if(AudioDeviceGetPropertyInfo(devices[i], 0, 0, kAudioDevicePropertyStreams, &size, NULL) != 0)
continue;
bool output = (size > 0);
int dev_int = devices[i];
if(type & DIR_INPUT && input)
{
Item i;
i.type = Item::Audio;
i.dir = Item::Input;
i.name = qname;
i.driver = "osxaudio";
i.id = QString::number(dev_int);
out += i;
}
if(type & DIR_OUTPUT && output)
{
Item i;
i.type = Item::Audio;
i.dir = Item::Output;
i.name = qname;
i.driver = "osxaudio";
i.id = QString::number(dev_int);
out += i;
}
}
// do default output first, then input, so that if both are found, input
// will end up at the top. not that it really matters.
// Get the default output device
if(type & DIR_OUTPUT)
{
size = sizeof(AudioDeviceID);
AudioDeviceID default_output = kAudioDeviceUnknown;
if(AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &default_output) == 0)
{
int at = find_by_id(out, default_output);
if(at != -1)
out.move(at, 0);
}
}
// Get the default input device
if(type & DIR_INPUT)
{
size = sizeof(AudioDeviceID);
AudioDeviceID default_input = kAudioDeviceUnknown;
if(AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice, &size, &default_input) == 0)
{
int at = find_by_id(out, default_input);
if(at != -1)
out.move(at, 0);
}
}
return out;
}