本文整理汇总了C++中QScopedPointer类的典型用法代码示例。如果您正苦于以下问题:C++ QScopedPointer类的具体用法?C++ QScopedPointer怎么用?C++ QScopedPointer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QScopedPointer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defined
/*!
\reimp
*/
QIODevice *QNetworkDiskCache::data(const QUrl &url)
{
#if defined(QNETWORKDISKCACHE_DEBUG)
qDebug() << "QNetworkDiskCache::data()" << url;
#endif
Q_D(QNetworkDiskCache);
QScopedPointer<QBuffer> buffer;
if (!url.isValid())
return 0;
if (d->lastItem.metaData.url() == url && d->lastItem.data.isOpen()) {
buffer.reset(new QBuffer);
buffer->setData(d->lastItem.data.data());
} else {
QScopedPointer<QFile> file(new QFile(d->cacheFileName(url)));
if (!file->open(QFile::ReadOnly | QIODevice::Unbuffered))
return 0;
if (!d->lastItem.read(file.data(), true)) {
file->close();
remove(url);
return 0;
}
if (d->lastItem.data.isOpen()) {
// compressed
buffer.reset(new QBuffer);
buffer->setData(d->lastItem.data.data());
} else {
buffer.reset(new QBuffer);
// ### verify that QFile uses the fd size and not the file name
qint64 size = file->size() - file->pos();
const uchar *p = 0;
#if !defined(Q_OS_WINCE) && !defined(Q_OS_INTEGRITY)
p = file->map(file->pos(), size);
#endif
if (p) {
buffer->setData((const char *)p, size);
file.take()->setParent(buffer.data());
} else {
buffer->setData(file->readAll());
}
}
}
buffer->open(QBuffer::ReadOnly);
return buffer.take();
}
示例2: main
//.........这里部分代码省略.........
}
if (exeFile.isEmpty() && sisFile.isEmpty() &&
(downloadLocalFile.isEmpty() || downloadRemoteFile.isEmpty())) {
printUsage(outstream, args[0]);
return 1;
}
if (serialPortName.isEmpty()) {
if (loglevel > 0)
outstream << "Detecting serial ports" << endl;
foreach (const SerialPortId &id, enumerateSerialPorts(loglevel)) {
if (loglevel > 0)
outstream << "Port Name: " << id.portName << ", "
<< "Friendly Name:" << id.friendlyName << endl;
if (!id.friendlyName.isEmpty()
&& serialPortFriendlyName.isEmpty()
&& (id.friendlyName.contains("symbian", Qt::CaseInsensitive)
|| id.friendlyName.contains("s60", Qt::CaseInsensitive)
|| id.friendlyName.contains("nokia", Qt::CaseInsensitive))) {
serialPortName = id.portName;
break;
} else if (!id.friendlyName.isEmpty()
&& !serialPortFriendlyName.isEmpty()
&& id.friendlyName.contains(serialPortFriendlyName)) {
serialPortName = id.portName;
break;
}
}
if (serialPortName.isEmpty()) {
errstream << "No phone found, ensure USB cable is connected or specify manually with -p" << endl;
return 1;
}
}
QScopedPointer<trk::Launcher> launcher;
launcher.reset(new trk::Launcher(trk::Launcher::ActionPingOnly));
QFileInfo info(exeFile);
if (!sisFile.isEmpty()) {
launcher->addStartupActions(trk::Launcher::ActionCopyInstall);
launcher->setCopyFileName(sisFile, "c:\\data\\testtemp.sis");
launcher->setInstallFileName("c:\\data\\testtemp.sis");
}
else if (info.exists()) {
launcher->addStartupActions(trk::Launcher::ActionCopy);
launcher->setCopyFileName(exeFile, QString("c:\\sys\\bin\\") + info.fileName());
}
if (!exeFile.isEmpty()) {
launcher->addStartupActions(trk::Launcher::ActionRun);
launcher->setFileName(QString("c:\\sys\\bin\\") + info.fileName());
launcher->setCommandLineArgs(cmdLine);
}
if (!downloadRemoteFile.isEmpty() && !downloadLocalFile.isEmpty()) {
launcher->addStartupActions(trk::Launcher::ActionDownload);
launcher->setDownloadFileName(downloadRemoteFile, downloadLocalFile);
}
if (loglevel > 0)
outstream << "Connecting to target via " << serialPortName << endl;
launcher->setTrkServerName(serialPortName);
if (loglevel > 1)
launcher->setVerbose(1);
TrkSignalHandler handler;
handler.setLogLevel(loglevel);
QObject::connect(launcher.data(), SIGNAL(copyingStarted()), &handler, SLOT(copyingStarted()));
QObject::connect(launcher.data(), SIGNAL(canNotConnect(const QString &)), &handler, SLOT(canNotConnect(const QString &)));
QObject::connect(launcher.data(), SIGNAL(canNotCreateFile(const QString &, const QString &)), &handler, SLOT(canNotCreateFile(const QString &, const QString &)));
QObject::connect(launcher.data(), SIGNAL(canNotWriteFile(const QString &, const QString &)), &handler, SLOT(canNotWriteFile(const QString &, const QString &)));
QObject::connect(launcher.data(), SIGNAL(canNotCloseFile(const QString &, const QString &)), &handler, SLOT(canNotCloseFile(const QString &, const QString &)));
QObject::connect(launcher.data(), SIGNAL(installingStarted()), &handler, SLOT(installingStarted()));
QObject::connect(launcher.data(), SIGNAL(canNotInstall(const QString &, const QString &)), &handler, SLOT(canNotInstall(const QString &, const QString &)));
QObject::connect(launcher.data(), SIGNAL(installingFinished()), &handler, SLOT(installingFinished()));
QObject::connect(launcher.data(), SIGNAL(startingApplication()), &handler, SLOT(startingApplication()));
QObject::connect(launcher.data(), SIGNAL(applicationRunning(uint)), &handler, SLOT(applicationRunning(uint)));
QObject::connect(launcher.data(), SIGNAL(canNotRun(const QString &)), &handler, SLOT(canNotRun(const QString &)));
QObject::connect(launcher.data(), SIGNAL(applicationOutputReceived(const QString &)), &handler, SLOT(applicationOutputReceived(const QString &)));
QObject::connect(launcher.data(), SIGNAL(copyProgress(int)), &handler, SLOT(copyProgress(int)));
QObject::connect(launcher.data(), SIGNAL(stateChanged(int)), &handler, SLOT(stateChanged(int)));
QObject::connect(launcher.data(), SIGNAL(processStopped(uint,uint,uint,QString)), &handler, SLOT(stopped(uint,uint,uint,QString)));
QObject::connect(&handler, SIGNAL(resume(uint,uint)), launcher.data(), SLOT(resumeProcess(uint,uint)));
QObject::connect(&handler, SIGNAL(terminate()), launcher.data(), SLOT(terminate()));
QObject::connect(launcher.data(), SIGNAL(finished()), &handler, SLOT(finished()));
QTimer timer;
timer.setSingleShot(true);
QObject::connect(&timer, SIGNAL(timeout()), &handler, SLOT(timeout()));
if (timeout > 0) {
timer.start(timeout);
}
QString errorMessage;
if (!launcher->startServer(&errorMessage)) {
errstream << errorMessage << endl;
return 1;
}
return a.exec();
}
示例3: randomGen
void KeePass2Writer::writeDatabase(QIODevice* device, Database* db)
{
m_error = false;
m_errorStr.clear();
QByteArray masterSeed = randomGen()->randomArray(32);
QByteArray encryptionIV = randomGen()->randomArray(16);
QByteArray protectedStreamKey = randomGen()->randomArray(32);
QByteArray startBytes = randomGen()->randomArray(32);
QByteArray endOfHeader = "\r\n\r\n";
CryptoHash hash(CryptoHash::Sha256);
hash.addData(masterSeed);
Q_ASSERT(!db->transformedMasterKey().isEmpty());
hash.addData(db->transformedMasterKey());
QByteArray finalKey = hash.result();
QBuffer header;
header.open(QIODevice::WriteOnly);
m_device = &header;
CHECK_RETURN(writeData(Endian::int32ToBytes(KeePass2::SIGNATURE_1, KeePass2::BYTEORDER)));
CHECK_RETURN(writeData(Endian::int32ToBytes(KeePass2::SIGNATURE_2, KeePass2::BYTEORDER)));
CHECK_RETURN(writeData(Endian::int32ToBytes(KeePass2::FILE_VERSION, KeePass2::BYTEORDER)));
CHECK_RETURN(writeHeaderField(KeePass2::CipherID, db->cipher().toByteArray()));
CHECK_RETURN(writeHeaderField(KeePass2::CompressionFlags,
Endian::int32ToBytes(db->compressionAlgo(),
KeePass2::BYTEORDER)));
CHECK_RETURN(writeHeaderField(KeePass2::MasterSeed, masterSeed));
CHECK_RETURN(writeHeaderField(KeePass2::TransformSeed, db->transformSeed()));
CHECK_RETURN(writeHeaderField(KeePass2::TransformRounds,
Endian::int64ToBytes(db->transformRounds(),
KeePass2::BYTEORDER)));
CHECK_RETURN(writeHeaderField(KeePass2::EncryptionIV, encryptionIV));
CHECK_RETURN(writeHeaderField(KeePass2::ProtectedStreamKey, protectedStreamKey));
CHECK_RETURN(writeHeaderField(KeePass2::StreamStartBytes, startBytes));
CHECK_RETURN(writeHeaderField(KeePass2::InnerRandomStreamID,
Endian::int32ToBytes(KeePass2::Salsa20,
KeePass2::BYTEORDER)));
CHECK_RETURN(writeHeaderField(KeePass2::EndOfHeader, endOfHeader));
header.close();
m_device = device;
QByteArray headerHash = CryptoHash::hash(header.data(), CryptoHash::Sha256);
CHECK_RETURN(writeData(header.data()));
SymmetricCipherStream cipherStream(device, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
SymmetricCipher::Encrypt, finalKey, encryptionIV);
cipherStream.open(QIODevice::WriteOnly);
m_device = &cipherStream;
CHECK_RETURN(writeData(startBytes));
HashedBlockStream hashedStream(&cipherStream);
hashedStream.open(QIODevice::WriteOnly);
QScopedPointer<QtIOCompressor> ioCompressor;
if (db->compressionAlgo() == Database::CompressionNone) {
m_device = &hashedStream;
}
else {
ioCompressor.reset(new QtIOCompressor(&hashedStream));
ioCompressor->setStreamFormat(QtIOCompressor::GzipFormat);
ioCompressor->open(QIODevice::WriteOnly);
m_device = ioCompressor.data();
}
KeePass2RandomStream randomStream(protectedStreamKey);
KeePass2XmlWriter xmlWriter;
xmlWriter.writeDatabase(m_device, db, &randomStream, headerHash);
}
示例4: createExpressionContext
int QgsAtlasComposition::updateFeatures()
{
//needs to be called when layer, filter, sort changes
if ( !mCoverageLayer )
{
return 0;
}
QgsExpressionContext expressionContext = createExpressionContext();
updateFilenameExpression();
// select all features with all attributes
QgsFeatureRequest req;
QScopedPointer<QgsExpression> filterExpression;
if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
{
filterExpression.reset( new QgsExpression( mFeatureFilter ) );
if ( filterExpression->hasParserError() )
{
mFilterParserError = filterExpression->parserErrorString();
return 0;
}
//filter good to go
req.setFilterExpression( mFeatureFilter );
}
mFilterParserError = QString();
QgsFeatureIterator fit = mCoverageLayer->getFeatures( req );
QScopedPointer<QgsExpression> nameExpression;
if ( !mPageNameExpression.isEmpty() )
{
nameExpression.reset( new QgsExpression( mPageNameExpression ) );
if ( nameExpression->hasParserError() )
{
nameExpression.reset( nullptr );
}
nameExpression->prepare( &expressionContext );
}
// We cannot use nextFeature() directly since the feature pointer is rewinded by the rendering process
// We thus store the feature ids for future extraction
QgsFeature feat;
mFeatureIds.clear();
mFeatureKeys.clear();
int sortIdx = mCoverageLayer->fieldNameIndex( mSortKeyAttributeName );
while ( fit.nextFeature( feat ) )
{
expressionContext.setFeature( feat );
QString pageName;
if ( !nameExpression.isNull() )
{
QVariant result = nameExpression->evaluate( &expressionContext );
if ( nameExpression->hasEvalError() )
{
QgsMessageLog::logMessage( tr( "Atlas name eval error: %1" ).arg( nameExpression->evalErrorString() ), tr( "Composer" ) );
}
pageName = result.toString();
}
mFeatureIds.push_back( qMakePair( feat.id(), pageName ) );
if ( mSortFeatures && sortIdx != -1 )
{
mFeatureKeys.insert( feat.id(), feat.attributes().at( sortIdx ) );
}
}
// sort features, if asked for
if ( !mFeatureKeys.isEmpty() )
{
FieldSorter sorter( mFeatureKeys, mSortAscending );
qSort( mFeatureIds.begin(), mFeatureIds.end(), sorter );
}
emit numberFeaturesChanged( mFeatureIds.size() );
//jump to first feature if currently using an atlas preview
//need to do this in case filtering/layer change has altered matching features
if ( mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
firstFeature();
}
return mFeatureIds.size();
}
示例5: self
GasSelectionModel *GasSelectionModel::instance()
{
static QScopedPointer<GasSelectionModel> self(new GasSelectionModel());
return self.data();
}
示例6: self
WSInfoModel *WSInfoModel::instance()
{
static QScopedPointer<WSInfoModel> self(new WSInfoModel());
return self.data();
}
示例7: slotStateChanged
void StateListener::slotStateChanged()
{
// Get the current file. Are we on a temporary submit editor indicated by
// temporary path prefix or does the file contains a hash, indicating a project
// folder?
State state;
IDocument *currentDocument = EditorManager::currentDocument();
if (!currentDocument) {
state.currentFile.clear();
} else {
state.currentFile = currentDocument->filePath().toString();
if (state.currentFile.isEmpty() || currentDocument->isTemporary())
state.currentFile = VcsBasePlugin::source(currentDocument);
}
QScopedPointer<QFileInfo> currentFileInfo; // Instantiate QFileInfo only once if required.
if (!state.currentFile.isEmpty()) {
const bool isTempFile = state.currentFile.startsWith(QDir::tempPath());
// Quick check: Does it look like a patch?
const bool isPatch = state.currentFile.endsWith(QLatin1String(".patch"))
|| state.currentFile.endsWith(QLatin1String(".diff"));
if (isPatch) {
// Patch: Figure out a name to display. If it is a temp file, it could be
// Codepaster. Use the display name of the editor.
state.currentPatchFile = state.currentFile;
if (isTempFile)
state.currentPatchFileDisplayName = displayNameOfEditor(state.currentPatchFile);
if (state.currentPatchFileDisplayName.isEmpty()) {
currentFileInfo.reset(new QFileInfo(state.currentFile));
state.currentPatchFileDisplayName = currentFileInfo->fileName();
}
}
// For actual version control operations on it:
// Do not show temporary files and project folders ('#')
if (isTempFile || state.currentFile.contains(QLatin1Char('#')))
state.currentFile.clear();
}
// Get the file and its control. Do not use the file unless we find one
IVersionControl *fileControl = 0;
if (!state.currentFile.isEmpty()) {
if (currentFileInfo.isNull())
currentFileInfo.reset(new QFileInfo(state.currentFile));
if (currentFileInfo->isDir()) {
state.currentFile.clear();
state.currentFileDirectory = currentFileInfo->absoluteFilePath();
} else {
state.currentFileDirectory = currentFileInfo->absolutePath();
state.currentFileName = currentFileInfo->fileName();
}
fileControl = VcsManager::findVersionControlForDirectory(
state.currentFileDirectory,
&state.currentFileTopLevel);
if (!fileControl)
state.clearFile();
}
// Check for project, find the control
IVersionControl *projectControl = 0;
Project *currentProject = ProjectTree::currentProject();
if (!currentProject)
currentProject = SessionManager::startupProject();
if (currentProject) {
state.currentProjectPath = currentProject->projectDirectory().toString();
state.currentProjectName = currentProject->displayName();
projectControl = VcsManager::findVersionControlForDirectory(state.currentProjectPath,
&state.currentProjectTopLevel);
if (projectControl) {
// If we have both, let the file's one take preference
if (fileControl && projectControl != fileControl)
state.clearProject();
} else {
state.clearProject(); // No control found
}
}
// Assemble state and emit signal.
IVersionControl *vc = fileControl;
if (!vc)
vc = projectControl;
if (!vc)
state.clearPatchFile(); // Need a repository to patch
if (debug)
qDebug() << state << (vc ? vc->displayName() : QLatin1String("No version control"));
EditorManager::updateWindowTitles();
emit stateChanged(state, vc);
}
示例8: extentGeom
QgsLabelFeature* QgsVectorLayerDiagramProvider::registerDiagram( QgsFeature& feat, QgsRenderContext &context, QgsGeometry* obstacleGeometry )
{
const QgsMapSettings& mapSettings = mEngine->mapSettings();
QgsDiagramRendererV2* dr = mSettings.renderer;
if ( dr )
{
QList<QgsDiagramSettings> settingList = dr->diagramSettings();
if ( !settingList.isEmpty() && settingList.at( 0 ).scaleBasedVisibility )
{
double minScale = settingList.at( 0 ).minScaleDenominator;
if ( minScale > 0 && context.rendererScale() < minScale )
{
return 0;
}
double maxScale = settingList.at( 0 ).maxScaleDenominator;
if ( maxScale > 0 && context.rendererScale() > maxScale )
{
return 0;
}
}
}
//convert geom to geos
const QgsGeometry* geom = feat.constGeometry();
QScopedPointer<QgsGeometry> extentGeom( QgsGeometry::fromRect( mapSettings.visibleExtent() ) );
if ( !qgsDoubleNear( mapSettings.rotation(), 0.0 ) )
{
//PAL features are prerotated, so extent also needs to be unrotated
extentGeom->rotate( -mapSettings.rotation(), mapSettings.visibleExtent().center() );
}
const GEOSGeometry* geos_geom = 0;
QScopedPointer<QgsGeometry> preparedGeom;
if ( QgsPalLabeling::geometryRequiresPreparation( geom, context, mSettings.ct, extentGeom.data() ) )
{
preparedGeom.reset( QgsPalLabeling::prepareGeometry( geom, context, mSettings.ct, extentGeom.data() ) );
if ( !preparedGeom.data() )
return 0;
geos_geom = preparedGeom.data()->asGeos();
}
else
{
geos_geom = geom->asGeos();
}
if ( geos_geom == 0 )
{
return 0; // invalid geometry
}
GEOSGeometry* geomCopy = GEOSGeom_clone_r( QgsGeometry::getGEOSHandler(), geos_geom );
const GEOSGeometry* geosObstacleGeom = 0;
QScopedPointer<QgsGeometry> scopedObstacleGeom;
if ( mSettings.obstacle && obstacleGeometry && QgsPalLabeling::geometryRequiresPreparation( obstacleGeometry, context, mSettings.ct, extentGeom.data() ) )
{
scopedObstacleGeom.reset( QgsPalLabeling::prepareGeometry( obstacleGeometry, context, mSettings.ct, extentGeom.data() ) );
geosObstacleGeom = scopedObstacleGeom.data()->asGeos();
}
else if ( mSettings.obstacle && obstacleGeometry )
{
geosObstacleGeom = obstacleGeometry->asGeos();
}
GEOSGeometry* geosObstacleGeomClone = 0;
if ( geosObstacleGeom )
{
geosObstacleGeomClone = GEOSGeom_clone_r( QgsGeometry::getGEOSHandler(), geosObstacleGeom );
}
double diagramWidth = 0;
double diagramHeight = 0;
if ( dr )
{
QSizeF diagSize = dr->sizeMapUnits( feat, context );
if ( diagSize.isValid() )
{
diagramWidth = diagSize.width();
diagramHeight = diagSize.height();
}
}
// feature to the layer
bool alwaysShow = mSettings.showAll;
int ddColX = mSettings.xPosColumn;
int ddColY = mSettings.yPosColumn;
double ddPosX = 0.0;
double ddPosY = 0.0;
bool ddPos = ( ddColX >= 0 && ddColY >= 0 );
if ( ddPos )
{
bool posXOk, posYOk;
ddPosX = feat.attribute( ddColX ).toDouble( &posXOk );
ddPosY = feat.attribute( ddColY ).toDouble( &posYOk );
if ( !posXOk || !posYOk )
{
ddPos = false;
}
else
//.........这里部分代码省略.........
示例9: main
int main(int argc, char *argv[])
{
/* Workaround Qt platform integration plugin not advertising itself
as having the following capabilities:
- QPlatformIntegration::ThreadedOpenGL
- QPlatformIntegration::BufferQueueingOpenGL
*/
setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
// ignore favorites in unity-scopes-shell plugin
setenv("UNITY_SCOPES_NO_FAVORITES", "1", 1);
QGuiApplication::setApplicationName("Unity Scope Tool");
QGuiApplication *application;
application = new QGuiApplication(argc, argv);
QCommandLineParser parser;
parser.setApplicationDescription("Unity Scope Tool\n\n"
"This tool allows development and testing of scopes. Running it without\n"
"any arguments will open a session to all scopes available on the system.\n"
"Otherwise passing a path to a scope config file will open a session with\n"
"only that scope (assuming that the binary implementing the scope can be\n"
"found in the same directory as the config file).");
QCommandLineOption helpOption = parser.addHelpOption();
parser.addPositionalArgument("scopes", "Paths to scope config files to spawn, optionally.", "[scopes...]");
QCommandLineOption includeSystemScopes("include-system-scopes",
"Initialize the registry with scopes installed on this system");
QCommandLineOption includeServerScopes("include-server-scopes",
"Initialize the registry with scopes on the default server");
parser.addOption(includeServerScopes);
parser.addOption(includeSystemScopes);
parser.parse(application->arguments());
if (parser.isSet(helpOption)) {
parser.showHelp();
}
QStringList extraScopes = parser.positionalArguments();
QScopedPointer<RegistryTracker> tracker;
if (!extraScopes.isEmpty()) {
bool systemScopes = parser.isSet(includeSystemScopes);
bool serverScopes = parser.isSet(includeServerScopes);
tracker.reset(new RegistryTracker(extraScopes, systemScopes, serverScopes));
}
bindtextdomain("unity8", translationDirectory().toUtf8().data());
textdomain("unity8");
QQuickView* view = new QQuickView();
view->setResizeMode(QQuickView::SizeRootObjectToView);
view->setTitle(QGuiApplication::applicationName());
view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
QUrl source(::qmlDirectory() + "/ScopeTool.qml");
prependImportPaths(view->engine(), ::overrideImportPaths());
prependImportPaths(view->engine(), ::nonMirImportPaths());
appendImportPaths(view->engine(), ::fallbackImportPaths());
view->setSource(source);
view->show();
UnixSignalHandler signal_handler([]{
QGuiApplication::exit(0);
});
signal_handler.setupUnixSignalHandlers();
int result = application->exec();
delete view;
delete application;
return result;
}
示例10: self
DivePlannerPointsModel *DivePlannerPointsModel::instance()
{
static QScopedPointer<DivePlannerPointsModel> self(new DivePlannerPointsModel());
return self.data();
}
示例11: main
int main(int argc, char** argv)
{
QApplication app(argc,argv);
QStringList args = app.arguments();
if (args.count() < 2)
{
qWarning() << "Usage: qtinspector <pid>|<program> (<args>...)";
return -1;
}
QProcess process;
int targetPid = args.at(1).toInt();
// inject the helper library
QScopedPointer<Injector> injector;
if (targetPid != 0)
{
#ifdef Q_OS_UNIX
injector.reset(new GdbLibraryInjector);
#endif
if (!injector->inject(targetPid, injectorLibPath(), "qtInspectorInit"))
{
return false;
}
}
else
{
#ifdef Q_OS_UNIX
injector.reset(new PreloadInjector);
#endif
QStringList programArgs;
for (int i=2; i < args.count(); i++)
{
programArgs << args.at(i);
}
if (!injector->startAndInject(args.at(1),programArgs,injectorLibPath(),"qtInspectorInit",&targetPid))
{
return false;
}
}
TargetApplicationProxy proxy;
if (!proxy.connectToTarget(targetPid))
{
qWarning() << "Failed to inject helper library into process <pid>";
}
WidgetPicker* picker = new ExternalWidgetPicker(&proxy,0);
WidgetInspector inspector(&proxy);
inspector.setWidgetPicker(picker);
inspector.show();
int result = app.exec();
if (process.state() == QProcess::Running && !process.waitForFinished())
{
qWarning() << "Failed to wait for process" << process.pid() << "to exit";
}
return result;
}
示例12: context
bool QgsComposerAttributeTable::getFeatureAttributes( QList<QgsAttributeMap> &attributeMaps )
{
if ( !mVectorLayer )
{
return false;
}
QScopedPointer< QgsExpressionContext > context( createExpressionContext() );
context->setFields( mVectorLayer->fields() );
attributeMaps.clear();
//prepare filter expression
QScopedPointer<QgsExpression> filterExpression;
bool activeFilter = false;
if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
{
filterExpression.reset( new QgsExpression( mFeatureFilter ) );
if ( !filterExpression->hasParserError() )
{
activeFilter = true;
}
}
QgsRectangle selectionRect;
if ( mComposerMap && mShowOnlyVisibleFeatures )
{
selectionRect = *mComposerMap->currentMapExtent();
if ( mVectorLayer && mComposition->mapSettings().hasCrsTransformEnabled() )
{
//transform back to layer CRS
QgsCoordinateTransform coordTransform( mVectorLayer->crs(), mComposition->mapSettings().destinationCrs() );
try
{
selectionRect = coordTransform.transformBoundingBox( selectionRect, QgsCoordinateTransform::ReverseTransform );
}
catch ( QgsCsException &cse )
{
Q_UNUSED( cse );
return false;
}
}
}
QgsFeatureRequest req;
if ( !selectionRect.isEmpty() )
req.setFilterRect( selectionRect );
req.setFlags( mShowOnlyVisibleFeatures ? QgsFeatureRequest::ExactIntersect : QgsFeatureRequest::NoFlags );
QgsFeature f;
int counter = 0;
QgsFeatureIterator fit = mVectorLayer->getFeatures( req );
while ( fit.nextFeature( f ) && counter < mMaximumNumberOfFeatures )
{
context->setFeature( f );
//check feature against filter
if ( activeFilter && !filterExpression.isNull() )
{
QVariant result = filterExpression->evaluate( context.data() );
// skip this feature if the filter evaluation is false
if ( !result.toBool() )
{
continue;
}
}
attributeMaps.push_back( QgsAttributeMap() );
QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin();
int i = 0;
for ( ; columnIt != mColumns.constEnd(); ++columnIt )
{
int idx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
if ( idx != -1 )
{
attributeMaps.last().insert( i, f.attributes()[idx] );
}
else
{
// Lets assume it's an expression
QgsExpression* expression = new QgsExpression(( *columnIt )->attribute() );
context->lastScope()->setVariable( QString( "_rownum_" ), counter + 1 );
expression->prepare( context.data() );
QVariant value = expression->evaluate( context.data() );
attributeMaps.last().insert( i, value.toString() );
}
i++;
}
++counter;
}
//sort the list, starting with the last attribute
QgsComposerAttributeTableCompare c;
QList< QPair<int, bool> > sortColumns = sortAttributes();
for ( int i = sortColumns.size() - 1; i >= 0; --i )
{
c.setSortColumn( sortColumns.at( i ).first );
//.........这里部分代码省略.........
示例13: inputStream
synthclone::Sample *
SessionSampleData::updateSample(synthclone::Sample &sample, bool forceCopy,
QObject *parent)
{
if (! sampleDirectory) {
// The session is being unloaded.
return 0;
}
synthclone::SampleInputStream inputStream(sample);
ChannelConvertAlgorithm channelConvertAlgorithm;
synthclone::SampleChannelCount inputChannels = inputStream.getChannels();
if (sampleChannelCount == inputChannels) {
channelConvertAlgorithm = CHANNELCONVERTALGORITHM_NONE;
} else if (sampleChannelCount == 1) {
channelConvertAlgorithm = CHANNELCONVERTALGORITHM_TO_MONO;
} else if (inputChannels == 1) {
channelConvertAlgorithm = CHANNELCONVERTALGORITHM_FROM_MONO;
} else {
// How does one convert a multi-channel sample to a different channel
// count that isn't mono? I'm open to ideas.
return 0;
}
// If the sample rate isn't set, then set it to the sample rate of the new
// sample.
synthclone::SampleRate inputSampleRate = inputStream.getSampleRate();
if (sampleRate == synthclone::SAMPLE_RATE_NOT_SET) {
setSampleRate(inputSampleRate);
}
bool sampleConversionRequired = inputSampleRate != sampleRate;
QString newPath = createUniqueFile(sampleDirectory);
if ((channelConvertAlgorithm == CHANNELCONVERTALGORITHM_NONE) &&
(! sampleConversionRequired) && (! forceCopy)) {
if (sampleDirectory) {
if (QFileInfo(sample.getPath()).absolutePath() ==
sampleDirectory->absolutePath()) {
// Nothing needs to be done.
return &sample;
}
}
}
// At this point, either some sort of conversion is required, the sample is
// being moved from outside the sample directory into the sample directory,
// or a forced copy was requested.
float *channelBuffer;
// For some reason, the empty QScopedArrayPointer constructor is not
// available on the Mac OSX platform.
QScopedArrayPointer<float> channelBufferPtr(static_cast<float *>(0));
float *convertBuffer = new float[sampleChannelCount * 512];
QScopedArrayPointer<float> convertBufferPtr(convertBuffer);
SampleRateConverter *converter;
QScopedPointer<SampleRateConverter> converterPtr;
float *inputBuffer = new float[inputChannels * 512];
QScopedArrayPointer<float> inputBufferPtr(inputBuffer);
if (! sampleConversionRequired) {
channelBuffer = convertBuffer;
converter = 0;
} else {
if (channelConvertAlgorithm != CHANNELCONVERTALGORITHM_NONE) {
channelBuffer = new float[sampleChannelCount];
channelBufferPtr.reset(channelBuffer);
} else {
channelBuffer = inputBuffer;
}
double ratio = static_cast<double>(sampleRate) / inputSampleRate;
converter = new SampleRateConverter(sampleChannelCount, ratio, this);
converterPtr.reset(converter);
}
// Create the new sample object.
synthclone::Sample *outputSample = new synthclone::Sample(newPath, parent);
QScopedPointer<synthclone::Sample> outputSamplePtr(outputSample);
synthclone::SampleOutputStream
outputStream(*outputSample, sampleRate, sampleChannelCount);
// Convert.
synthclone::SampleFrameCount framesRead;
long outputFramesUsed;
do {
// Get data from input stream.
framesRead = inputStream.read(inputBuffer, 512);
// Channel conversion.
switch (channelConvertAlgorithm) {
case CHANNELCONVERTALGORITHM_TO_MONO:
for (int i = 0; i < framesRead; i++) {
float n = 0.0;
for (int j = 0; j < inputChannels; j++) {
n += inputBuffer[(i * inputChannels) + j];
}
channelBuffer[i] = n / inputChannels;
}
//.........这里部分代码省略.........
示例14: SSH_SERVER_EXCEPTION
void SshKeyExchange::sendNewKeysPacket(const SshIncomingPacket &dhReply,
const QByteArray &clientId)
{
const SshKeyExchangeReply &reply
= dhReply.extractKeyExchangeReply(m_serverHostKeyAlgo);
if (reply.f <= 0 || reply.f >= m_dhKey->group_p()) {
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_KEY_EXCHANGE_FAILED,
"Server sent invalid f.");
}
QByteArray concatenatedData = AbstractSshPacket::encodeString(clientId);
concatenatedData += AbstractSshPacket::encodeString(m_serverId);
concatenatedData += AbstractSshPacket::encodeString(m_clientKexInitPayload);
concatenatedData += AbstractSshPacket::encodeString(m_serverKexInitPayload);
concatenatedData += reply.k_s;
concatenatedData += AbstractSshPacket::encodeMpInt(m_dhKey->get_y());
concatenatedData += AbstractSshPacket::encodeMpInt(reply.f);
const BigInt k = power_mod(reply.f, m_dhKey->get_x(), m_dhKey->get_domain().get_p());
m_k = AbstractSshPacket::encodeMpInt(k);
concatenatedData += m_k;
m_hash.reset(get_hash(botanSha1Name()));
const SecureVector<byte> &hashResult
= m_hash->process(convertByteArray(concatenatedData),
concatenatedData.size());
m_h = convertByteArray(hashResult);
#ifdef CREATOR_SSH_DEBUG
printData("Client Id", AbstractSshPacket::encodeString(clientId));
printData("Server Id", AbstractSshPacket::encodeString(m_serverId));
printData("Client Payload", AbstractSshPacket::encodeString(m_clientKexInitPayload));
printData("Server payload", AbstractSshPacket::encodeString(m_serverKexInitPayload));
printData("K_S", reply.k_s);
printData("y", AbstractSshPacket::encodeMpInt(m_dhKey->get_y()));
printData("f", AbstractSshPacket::encodeMpInt(reply.f));
printData("K", m_k);
printData("Concatenated data", concatenatedData);
printData("H", m_h);
#endif // CREATOR_SSH_DEBUG
QScopedPointer<Public_Key> sigKey;
QScopedPointer<PK_Verifier> verifier;
if (m_serverHostKeyAlgo == SshCapabilities::PubKeyDss) {
const DL_Group group(reply.parameters.at(0), reply.parameters.at(1),
reply.parameters.at(2));
DSA_PublicKey * const dsaKey
= new DSA_PublicKey(group, reply.parameters.at(3));
sigKey.reset(dsaKey);
verifier.reset(new PK_Verifier(*dsaKey, botanEmsaAlgoName(SshCapabilities::PubKeyDss)));
} else if (m_serverHostKeyAlgo == SshCapabilities::PubKeyRsa) {
RSA_PublicKey * const rsaKey
= new RSA_PublicKey(reply.parameters.at(1), reply.parameters.at(0));
sigKey.reset(rsaKey);
verifier.reset(new PK_Verifier(*rsaKey, botanEmsaAlgoName(SshCapabilities::PubKeyRsa)));
} else {
Q_ASSERT(!"Impossible: Neither DSS nor RSA!");
}
const byte * const botanH = convertByteArray(m_h);
const Botan::byte * const botanSig
= convertByteArray(reply.signatureBlob);
if (!verifier->verify_message(botanH, m_h.size(), botanSig,
reply.signatureBlob.size())) {
throw SSH_SERVER_EXCEPTION(SSH_DISCONNECT_KEY_EXCHANGE_FAILED,
"Invalid signature in SSH_MSG_KEXDH_REPLY packet.");
}
m_sendFacility.sendNewKeysPacket();
}
示例15: shaderProgram
// The address returned here will only be valid until next time this function is called.
// The program is return bound.
QOpenGLEngineShaderProg *QOpenGLEngineSharedShaders::findProgramInCache(const QOpenGLEngineShaderProg &prog)
{
for (int i = 0; i < cachedPrograms.size(); ++i) {
QOpenGLEngineShaderProg *cachedProg = cachedPrograms[i];
if (*cachedProg == prog) {
// Move the program to the top of the list as a poor-man's cache algo
cachedPrograms.move(i, 0);
cachedProg->program->bind();
return cachedProg;
}
}
QScopedPointer<QOpenGLEngineShaderProg> newProg;
do {
QByteArray fragSource;
// Insert the custom stage before the srcPixel shader to work around an ATI driver bug
// where you cannot forward declare a function that takes a sampler as argument.
if (prog.srcPixelFragShader == CustomImageSrcFragmentShader)
fragSource.append(prog.customStageSource);
fragSource.append(qShaderSnippets[prog.mainFragShader]);
fragSource.append(qShaderSnippets[prog.srcPixelFragShader]);
if (prog.compositionFragShader)
fragSource.append(qShaderSnippets[prog.compositionFragShader]);
if (prog.maskFragShader)
fragSource.append(qShaderSnippets[prog.maskFragShader]);
QByteArray vertexSource;
vertexSource.append(qShaderSnippets[prog.mainVertexShader]);
vertexSource.append(qShaderSnippets[prog.positionVertexShader]);
QScopedPointer<QOpenGLShaderProgram> shaderProgram(new QOpenGLShaderProgram);
CachedShader shaderCache(fragSource, vertexSource);
bool inCache = shaderCache.load(shaderProgram.data(), QOpenGLContext::currentContext());
if (!inCache) {
QScopedPointer<QOpenGLShader> fragShader(new QOpenGLShader(QOpenGLShader::Fragment));
QByteArray description;
#if defined(QT_DEBUG)
// Name the shader for easier debugging
description.append("Fragment shader: main=");
description.append(snippetNameStr(prog.mainFragShader));
description.append(", srcPixel=");
description.append(snippetNameStr(prog.srcPixelFragShader));
if (prog.compositionFragShader) {
description.append(", composition=");
description.append(snippetNameStr(prog.compositionFragShader));
}
if (prog.maskFragShader) {
description.append(", mask=");
description.append(snippetNameStr(prog.maskFragShader));
}
fragShader->setObjectName(QString::fromLatin1(description));
#endif
if (!fragShader->compileSourceCode(fragSource)) {
qWarning() << "Warning:" << description << "failed to compile!";
break;
}
QScopedPointer<QOpenGLShader> vertexShader(new QOpenGLShader(QOpenGLShader::Vertex));
#if defined(QT_DEBUG)
// Name the shader for easier debugging
description.clear();
description.append("Vertex shader: main=");
description.append(snippetNameStr(prog.mainVertexShader));
description.append(", position=");
description.append(snippetNameStr(prog.positionVertexShader));
vertexShader->setObjectName(QString::fromLatin1(description));
#endif
if (!vertexShader->compileSourceCode(vertexSource)) {
qWarning() << "Warning:" << description << "failed to compile!";
break;
}
shaders.append(vertexShader.data());
shaders.append(fragShader.data());
shaderProgram->addShader(vertexShader.take());
shaderProgram->addShader(fragShader.take());
// We have to bind the vertex attribute names before the program is linked:
shaderProgram->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
if (prog.useTextureCoords)
shaderProgram->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR);
if (prog.useOpacityAttribute)
shaderProgram->bindAttributeLocation("opacityArray", QT_OPACITY_ATTR);
if (prog.usePmvMatrixAttribute) {
shaderProgram->bindAttributeLocation("pmvMatrix1", QT_PMV_MATRIX_1_ATTR);
shaderProgram->bindAttributeLocation("pmvMatrix2", QT_PMV_MATRIX_2_ATTR);
shaderProgram->bindAttributeLocation("pmvMatrix3", QT_PMV_MATRIX_3_ATTR);
}
}
newProg.reset(new QOpenGLEngineShaderProg(prog));
newProg->program = shaderProgram.take();
newProg->program->link();
//.........这里部分代码省略.........