void BookmarkList::dropEvent(QDropEvent *event) { const QMimeData* data = event->mimeData(); if(data->hasUrls()) { //TODO: Add insert to the dropped row, except row 0 QStandardItemModel* mod = (QStandardItemModel*)model(); QString path = data->urls()[0].path(); QFileInfo f(path); if(mod) { QList<QStandardItem*> items = mod->findItems(f.fileName()); if(f.isDir() && items.isEmpty()) { QStandardItem *it = new QStandardItem(); it->setText(f.fileName()); it->setData(path); #if QT_VERSION >= 0x040600 // Todo: Use a "favorites folder" icon instead it->setIcon(*globalIcon); #else it->setIcon(QIcon(":/images/icons/clip-folder-bookmark.png")); #endif it->setDropEnabled(true); mod->appendRow(it); emit bookmarkAdded(); } } } event->acceptProposedAction(); }
bool ProgramsModel::AddGroup(QModelIndex &index, int row) { int groupId = myHost->programsModel->GetNextGroupId(); QString name("New grp"); //create the group QStandardItem *groupItem = new QStandardItem( name ); groupItem->setData(GroupNode,NodeType); groupItem->setData(groupId,ProgramId); #ifndef QT_NO_DEBUG groupItem->setData(groupId,Qt::ToolTipRole); #endif groupItem->setDragEnabled(true); groupItem->setDropEnabled(false); groupItem->setEditable(true); if(row==-1) row=rowCount(); insertRow( row, groupItem ); index = groupItem->index(); return true; }
bool ProgramsModel::AddProgram(int groupNum, QModelIndex &index, int row) { QStandardItem *groupItem = item(groupNum); //if the group was disabled re-enable it if(groupItem->rowCount()==0) { groupItem->setBackground(Qt::transparent); groupItem->setToolTip(""); } int progId = myHost->programsModel->GetNextProgId(); QString name("New prog"); //create the program item QStandardItem *prgItem = new QStandardItem( name ); prgItem->setData(ProgramNode,NodeType); prgItem->setData(progId,ProgramId); #ifndef QT_NO_DEBUG prgItem->setData(progId,Qt::ToolTipRole); #endif prgItem->setDragEnabled(true); prgItem->setDropEnabled(false); prgItem->setEditable(true); if(row==-1) row=groupItem->rowCount(); groupItem->insertRow(row, prgItem); index = prgItem->index(); // ValidateProgChange(index); return true; }
NavigatorTreeModel::ItemRow NavigatorTreeModel::createItemRow(const ModelNode &node) { Q_ASSERT(node.isValid()); uint hash = node.internalId(); const bool dropEnabled = node.metaInfo().isValid(); QStandardItem *idItem = new QStandardItem; idItem->setDragEnabled(true); idItem->setDropEnabled(dropEnabled); idItem->setEditable(true); idItem->setData(hash, NavigatorRole); if (node.metaInfo().isValid()) idItem->setToolTip(node.type()); else idItem->setToolTip(msgUnknownItem(node.type())); # ifdef _LOCK_ITEMS_ QStandardItem *lockItem = new QStandardItem; lockItem->setDragEnabled(true); lockItem->setDropEnabled(dropEnabled); lockItem->setEditable(false); lockItem->setCheckable(true); lockItem->setData(hash, NavigatorRole); # endif QStandardItem *visibilityItem = new QStandardItem; visibilityItem->setDropEnabled(dropEnabled); visibilityItem->setCheckable(true); visibilityItem->setEditable(false); visibilityItem->setData(hash, NavigatorRole); if (node.isRootNode()) visibilityItem->setCheckable(false); QMap<QString, QStandardItem *> propertyItems; foreach (const QString &propertyName, visibleProperties(node)) { QStandardItem *propertyItem = new QStandardItem; propertyItem->setSelectable(false); propertyItem->setDragEnabled(false); propertyItem->setDropEnabled(dropEnabled); propertyItem->setEditable(false); propertyItem->setData(propertyName, Qt::DisplayRole); propertyItems.insert(propertyName, propertyItem); idItem->appendRow(propertyItem); }
NavigatorTreeModel::ItemRow NavigatorTreeModel::createItemRow(const ModelNode &node) { Q_ASSERT(node.isValid()); uint hash = qHash(node); const bool dropEnabled = node.metaInfo().isValid(); QStandardItem *idItem = new QStandardItem; idItem->setDragEnabled(true); idItem->setDropEnabled(dropEnabled); idItem->setEditable(true); idItem->setData(hash, Qt::UserRole); #ifdef _LOCK_ITEMS_ QStandardItem *lockItem = new QStandardItem; lockItem->setDragEnabled(true); lockItem->setDropEnabled(dropEnabled); lockItem->setEditable(false); lockItem->setCheckable(true); lockItem->setData(hash, Qt::UserRole); #endif QStandardItem *visibilityItem = new QStandardItem; visibilityItem->setDropEnabled(dropEnabled); visibilityItem->setCheckable(true); visibilityItem->setEditable(false); visibilityItem->setData(hash, Qt::UserRole); if (node.isRootNode()) { visibilityItem->setCheckable(false); } #ifdef _LOCK_ITEMS_ return ItemRow(idItem, lockItem, visibilityItem); #else return ItemRow(idItem, visibilityItem); #endif }
void SinglePlaylistView::browseSavedPlaylist(MafwPlaylist *mafwplaylist) { currentObjectId = QString(); playlistLoaded = true; objectModel->clear(); QStandardItem *item = new QStandardItem(); item->setData(true, UserRoleHeader); item->setDragEnabled(false); item->setDropEnabled(false); objectModel->appendRow(item); connect(ui->objectList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onItemDoubleClicked())); MafwPlaylistAdapter *mpa = new MafwPlaylistAdapter(mafwplaylist); int size = mpa->size(); gchar** items = mpa->items(0, size-1); for (int i = 0; items[i] != NULL; i++) { QStandardItem *item = new QStandardItem(); item->setData(QString::fromUtf8(items[i]), UserRoleObjectID); item->setData(Duration::Blank, UserRoleSongDuration); item->setDropEnabled(false); objectModel->appendRow(item); } g_strfreev(items); PlaylistQueryManager *playlistQM = new PlaylistQueryManager(this, mpa); mpa->setParent(playlistQM); connect(playlistQM, SIGNAL(gotItem(QString,GHashTable*,uint)), this, SLOT(onItemReceived(QString,GHashTable*,uint))); connect(ui->objectList->verticalScrollBar(), SIGNAL(valueChanged(int)), playlistQM, SLOT(setPriority(int))); playlistQM->getItems(0, size-1); remainingCount = size; updateSongCount(); }
bool BookmarkListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int col, const QModelIndex &parent) { Q_UNUSED(parent); if(action == Qt::IgnoreAction) return true; //Make sure we have urls as created by the fileList if(!data->hasUrls())/*{{{*/ { qDebug("Drop is not a URL"); return false; } //Single column for now if(col > 0) return false; int irow = row; if(irow == 0) irow = 1; QString path = data->urls()[0].path(); QFileInfo f(path); QList<QStandardItem*> items = findItems(f.fileName()); if(f.isDir() && items.isEmpty()) { QStandardItem *it = new QStandardItem(); it->setText(f.fileName()); it->setData(path); #if QT_VERSION >= 0x040600 // Todo: Use a "favorites folder" icon instead it->setIcon(*globalIcon); #else it->setIcon(QIcon(":/images/icons/clip-folder-bookmark.png")); #endif it->setDropEnabled(true); if(row) insertRow(irow, it); else appendRow(it); emit bookmarkAdded(); }/*}}}*/ return true; }
QModelIndex AbstractCameraManager::detectNewCamerasAndExpand() { std::vector<AbstractCamera*> newCameras; std::vector<QStandardItem*> oldCameras; cameraTree_getCameraList(cameraTree.invisibleRootItem(), &oldCameras); detectNewCameras(&newCameras); qDebug() << "oldCameras" << oldCameras.size(); qDebug() << "newCameras" << newCameras.size(); //removing disconnected cameras for(unsigned int i=0; i<oldCameras.size(); i++) { QStandardItem* item = oldCameras.at(i); AbstractCamera* cam = reinterpret_cast<AbstractCamera *>( item->data(CameraRole).value<quintptr>() ); qDebug() << "oldCameras(" << i << "):" << cam; bool found = false; for(int j=newCameras.size()-1; j>=0; j--) { if(cam->equalsTo(newCameras.at(j))) { found = true; newCameras.erase(newCameras.begin()+j); continue; } } if( !found ) { //remove if disconnected activateCamera(cam, item, false); item->parent()->removeRow(item->row()); } } qDebug() << "newCameras" << newCameras.size(); //adding new cameras for(unsigned int i=0; i<newCameras.size(); i++) { AbstractCamera* cam = newCameras.at(i); QStandardItem *item = new QStandardItem(cam->getString().c_str()); item->setData(QVariant::fromValue( reinterpret_cast<quintptr>(cam) ), CameraRole); //qDebug() << "setData " << camera << " data " << item->data(CameraRole).value<AbstractCamera *>(); item->setCheckable(true); item->setCheckState(Qt::Unchecked); item->setDropEnabled(false); newCameraList.appendRow(item); } return newCameraList.index(); }
void Load::setMedia(const QStringList urlList, const QString title) { if (urlList.isEmpty()) { return; } APlayer::instance()->setMedia(urlList[0]); List *list = List::instance(); list->removeRow(list->rowCount()-1); int count = 1; QModelIndexList indexes; for (const QString &url : urlList) { QStandardItem *i = new QStandardItem; i->setText(title + QString::number(count)); i->setData(url, List::FileRole); i->setEditable(false); i->setDropEnabled(false); list->appendRow(i); indexes.append(i->index()); count++; } list->merge(indexes); }
void tst_QStandardItem::getSetFlags() { QStandardItem item; item.setEnabled(true); QVERIFY(item.isEnabled()); QVERIFY(item.flags() & Qt::ItemIsEnabled); item.setEditable(true); QVERIFY(item.isEditable()); QVERIFY(item.flags() & Qt::ItemIsEditable); item.setSelectable(true); QVERIFY(item.isSelectable()); QVERIFY(item.flags() & Qt::ItemIsSelectable); item.setCheckable(true); QVERIFY(item.isCheckable()); QCOMPARE(item.checkState(), Qt::Unchecked); QVERIFY(item.flags() & Qt::ItemIsUserCheckable); item.setTristate(true); QVERIFY(item.isTristate()); QVERIFY(item.flags() & Qt::ItemIsTristate); #ifndef QT_NO_DRAGANDDROP item.setDragEnabled(true); QVERIFY(item.isDragEnabled()); QVERIFY(item.flags() & Qt::ItemIsDragEnabled); item.setDropEnabled(true); QVERIFY(item.isDropEnabled()); QVERIFY(item.flags() & Qt::ItemIsDropEnabled); #endif QVERIFY(item.isEnabled()); item.setEnabled(false); QVERIFY(!item.isEnabled()); QVERIFY(!(item.flags() & Qt::ItemIsEnabled)); QVERIFY(item.isEditable()); item.setEditable(false); QVERIFY(!item.isEditable()); QVERIFY(!(item.flags() & Qt::ItemIsEditable)); QVERIFY(item.isSelectable()); item.setSelectable(false); QVERIFY(!item.isSelectable()); QVERIFY(!(item.flags() & Qt::ItemIsSelectable)); QVERIFY(item.isCheckable()); item.setCheckable(false); QVERIFY(!item.isCheckable()); QVERIFY(!(item.flags() & Qt::ItemIsUserCheckable)); QVERIFY(item.isTristate()); item.setTristate(false); QVERIFY(!item.isTristate()); QVERIFY(!(item.flags() & Qt::ItemIsTristate)); #ifndef QT_NO_DRAGANDDROP QVERIFY(item.isDragEnabled()); item.setDragEnabled(false); QVERIFY(!item.isDragEnabled()); QVERIFY(!(item.flags() & Qt::ItemIsDragEnabled)); QVERIFY(item.isDropEnabled()); item.setDropEnabled(false); QVERIFY(!item.isDropEnabled()); QVERIFY(!(item.flags() & Qt::ItemIsDropEnabled)); #endif item.setCheckable(false); item.setCheckState(Qt::Checked); item.setCheckable(true); QCOMPARE(item.checkState(), Qt::Checked); }