本文整理汇总了C++中QVariantMap::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariantMap::insert方法的具体用法?C++ QVariantMap::insert怎么用?C++ QVariantMap::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariantMap
的用法示例。
在下文中一共展示了QVariantMap::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: styleFile
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
QFile styleFile(":/style.css");
styleFile.open(QFile::ReadOnly);
QString styleSheet = QLatin1String(styleFile.readAll());
qApp->setStyleSheet(styleSheet);
QPixmap window_icon;
QFile iconFile(":/icon.png");
iconFile.open(QFile::ReadOnly);
QByteArray icon_data = iconFile.readAll();
window_icon.loadFromData(icon_data);
qApp->setWindowIcon(QIcon(window_icon));
awesome = new QtAwesome(qApp);
settings = new Settings(this);
window_watcher = new WindowWatcher(this);
anitomy = new AnitomyWrapper();
event_timer = new QTimer(this);
watch_timer = new QTimer(this);
uptime_timer = new QElapsedTimer;
progress_bar = new QProgressBar(ui->statusBar);
over = new Overlay(this);
torrent_refresh_time = 0;
user_refresh_time =
settings->getValue(Settings::UserRefreshTime, D_USER_REFRESH_TIME)
.toInt();
download_rule = 0;
download_count = 0;
hasUser = false;
uptime_timer->start();
watch_timer->setSingleShot(true);
awesome->initFontAwesome();
bool check_for_updates =
settings->getValue(Settings::CheckUpdates, D_CHECK_FOR_UPDATES).toBool();
if (check_for_updates) {
connect(FvUpdater::sharedUpdater(), &FvUpdater::restartRequested,
[&]() { // NOLINT
QString app = QApplication::applicationFilePath();
QStringList arguments = QApplication::arguments();
QString wd = QDir::currentPath();
QProcess::startDetached(app, arguments, wd);
elegantClose(true);
});
FvUpdater::sharedUpdater()->CheckForUpdatesSilent();
}
QFont font = ui->listTabs->tabBar()->font();
font.setCapitalization(QFont::Capitalize);
ui->listTabs->tabBar()->setFont(font);
int currentYear = QDate::currentDate().year();
int lowerYear = currentYear - 10;
while (currentYear > lowerYear) {
ui->comboYear->addItem(QString::number(currentYear));
currentYear--;
}
QWidget *container = new QWidget(ui->scrollArea);
layout = new FlowLayout(container);
ui->scrollArea->setWidget(container);
container->setLayout(layout);
QWidget *container2 = new QWidget(ui->scrollArea_2);
layout2 = new FlowLayout(container2);
layout2->disableSort();
ui->scrollArea_2->setWidget(container2);
container2->setLayout(layout2);
QVariantMap black;
black.insert("color", QColor(0, 0, 0));
black.insert("color-active", QColor(0, 0, 0));
black.insert("color-disabled", QColor(0, 0, 0));
black.insert("color-selected", QColor(0, 0, 0));
ui->airingButton->setIcon(awesome->icon(fa::clocko, black));
ui->torrentsButton->setIcon(awesome->icon(fa::rss, black));
ui->animeButton->setIcon(awesome->icon(fa::bars, black));
ui->seasonsButton->setIcon(awesome->icon(fa::th, black));
ui->statisticsButton->setIcon(awesome->icon(fa::piechart, black));
ui->tabWidget->tabBar()->hide();
ui->tabWidget->setCurrentIndex(UserTabs::tAnime);
ui->listTabs->setCurrentIndex(0);
ui->statusBar->addWidget(progress_bar);
ui->statusBar->layout()->setContentsMargins(1, 0, 0, 0);
progress_bar->setRange(0, 100);
progress_bar->setValue(5);
progress_bar->setFormat("Authorizing");
QSettings s;
//.........这里部分代码省略.........
示例2: getExif
QVariantMap JpgHead::getExif()
{
if (!isProcessFile) return QVariantMap();
QVariantMap map;
map.insert("FileName", ImageInfo.FileName);
map.insert("FileDateTime", ImageInfo.FileDateTime);
map.insert("FileSize", ImageInfo.FileSize);
map.insert("CameraMake", ImageInfo.CameraMake);
map.insert("CameraModel", ImageInfo.CameraModel);
map.insert("DateTime", ImageInfo.DateTime);
map.insert("Height", ImageInfo.Height);
map.insert("Width", ImageInfo.Width);
map.insert("Orientation", ImageInfo.Orientation);
map.insert("IsColor", ImageInfo.IsColor);
map.insert("FocalLength35mmEquiv",ImageInfo.FocalLength35mmEquiv);
map.insert("ExposureTime", ImageInfo.ExposureTime);
return map;
//struct {
// // Info in the jfif header.
// // This info is not used much - jhead used to just replace it with default
// // values, and over 10 years, only two people pointed this out.
// char Present;
// char ResolutionUnits;
// short XDensity;
// short YDensity;
//}JfifHeader;
//int Process;
//int FlashUsed;
//float FocalLength;
//float ExposureTime;
//float ApertureFNumber;
//float Distance;
//float CCDWidth;
//float ExposureBias;
//float DigitalZoomRatio;
//int FocalLength35mmEquiv; // Exif 2.2 tag - usually not present.
//int Whitebalance;
//int MeteringMode;
//int ExposureProgram;
//int ExposureMode;
//int ISOequivalent;
//int LightSource;
//int DistanceRange;
//float xResolution;
//float yResolution;
//int ResolutionUnit;
//char Comments[MAX_COMMENT_SIZE];
//int CommentWidthchars; // If nonzero, widechar comment, indicates number of chars.
//unsigned ThumbnailOffset; // Exif offset to thumbnail
//unsigned ThumbnailSize; // Size of thumbnail.
//unsigned LargestExifOffset; // Last exif data referenced (to check if thumbnail is at end)
//char ThumbnailAtEnd; // Exif header ends with the thumbnail
//// (we can only modify the thumbnail if its at the end)
//int ThumbnailSizeOffset;
//int DateTimeOffsets[MAX_DATE_COPIES];
//int numDateTimeTags;
//int GpsInfoPresent;
//char GpsLat[31];
//char GpsLong[31];
//char GpsAlt[20];
}
示例3: toMap
QVariantMap IDevice::toMap() const
{
QVariantMap map;
map.insert(QLatin1String(DisplayNameKey), d->displayName);
map.insert(QLatin1String(TypeKey), d->type.toString());
map.insert(QLatin1String(IdKey), d->id.toSetting());
map.insert(QLatin1String(OriginKey), d->origin);
map.insert(QLatin1String(MachineTypeKey), d->machineType);
map.insert(QLatin1String(HostKey), d->sshParameters.host);
map.insert(QLatin1String(SshPortKey), d->sshParameters.port);
map.insert(QLatin1String(UserNameKey), d->sshParameters.userName);
map.insert(QLatin1String(AuthKey), d->sshParameters.authenticationType);
map.insert(QLatin1String(PasswordKey), d->sshParameters.password);
map.insert(QLatin1String(KeyFileKey), d->sshParameters.privateKeyFile);
map.insert(QLatin1String(TimeoutKey), d->sshParameters.timeout);
map.insert(QLatin1String(PortsSpecKey), d->freePorts.toString());
map.insert(QLatin1String(VersionKey), d->version);
map.insert(QLatin1String(DebugServerKey), d->debugServerPath);
return map;
}
示例4: toMap
QVariantMap AndroidToolChain::toMap() const
{
QVariantMap result = GccToolChain::toMap();
result.insert(QLatin1String(ANDROID_NDK_TC_VERION), m_ndkToolChainVersion);
return result;
}
示例5: mutate
void IntegerMutation::mutate(QVariantMap &map, QString key){
int newValue = this->mutate(map.value(key).toInt());
map.remove(key);
map.insert(key,QVariant((int)newValue));
}
示例6: artist
QVariant
Result::toVariant() const
{
QVariantMap m;
m.insert( "artist", artist()->name() );
m.insert( "album", album()->name() );
m.insert( "track", track() );
if ( !collection().isNull() )
m.insert( "source", collection()->source()->friendlyName() );
else
m.insert( "source", friendlySource() );
m.insert( "mimetype", mimetype() );
m.insert( "size", size() );
m.insert( "bitrate", bitrate() );
m.insert( "duration", duration() );
m.insert( "score", score() );
m.insert( "sid", id() );
return m;
}
示例7: processAlgorithm
QVariantMap QgsBufferAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
std::unique_ptr< QgsFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
if ( !source )
throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "INPUT" ) ) );
QString dest;
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest, source->fields(), QgsWkbTypes::Polygon, source->sourceCrs() ) );
if ( !sink )
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );
// fixed parameters
bool dissolve = parameterAsBool( parameters, QStringLiteral( "DISSOLVE" ), context );
int segments = parameterAsInt( parameters, QStringLiteral( "SEGMENTS" ), context );
QgsGeometry::EndCapStyle endCapStyle = static_cast< QgsGeometry::EndCapStyle >( 1 + parameterAsInt( parameters, QStringLiteral( "END_CAP_STYLE" ), context ) );
QgsGeometry::JoinStyle joinStyle = static_cast< QgsGeometry::JoinStyle>( 1 + parameterAsInt( parameters, QStringLiteral( "JOIN_STYLE" ), context ) );
double miterLimit = parameterAsDouble( parameters, QStringLiteral( "MITER_LIMIT" ), context );
double bufferDistance = parameterAsDouble( parameters, QStringLiteral( "DISTANCE" ), context );
bool dynamicBuffer = QgsProcessingParameters::isDynamic( parameters, QStringLiteral( "DISTANCE" ) );
QgsExpressionContext expressionContext = createExpressionContext( parameters, context, dynamic_cast< QgsProcessingFeatureSource * >( source.get() ) );
QgsProperty bufferProperty;
if ( dynamicBuffer )
{
bufferProperty = parameters.value( QStringLiteral( "DISTANCE" ) ).value< QgsProperty >();
}
long count = source->featureCount();
QgsFeature f;
QgsFeatureIterator it = source->getFeatures();
double step = count > 0 ? 100.0 / count : 1;
int current = 0;
QVector< QgsGeometry > bufferedGeometriesForDissolve;
QgsAttributes dissolveAttrs;
while ( it.nextFeature( f ) )
{
if ( feedback->isCanceled() )
{
break;
}
if ( dissolveAttrs.isEmpty() )
dissolveAttrs = f.attributes();
QgsFeature out = f;
if ( out.hasGeometry() )
{
double distance = bufferDistance;
if ( dynamicBuffer )
{
expressionContext.setFeature( f );
distance = bufferProperty.valueAsDouble( expressionContext, bufferDistance );
}
QgsGeometry outputGeometry = f.geometry().buffer( distance, segments, endCapStyle, joinStyle, miterLimit );
if ( !outputGeometry )
{
QgsMessageLog::logMessage( QObject::tr( "Error calculating buffer for feature %1" ).arg( f.id() ), QObject::tr( "Processing" ), Qgis::Warning );
}
if ( dissolve )
bufferedGeometriesForDissolve << outputGeometry;
else
out.setGeometry( outputGeometry );
}
if ( !dissolve )
sink->addFeature( out, QgsFeatureSink::FastInsert );
feedback->setProgress( current * step );
current++;
}
if ( dissolve )
{
QgsGeometry finalGeometry = QgsGeometry::unaryUnion( bufferedGeometriesForDissolve );
QgsFeature f;
f.setGeometry( finalGeometry );
f.setAttributes( dissolveAttrs );
sink->addFeature( f, QgsFeatureSink::FastInsert );
}
QVariantMap outputs;
outputs.insert( QStringLiteral( "OUTPUT" ), dest );
return outputs;
}
示例8: JsonHandler
DeviceHandler::DeviceHandler(QObject *parent) :
JsonHandler(parent)
{
QVariantMap returns;
QVariantMap params;
params.clear(); returns.clear();
setDescription("GetSupportedVendors", "Returns a list of supported Vendors.");
setParams("GetSupportedVendors", params);
QVariantList vendors;
vendors.append(JsonTypes::vendorRef());
returns.insert("vendors", vendors);
setReturns("GetSupportedVendors", returns);
params.clear(); returns.clear();
setDescription("GetSupportedDevices", "Returns a list of supported Device classes, optionally filtered by vendorId.");
params.insert("o:vendorId", JsonTypes::basicTypeToString(JsonTypes::Uuid));
setParams("GetSupportedDevices", params);
QVariantList deviceClasses;
deviceClasses.append(JsonTypes::deviceClassRef());
returns.insert("deviceClasses", deviceClasses);
setReturns("GetSupportedDevices", returns);
params.clear(); returns.clear();
setDescription("GetPlugins", "Returns a list of loaded plugins.");
setParams("GetPlugins", params);
QVariantList plugins;
plugins.append(JsonTypes::pluginRef());
returns.insert("plugins", plugins);
setReturns("GetPlugins", returns);
params.clear(); returns.clear();
setDescription("GetPluginConfiguration", "Get a plugin's params.");
params.insert("pluginId", JsonTypes::basicTypeToString(JsonTypes::Uuid));
setParams("GetPluginConfiguration", params);
QVariantList pluginParams;
pluginParams.append(JsonTypes::paramRef());
returns.insert("deviceError", JsonTypes::deviceErrorRef());
returns.insert("o:configuration", pluginParams);
setReturns("GetPluginConfiguration", returns);
params.clear(); returns.clear();
setDescription("SetPluginConfiguration", "Set a plugin's params.");
params.insert("pluginId", JsonTypes::basicTypeToString(JsonTypes::Uuid));
params.insert("configuration", pluginParams);
setParams("SetPluginConfiguration", params);
returns.insert("deviceError", JsonTypes::deviceErrorRef());
setReturns("SetPluginConfiguration", returns);
params.clear(); returns.clear();
setDescription("AddConfiguredDevice", "Add a configured device with a setupMethod of SetupMethodJustAdd. "
"For devices with a setupMethod different than SetupMethodJustAdd, use PairDevice. "
"Use deviceDescriptorId or deviceParams, depending on the createMethod of the device class. "
"CreateMethodJustAdd takes the parameters you want to have with that device. "
"CreateMethodDiscovery requires the use of a deviceDescriptorId."
);
params.insert("deviceClassId", JsonTypes::basicTypeToString(JsonTypes::Uuid));
params.insert("o:deviceDescriptorId", JsonTypes::basicTypeToString(JsonTypes::Uuid));
QVariantList deviceParams;
deviceParams.append(JsonTypes::paramRef());
params.insert("o:deviceParams", deviceParams);
setParams("AddConfiguredDevice", params);
returns.insert("deviceError", JsonTypes::deviceErrorRef());
returns.insert("o:deviceId", JsonTypes::basicTypeToString(JsonTypes::Uuid));
setReturns("AddConfiguredDevice", returns);
returns.clear(); // Reused params from above!
setDescription("PairDevice", "Pair a device. "
"Use this for DeviceClasses with a setupMethod different than SetupMethodJustAdd. "
"Use deviceDescriptorId or deviceParams, depending on the createMethod of the device class. "
"CreateMethodJustAdd takes the parameters you want to have with that device. "
"CreateMethodDiscovery requires the use of a deviceDescriptorId. "
"If success is true, the return values will contain a pairingTransactionId, a displayMessage and "
"the setupMethod. Depending on the setupMethod you should either proceed with AddConfiguredDevice "
"or PairDevice."
);
setParams("PairDevice", params);
returns.insert("deviceError", JsonTypes::deviceErrorRef());
returns.insert("o:pairingTransactionId", JsonTypes::basicTypeToString(JsonTypes::Uuid));
returns.insert("o:displayMessage", JsonTypes::basicTypeToString(JsonTypes::String));
returns.insert("o:setupMethod", JsonTypes::setupMethodRef());
setReturns("PairDevice", returns);
params.clear(); returns.clear();
setDescription("ConfirmPairing", "Confirm an ongoing pairing. In case of SetupMethodEnterPin also provide the pin in the params.");
params.insert("pairingTransactionId", JsonTypes::basicTypeToString(JsonTypes::Uuid));
params.insert("o:secret", JsonTypes::basicTypeToString(JsonTypes::String));
setParams("ConfirmPairing", params);
returns.insert("deviceError", JsonTypes::deviceErrorRef());
returns.insert("o:deviceId", JsonTypes::basicTypeToString(JsonTypes::Uuid));
setReturns("ConfirmPairing", returns);
params.clear(); returns.clear();
setDescription("GetConfiguredDevices", "Returns a list of configured devices.");
setParams("GetConfiguredDevices", params);
QVariantList devices;
devices.append(JsonTypes::deviceRef());
returns.insert("devices", devices);
setReturns("GetConfiguredDevices", returns);
//.........这里部分代码省略.........
示例9: if
void
Api_v1_5::playback( QxtWebRequestEvent* event, const QString& command )
{
if ( command == "next")
{
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "next", Qt::QueuedConnection ) , "Skipping to the next track failed." );
}
else if ( command == "previous" )
{
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "previous", Qt::QueuedConnection ), "Rewinding to the previous track failed." );
}
else if ( command == "playpause" )
{
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "playPause", Qt::QueuedConnection ), "Play/Pause failed." );
}
else if ( command == "play" )
{
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "play", Qt::QueuedConnection ), "Starting the playback failed." );
}
else if ( command == "pause" )
{
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "pause", Qt::QueuedConnection ), "Pausing the current track failed." );
}
else if ( command == "stop" )
{
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "stop", Qt::QueuedConnection ), "Stopping the current track failed." );
}
else if ( command == "lowervolume" )
{
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "lowerVolume", Qt::QueuedConnection ), "Lowering volume failed." );
}
else if ( command == "raisevolume" )
{
JSON_REPLY( QMetaObject::invokeMethod( AudioEngine::instance(), "raiseVolume", Qt::QueuedConnection ), "Raising volume failed." );
}
else if ( command == "currenttrack" )
{
QByteArray json;
Tomahawk::result_ptr currentTrack = AudioEngine::instance()->currentTrack();
if ( currentTrack.isNull() )
{
json = "{ \"playing\": false }";
}
else
{
QVariantMap trackInfo;
trackInfo.insert( "playing", true );
trackInfo.insert( "paused", AudioEngine::instance()->isPaused() );
trackInfo.insert( "position", AudioEngine::instance()->currentTime() / 1000 );
trackInfo.insert( "bitrate", currentTrack->bitrate() );
if ( currentTrack->resolvedBy() ) {
QString resolverName = currentTrack->resolvedBy()->name();
trackInfo.insert( "resolvedBy", resolverName );
} else {
trackInfo.insert( "resolvedBy", "<unknown resolver>" );
}
trackInfo.insert( "score", currentTrack->score() );
trackInfo.insert( "album", currentTrack->track()->album() );
trackInfo.insert( "albumpos", currentTrack->track()->albumpos() );
trackInfo.insert( "artist", currentTrack->track()->artist() );
trackInfo.insert( "duration", currentTrack->track()->duration() );
trackInfo.insert( "track", currentTrack->track()->track() );
bool ok;
json = TomahawkUtils::toJson( trackInfo, &ok );
Q_ASSERT( ok );
}
QxtWebPageEvent * e = new QxtWebPageEvent( event->sessionID, event->requestID, json );
e->headers.insert( "Access-Control-Allow-Origin", "*" );
e->contentType = "application/json";
m_service->postEvent( e );
}
else if ( command == "volume" )
{
QByteArray json = QString( "{ \"result\": \"ok\", \"volume\": %1}" ).arg( AudioEngine::instance()->volume() ).toUtf8();
QxtWebPageEvent * e = new QxtWebPageEvent( event->sessionID, event->requestID, json );
e->headers.insert( "Access-Control-Allow-Origin", "*" );
e->contentType = "application/json";
m_service->postEvent( e );
}
else
{
m_service->sendJsonError( event, "No such playback command." );
}
}
示例10: toMap
QVariantMap BuildStep::toMap() const
{
QVariantMap map = ProjectConfiguration::toMap();
map.insert(QLatin1String(buildStepEnabledKey), m_enabled);
return map;
}
示例11: GetSupportedDevices
JsonReply* DeviceHandler::GetSupportedDevices(const QVariantMap ¶ms) const
{
QVariantMap returns;
returns.insert("deviceClasses", JsonTypes::packSupportedDevices(VendorId(params.value("vendorId").toString())));
return createReply(returns);
}
示例12: settings
QVariantMap QmlJSOutlineWidget::settings() const
{
QVariantMap map;
map.insert(QLatin1String("QmlJSOutline.ShowBindings"), m_showBindingsAction->isChecked());
return map;
}
示例13: sendPropertiesChanged
static void sendPropertiesChanged(const QDBusAbstractAdaptor *adaptor, const char *property, const QVariant &value) {
QVariantMap properties; properties.insert(property, value); sendPropertiesChanged(adaptor, properties);
}
示例14: save
bool SessionManager::save()
{
if (debug)
qDebug() << "SessionManager - saving session" << d->m_sessionName;
emit m_instance->aboutToSaveSession();
if (!d->m_writer || d->m_writer->fileName() != sessionNameToFileName(d->m_sessionName)) {
delete d->m_writer;
d->m_writer = new PersistentSettingsWriter(sessionNameToFileName(d->m_sessionName),
QLatin1String("QtCreatorSession"));
}
QVariantMap data;
// save the startup project
if (d->m_startupProject)
data.insert(QLatin1String("StartupProject"), d->m_startupProject->projectFilePath());
QColor c = StyleHelper::requestedBaseColor();
if (c.isValid()) {
QString tmp = QString::fromLatin1("#%1%2%3")
.arg(c.red(), 2, 16, QLatin1Char('0'))
.arg(c.green(), 2, 16, QLatin1Char('0'))
.arg(c.blue(), 2, 16, QLatin1Char('0'));
data.insert(QLatin1String("Color"), tmp);
}
QStringList projectFiles;
foreach (Project *pro, d->m_projects)
projectFiles << pro->projectFilePath();
// Restore infromation on projects that failed to load:
// don't readd projects to the list, which the user loaded
foreach (const QString &failed, d->m_failedProjects)
if (!projectFiles.contains(failed))
projectFiles << failed;
data.insert(QLatin1String("ProjectList"), projectFiles);
QMap<QString, QVariant> depMap;
QMap<QString, QStringList>::const_iterator i = d->m_depMap.constBegin();
while (i != d->m_depMap.constEnd()) {
QString key = i.key();
QStringList values;
foreach (const QString &value, i.value()) {
values << value;
}
depMap.insert(key, values);
++i;
}
data.insert(QLatin1String("ProjectDependencies"), QVariant(depMap));
data.insert(QLatin1String("EditorSettings"), EditorManager::saveState().toBase64());
QMap<QString, QVariant>::const_iterator it, end = d->m_values.constEnd();
QStringList keys;
for (it = d->m_values.constBegin(); it != end; ++it) {
data.insert(QLatin1String("value-") + it.key(), it.value());
keys << it.key();
}
data.insert(QLatin1String("valueKeys"), keys);
bool result = d->m_writer->save(data, Core::ICore::mainWindow());
if (!result) {
QMessageBox::warning(0, tr("Error while saving session"),
tr("Could not save session to file %1").arg(d->m_writer->fileName().toUserOutput()));
}
if (debug)
qDebug() << "SessionManager - saving session returned " << result;
return result;
}
示例15: createProjectDataset
void QWSTreeWidget::createProjectDataset()
{
if (!m_pDatabaseAdapter || !m_treeModel)
return;
QSqlQuery sqlQuery = m_pDatabaseAdapter->sqlQuery();
QString sql;
bool bRel;
QList<QVariantMap> recordList;
//Project
sql = "select ProjectName from TblProject";
bRel = sqlQuery.exec(sql);
QString strProjectName;
if (bRel)
{
while (sqlQuery.next())
{
QVariantMap m;
QString name = sqlQuery.value(0).toString();
strProjectName = "TblProject#1";
m.insert(DEFAULT_ID_FIELD, strProjectName);
m.insert(DEFAULT_TEXT_FIELD, QStringLiteral("工程:") + name);
m.insert(DEFAULT_PID_FIELD, QVariant());
m.insert(DEFAULT_ICON_FIELD, ":/project.png");
m.insert(DEFAULT_TYPE_FIELD, TYPE_PROJECT);
recordList.append(m);
}
}
//UC
sql = "select UCID, UCName from TblUC";
bRel = sqlQuery.exec(sql);
QMap<int, QString> ucMap;
if (bRel)
{
while (sqlQuery.next())
{
QVariantMap m;
QString ucName = sqlQuery.value(1).toString();
QString ucIDStr = "TblUC#" + sqlQuery.value(0).toString();
m.insert(DEFAULT_ID_FIELD, ucIDStr);
m.insert(DEFAULT_TEXT_FIELD, ucName);
m.insert(DEFAULT_PID_FIELD, strProjectName);
m.insert(DEFAULT_ICON_FIELD, ":/uc.png");
m.insert(DEFAULT_TYPE_FIELD, TYPE_UC);
recordList.append(m);
ucMap.insert(sqlQuery.value(0).toInt(), ucIDStr);
}
}
//PORT
QMap<int, QString>::const_iterator it = ucMap.constBegin();
QMap<int, QString> portMap;
while (it != ucMap.constEnd())
{
sql = QString("select PortID from TblPort where UCID = %1").arg(it.key());
bRel = sqlQuery.exec(sql);
if (bRel)
{
while (sqlQuery.next())
{
QVariantMap m;
QString portIDStr = "TblPort#" + sqlQuery.value(0).toString();
m.insert(DEFAULT_ID_FIELD, portIDStr);
m.insert(DEFAULT_TEXT_FIELD, QStringLiteral("端口-P%1").arg(sqlQuery.value(0).toInt()));
m.insert(DEFAULT_PID_FIELD, it.value());
m.insert(DEFAULT_ICON_FIELD, ":/port.png");
m.insert(DEFAULT_TYPE_FIELD, TYPE_PORT);
recordList.append(m);
portMap.insert(sqlQuery.value(0).toInt(), portIDStr);
}
}
++it;
}
//DEVICE
it = portMap.constBegin();
while (it != portMap.constEnd())
{
sql = QString("select DevID, Address, DevType, DevDsp from TblDevice where PortID = %1").arg(it.key());
bRel = sqlQuery.exec(sql);
if (bRel)
{
while (sqlQuery.next())
{
QVariantMap m;
QString devID = "TblDevice#" + sqlQuery.value(0).toString();
QString devAdd = sqlQuery.value(1).toString();
QString devType = sqlQuery.value(2).toString();
QString devDsp = sqlQuery.value(3).toString();
m.insert(DEFAULT_ID_FIELD, devID);
m.insert(DEFAULT_TEXT_FIELD, devAdd + " " + devType + " " + devDsp);
//.........这里部分代码省略.........