void pEnvironmentVariablesModel::setVariables( const pEnvironmentVariablesModel::Variables& variables, bool setDefault ) { emit layoutAboutToBeChanged(); int count = rowCount(); if ( count > 0 ) { beginRemoveRows( QModelIndex(), 0, count -1 ); } mRowCount = 0; mOrder.clear(); mVariables.clear(); if ( setDefault ) { mDefaultVariables.clear(); } if ( count > 0 ) { endRemoveRows(); } count = variables.count(); if ( count > 0 ) { beginInsertRows( QModelIndex(), 0, count -1 ); } mVariables = variables; mRowCount = count; if ( setDefault ) { setDefaultVariables( mVariables ); } QStringList keys = mVariables.keys(); qSort( keys ); foreach ( const QString& key, keys ) { mOrder << &mVariables[ key ]; } if ( count > 0 ) { endInsertRows(); } emit layoutChanged(); }
bool pEnvironmentVariablesManager::writeVariables( const pEnvironmentVariablesModel::Variables& variables ) const { pSettings settings( qApp, "EnvironmentVariables", "1.0.0" ); settings.remove( mSettingsKey ); settings.beginWriteArray( mSettingsKey ); for ( int i = 0; i < variables.count(); i++ ) { settings.setArrayIndex( i ); const pEnvironmentVariablesModel::Variable& variable = (variables.begin() +i).value(); settings.setValue( "Name", variable.name ); settings.setValue( "Value", variable.value ); settings.setValue( "Enabled", variable.enabled ); } settings.endArray(); return true; }