void RuleDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV4 o = option; o.text = index.model()->data(index, Qt::DisplayRole).toString(); o.displayAlignment = Qt::AlignCenter; int column = index.model()->headerData(index.column(),Qt::Horizontal,bfmodel::IdRole).toInt(); // if (index.column() < 6) o.state = QStyle::State_ReadOnly; QVariantList l = index.model()->data(index, bfmodel::DirtyRole).toList(); if (l.contains(column)) o.font.setBold(true); int value = index.model()->data(index, Qt::DisplayRole).toInt(); switch(column) { case bfmodel::SRCIP: if(value ==0) o.text = "ALL"; else o.text = QHostAddress(static_cast<quint32>(value)).toString(); break; case bfmodel::SRCPORT: if(value ==0) o.text = "ALL"; break; case bfmodel::DSTIP: if(value ==0) o.text = "ALL"; else o.text = QHostAddress(static_cast<quint32>(value)).toString(); break; case bfmodel::DSTPORT: if(value ==0) o.text = "ALL"; break; case bfmodel::PROTO: o.text = get_proto_name(value); break; case bfmodel::CHAIN: o.text = get_chain_name(static_cast<bf_chain_t>(value)); break; case bfmodel::POLICY: o.text = get_policy_name(static_cast<bf_policy_t>(value)); break; case bfmodel::OFF: o.text = get_sw_name(static_cast<bf_switch_rules_t>(value)); break; } QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &o, painter); }
void CReportDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { const QAbstractItemModel* model = index.model(); QVariant data = index.data(Qt::DisplayRole); //Populate the editor if(data.type() != QVariant::List) QStyledItemDelegate::setEditorData(editor,index); QVariantList validReports = index.data(Qt::EditRole).toList(); QVariantList currentReportsList = data.toList(); QListWidget* listWidget = static_cast<QListWidget*>(editor); // Prepare the items in the list foreach(QVariant dataElement,validReports) { QString outString = dataElement.toString(); if(m_reportNameModel!=(QAbstractItemModel*)NULL) { outString+=":"+searchReportColumnForId(dataElement.toInt()); } QListWidgetItem* item = new QListWidgetItem(outString); item->setData(Qt::UserRole,dataElement); //Now, determine if the ítem SHOULD be checked if(currentReportsList.contains(dataElement)) { item->setCheckState(Qt::Checked); } else { item->setCheckState(Qt::Unchecked); } listWidget->addItem(item); }
bool TestBindata::cbRemove2 (QVariantList list) { QVariant hash (m_serverhash); TVERIFY (!list.contains (hash), "Server still contains Bindata"); waitDone (); return true; }
bool TestBindata::cbList (QVariantList list) { QVariant hash (m_serverhash); TVERIFY (list.contains (hash), "Server doesn't have the file we sent"); waitDone (); return true; }
/// @remark Enables a 'pending' logic in SyncManager, with which a script can throttle the sending of entities to clients. QVariantList SceneSyncState::PendingEntityIDs() const { QVariantList list; for(PendingConstIter iter = pendingEntities_.begin(); iter != pendingEntities_.end(); ++iter) { entity_id_t id = (*iter); if (!list.contains(id)) list << id; } return list; }
void tst_TimelineNotesModel::selection() { TestNotesModel notes; TestModel model; notes.addTimelineModel(&model); int id1 = notes.add(10, 0, QLatin1String("blablub")); int id2 = notes.add(10, 0, QLatin1String("xyz")); QVariantList ids = notes.byTimelineModel(10); QCOMPARE(ids.length(), 2); QVERIFY(ids.contains(id1)); QVERIFY(ids.contains(id2)); ids = notes.byTypeId(7); QCOMPARE(ids.length(), 2); QVERIFY(ids.contains(id1)); QVERIFY(ids.contains(id2)); int got = notes.get(10, 0); QVERIFY(got == id1 || got == id2); QCOMPARE(notes.get(10, 20), -1); QCOMPARE(notes.get(20, 10), -1); }
QVariantList Capture::availableSizes(const QString &webcam) const { MediaTypesList mediaTypes = this->listMediaTypes(webcam); if (mediaTypes.isEmpty()) return QVariantList(); QVariantList resolutions; foreach (MediaTypePtr mediaType, mediaTypes) { VIDEOINFOHEADER *pInfoHeader = (VIDEOINFOHEADER *) mediaType->pbFormat; QSize size(pInfoHeader->bmiHeader.biWidth, pInfoHeader->bmiHeader.biHeight); if (!resolutions.contains(size)) resolutions << size; }
ServicesPanel::ServicesPanel(QWidget * parent) : XLet(parent, tr("Services"), ":/images/tab-services.svg"), m_nofwd_sent(false) { this->ui.setupUi(this); QVariantList features = b_engine->getConfig("services").toList(); if (! features.contains("incallfilter")) { this->ui.call_filtering_checkbox->hide(); } if (! features.contains("enablednd")) { this->ui.dnd_checkbox->hide(); } if (! features.contains("fwdunc")) { this->ui.fwdunc_input->hide(); this->ui.fwdunc_button->hide(); this->ui.fwdunc_radiobutton->hide(); } if (! features.contains("fwdrna")) { this->ui.fwdna_input->hide(); this->ui.fwdna_button->hide(); this->ui.fwdna_checkbox->hide(); } if (! features.contains("fwdbusy")) { this->ui.fwdbusy_input->hide(); this->ui.fwdbusy_button->hide(); this->ui.fwdbusy_checkbox->hide(); } if (! features.contains("fwdrna") && ! features.contains("fwdbusy")) { this->ui.fwdsimple_radiobutton->hide(); } //hide search button inside input this->ui.fwdna_button->hide(); this->ui.fwdbusy_button->hide(); this->ui.fwdunc_button->hide(); connect(b_engine, SIGNAL(updateUserConfig(const QString &, const QVariantMap &)), this, SLOT(updateUserConfig(const QString &, const QVariantMap &))); }
/*! Creates a input tag with type="checkbox", name=\a "name" and value=\a "value". If the \a checkedValues parameter contains the \a value parameter, this checkbox is checked. */ QString TViewHelper::checkBoxTag(const QString &name, const QVariant &value, const QVariantList &checkedValues, const THtmlAttribute &attributes) const { return checkBoxTag(name, value, (!value.toString().isEmpty() && checkedValues.contains(value)), attributes); }
bool LibArchiveInterface::copyFiles(const QVariantList& files, const QString& destinationDirectory, ExtractionOptions options) { kDebug() << "Changing current directory to " << destinationDirectory; QDir::setCurrent(destinationDirectory); const bool extractAll = files.isEmpty(); const bool preservePaths = options.value(QLatin1String( "PreservePaths" )).toBool(); QString rootNode = options.value(QLatin1String("RootNode"), QVariant()).toString(); if ((!rootNode.isEmpty()) && (!rootNode.endsWith(QLatin1Char('/')))) { rootNode.append(QLatin1Char('/')); } ArchiveRead arch(archive_read_new()); if (!(arch.data())) { return false; } if (archive_read_support_compression_all(arch.data()) != ARCHIVE_OK) { return false; } if (archive_read_support_format_all(arch.data()) != ARCHIVE_OK) { return false; } if (archive_read_open_filename(arch.data(), QFile::encodeName(filename()), 10240) != ARCHIVE_OK) { emit error(i18nc("@info", "Could not open the archive <filename>%1</filename>, libarchive cannot handle it.", filename())); return false; } ArchiveWrite writer(archive_write_disk_new()); if (!(writer.data())) { return false; } archive_write_disk_set_options(writer.data(), extractionFlags()); int entryNr = 0; int totalCount = 0; if (extractAll) { if (!m_cachedArchiveEntryCount) { emit progress(0); //TODO: once information progress has been implemented, send //feedback here that the archive is being read kDebug() << "For getting progress information, the archive will be listed once"; m_emitNoEntries = true; list(); m_emitNoEntries = false; } totalCount = m_cachedArchiveEntryCount; } else { totalCount = files.size(); } m_currentExtractedFilesSize = 0; bool overwriteAll = false; // Whether to overwrite all files bool skipAll = false; // Whether to skip all files struct archive_entry *entry; QString fileBeingRenamed; while (archive_read_next_header(arch.data(), &entry) == ARCHIVE_OK) { fileBeingRenamed.clear(); // retry with renamed entry, fire an overwrite query again // if the new entry also exists retry: const bool entryIsDir = S_ISDIR(archive_entry_mode(entry)); //we skip directories if not preserving paths if (!preservePaths && entryIsDir) { archive_read_data_skip(arch.data()); continue; } //entryName is the name inside the archive, full path QString entryName = QDir::fromNativeSeparators(QFile::decodeName(archive_entry_pathname(entry))); if (entryName.startsWith(QLatin1Char( '/' ))) { //for now we just can't handle absolute filenames in a tar archive. //TODO: find out what to do here!! emit error(i18n("This archive contains archive entries with absolute paths, which are not yet supported by ark.")); return false; } if (files.contains(entryName) || entryName == fileBeingRenamed || extractAll) { // entryFI is the fileinfo pointing to where the file will be // written from the archive QFileInfo entryFI(entryName); //kDebug() << "setting path to " << archive_entry_pathname( entry ); const QString fileWithoutPath(entryFI.fileName()); //if we DON'T preserve paths, we cut the path and set the entryFI //fileinfo to the one without the path if (!preservePaths) { //empty filenames (ie dirs) should have been skipped already, //so asserting Q_ASSERT(!fileWithoutPath.isEmpty()); archive_entry_copy_pathname(entry, QFile::encodeName(fileWithoutPath).constData()); entryFI = QFileInfo(fileWithoutPath); //OR, if the commonBase has been set, then we remove this //common base from the filename } else if (!rootNode.isEmpty()) { kDebug() << "Removing" << rootNode << "from" << entryName; const QString truncatedFilename(entryName.remove(0, rootNode.size())); archive_entry_copy_pathname(entry, QFile::encodeName(truncatedFilename).constData()); entryFI = QFileInfo(truncatedFilename); } //now check if the file about to be written already exists if (!entryIsDir && entryFI.exists()) { if (skipAll) { archive_read_data_skip(arch.data()); archive_entry_clear(entry); continue; } else if (!overwriteAll && !skipAll) { Kerfuffle::OverwriteQuery query(entryName); emit userQuery(&query); query.waitForResponse(); if (query.responseCancelled()) { archive_read_data_skip(arch.data()); archive_entry_clear(entry); break; } else if (query.responseSkip()) { archive_read_data_skip(arch.data()); archive_entry_clear(entry); continue; } else if (query.responseAutoSkip()) { archive_read_data_skip(arch.data()); archive_entry_clear(entry); skipAll = true; continue; } else if (query.responseRename()) { const QString newName(query.newFilename()); fileBeingRenamed = newName; archive_entry_copy_pathname(entry, QFile::encodeName(newName).constData()); goto retry; } else if (query.responseOverwriteAll()) { overwriteAll = true; } } } //if there is an already existing directory: if (entryIsDir && entryFI.exists()) { if (entryFI.isWritable()) { kDebug(1601) << "Warning, existing, but writable dir"; } else { kDebug(1601) << "Warning, existing, but non-writable dir. skipping"; archive_entry_clear(entry); archive_read_data_skip(arch.data()); continue; } } int header_response; kDebug() << "Writing " << fileWithoutPath << " to " << archive_entry_pathname(entry); if ((header_response = archive_write_header(writer.data(), entry)) == ARCHIVE_OK) { //if the whole archive is extracted and the total filesize is //available, we use partial progress copyData(arch.data(), writer.data(), (extractAll && m_extractedFilesSize)); } else if (header_response == ARCHIVE_WARN) { kDebug() << "Warning while writing " << entryName; } else { kDebug() << "Writing header failed with error code " << header_response << "While attempting to write " << entryName; } //if we only partially extract the archive and the number of //archive entries is available we use a simple progress based on //number of items extracted if (!extractAll && m_cachedArchiveEntryCount) { ++entryNr; emit progress(float(entryNr) / totalCount); } archive_entry_clear(entry); } else { archive_read_data_skip(arch.data()); } } return archive_read_close(arch.data()) == ARCHIVE_OK; }