|
39 | 39 | #include <QSettings>
|
40 | 40 | #include <QColorDialog>
|
41 | 41 | #include <QLocale>
|
| 42 | +#include <QProcess> |
42 | 43 | #include <QToolBar>
|
43 | 44 | #include <QSize>
|
44 | 45 | #include <QStyleFactory>
|
@@ -110,6 +111,99 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
|
110 | 111 | spinBoxIdentifyValue->setMinimum( 0.01 );
|
111 | 112 | spinBoxIdentifyValue->setValue( identifyValue );
|
112 | 113 |
|
| 114 | + // custom environment variables |
| 115 | + bool useCustomVars = settings.value( "qgis/customEnvVarsUse", QVariant( false ) ).toBool(); |
| 116 | + mCustomVariablesChkBx->setChecked( useCustomVars ); |
| 117 | + if ( !useCustomVars ) |
| 118 | + { |
| 119 | + mAddCustomVarBtn->setEnabled( false ); |
| 120 | + mRemoveCustomVarBtn->setEnabled( false ); |
| 121 | + mCustomVariablesTable->setEnabled( false ); |
| 122 | + } |
| 123 | + QStringList customVarsList = settings.value( "qgis/customEnvVars", "" ).toStringList(); |
| 124 | + mCustomVariablesTable->clearContents(); |
| 125 | + foreach ( const QString &varStr, customVarsList ) |
| 126 | + { |
| 127 | + int pos = varStr.indexOf( QLatin1Char( '|' ) ); |
| 128 | + if ( pos == -1 ) |
| 129 | + continue; |
| 130 | + QString varStrApply = varStr.left( pos ); |
| 131 | + QString varStrNameValue = varStr.mid( pos + 1 ); |
| 132 | + pos = varStrNameValue.indexOf( QLatin1Char( '=' ) ); |
| 133 | + if ( pos == -1 ) |
| 134 | + continue; |
| 135 | + QString varStrName = varStrNameValue.left( pos ); |
| 136 | + QString varStrValue = varStrNameValue.mid( pos + 1 ); |
| 137 | + |
| 138 | + addCustomEnvVarRow( varStrName, varStrValue, varStrApply ); |
| 139 | + } |
| 140 | + QFontMetrics fmCustomVar( mCustomVariablesTable->horizontalHeader()->font() ); |
| 141 | + int fmCustomVarH = fmCustomVar.height() + 2; |
| 142 | + mCustomVariablesTable->horizontalHeader()->setFixedHeight( fmCustomVarH ); |
| 143 | + |
| 144 | + mCustomVariablesTable->setColumnWidth( 0, 120 ); |
| 145 | + if ( mCustomVariablesTable->rowCount() > 0 ) |
| 146 | + { |
| 147 | + mCustomVariablesTable->resizeColumnToContents( 1 ); |
| 148 | + } |
| 149 | + else |
| 150 | + { |
| 151 | + mCustomVariablesTable->setColumnWidth( 1, 120 ); |
| 152 | + } |
| 153 | + |
| 154 | + // current environment variables |
| 155 | + mCurrentVariablesTable->horizontalHeader()->setFixedHeight( fmCustomVarH ); |
| 156 | + QMap<QString, QString> sysVarsMap = QgsApplication::systemEnvVars(); |
| 157 | + QStringList currentVarsList = QProcess::systemEnvironment(); |
| 158 | + mCurrentVariablesTable->clearContents(); |
| 159 | + |
| 160 | + foreach ( const QString &varStr, currentVarsList ) |
| 161 | + { |
| 162 | + int pos = varStr.indexOf( QLatin1Char( '=' ) ); |
| 163 | + if ( pos == -1 ) |
| 164 | + continue; |
| 165 | + QStringList varStrItms; |
| 166 | + QString varStrName = varStr.left( pos ); |
| 167 | + QString varStrValue = varStr.mid( pos + 1 ); |
| 168 | + varStrItms << varStrName << varStrValue; |
| 169 | + |
| 170 | + // check if different than system variable |
| 171 | + QString sysVarVal = QString( "" ); |
| 172 | + bool sysVarMissing = !sysVarsMap.contains( varStrName ); |
| 173 | + if ( sysVarMissing ) |
| 174 | + sysVarVal = tr( "not present" ); |
| 175 | + |
| 176 | + if ( !sysVarMissing && sysVarsMap.value( varStrName ) != varStrValue ) |
| 177 | + sysVarVal = sysVarsMap.value( varStrName ); |
| 178 | + |
| 179 | + if ( !sysVarVal.isEmpty() ) |
| 180 | + sysVarVal = tr( "System value: %1" ).arg( sysVarVal ); |
| 181 | + |
| 182 | + int rowCnt = mCurrentVariablesTable->rowCount(); |
| 183 | + mCurrentVariablesTable->insertRow( rowCnt ); |
| 184 | + |
| 185 | + QFont fItm; |
| 186 | + for ( int i = 0; i < varStrItms.size(); ++i ) |
| 187 | + { |
| 188 | + QTableWidgetItem* varNameItm = new QTableWidgetItem( varStrItms.at( i ) ); |
| 189 | + varNameItm->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable |
| 190 | + | Qt::ItemIsEditable | Qt::ItemIsDragEnabled ); |
| 191 | + fItm = varNameItm->font(); |
| 192 | + if ( !sysVarVal.isEmpty() ) |
| 193 | + { |
| 194 | + fItm.setBold( true ); |
| 195 | + varNameItm->setFont( fItm ); |
| 196 | + varNameItm->setToolTip( sysVarVal ); |
| 197 | + } |
| 198 | + mCurrentVariablesTable->setItem( rowCnt, i, varNameItm ); |
| 199 | + } |
| 200 | + fItm.setBold( true ); |
| 201 | + QFontMetrics fmRow( fItm ); |
| 202 | + mCurrentVariablesTable->setRowHeight( rowCnt, fmRow.height() + 6 ); |
| 203 | + } |
| 204 | + if ( mCurrentVariablesTable->rowCount() > 0 ) |
| 205 | + mCurrentVariablesTable->resizeColumnToContents( 0 ); |
| 206 | + |
113 | 207 | //local directories to search when loading c++ plugins
|
114 | 208 | QString myPaths = settings.value( "plugins/searchPathsForPlugins", "" ).toString();
|
115 | 209 | if ( !myPaths.isEmpty() )
|
@@ -781,6 +875,23 @@ void QgsOptions::saveOptions()
|
781 | 875 | {
|
782 | 876 | QSettings settings;
|
783 | 877 |
|
| 878 | + // custom environment variables |
| 879 | + settings.setValue( "qgis/customEnvVarsUse", QVariant( mCustomVariablesChkBx->isChecked() ) ); |
| 880 | + QStringList customVars; |
| 881 | + for ( int i = 0; i < mCustomVariablesTable->rowCount(); ++i ) |
| 882 | + { |
| 883 | + if ( mCustomVariablesTable->item( i, 1 )->text().isEmpty() ) |
| 884 | + continue; |
| 885 | + QComboBox* varApplyCmbBx = qobject_cast<QComboBox*>( mCustomVariablesTable->cellWidget( i, 0 ) ); |
| 886 | + QString customVar = varApplyCmbBx->itemData( varApplyCmbBx->currentIndex() ).toString(); |
| 887 | + customVar += "|"; |
| 888 | + customVar += mCustomVariablesTable->item( i, 1 )->text(); |
| 889 | + customVar += "="; |
| 890 | + customVar += mCustomVariablesTable->item( i, 2 )->text(); |
| 891 | + customVars << customVar; |
| 892 | + } |
| 893 | + settings.setValue( "qgis/customEnvVars", QVariant( customVars ) ); |
| 894 | + |
784 | 895 | //search directories for user plugins
|
785 | 896 | QString myPaths;
|
786 | 897 | for ( int i = 0; i < mListPluginPaths->count(); ++i )
|
@@ -1211,6 +1322,52 @@ QStringList QgsOptions::i18nList()
|
1211 | 1322 | return myList;
|
1212 | 1323 | }
|
1213 | 1324 |
|
| 1325 | +void QgsOptions::addCustomEnvVarRow( QString varName, QString varVal, QString varApply ) |
| 1326 | +{ |
| 1327 | + int rowCnt = mCustomVariablesTable->rowCount(); |
| 1328 | + mCustomVariablesTable->insertRow( rowCnt ); |
| 1329 | + |
| 1330 | + QComboBox* varApplyCmbBx = new QComboBox( this ); |
| 1331 | + varApplyCmbBx->addItem( tr( "Overwrite" ), QVariant( "overwrite" ) ); |
| 1332 | + varApplyCmbBx->addItem( tr( "If Undefined" ), QVariant( "undefined" ) ); |
| 1333 | + varApplyCmbBx->addItem( tr( "Unset" ), QVariant( "unset" ) ); |
| 1334 | + varApplyCmbBx->addItem( tr( "Prepend" ), QVariant( "prepend" ) ); |
| 1335 | + varApplyCmbBx->addItem( tr( "Append" ), QVariant( "append" ) ); |
| 1336 | + varApplyCmbBx->setCurrentIndex( varApply.isEmpty() ? 0 : varApplyCmbBx->findData( QVariant( varApply ) ) ); |
| 1337 | + |
| 1338 | + QFont cbf = varApplyCmbBx->font(); |
| 1339 | + QFontMetrics cbfm = QFontMetrics( cbf ); |
| 1340 | + cbf.setPointSize( cbf.pointSize() - 2 ); |
| 1341 | + varApplyCmbBx->setFont( cbf ); |
| 1342 | + mCustomVariablesTable->setCellWidget( rowCnt, 0, varApplyCmbBx ); |
| 1343 | + |
| 1344 | + Qt::ItemFlags itmFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable |
| 1345 | + | Qt::ItemIsEditable | Qt::ItemIsDropEnabled; |
| 1346 | + |
| 1347 | + QTableWidgetItem* varNameItm = new QTableWidgetItem( varName ); |
| 1348 | + varNameItm->setFlags( itmFlags ); |
| 1349 | + mCustomVariablesTable->setItem( rowCnt, 1, varNameItm ); |
| 1350 | + |
| 1351 | + QTableWidgetItem* varValueItm = new QTableWidgetItem( varVal ); |
| 1352 | + varNameItm->setFlags( itmFlags ); |
| 1353 | + mCustomVariablesTable->setItem( rowCnt, 2, varValueItm ); |
| 1354 | + |
| 1355 | + mCustomVariablesTable->setRowHeight( rowCnt, cbfm.height() + 8 ); |
| 1356 | +} |
| 1357 | + |
| 1358 | +void QgsOptions::on_mAddCustomVarBtn_clicked() |
| 1359 | +{ |
| 1360 | + addCustomEnvVarRow( QString( "" ), QString( "" ) ); |
| 1361 | + mCustomVariablesTable->setFocus(); |
| 1362 | + mCustomVariablesTable->setCurrentCell( mCustomVariablesTable->rowCount() - 1, 1 ); |
| 1363 | + mCustomVariablesTable->edit( mCustomVariablesTable->currentIndex() ); |
| 1364 | +} |
| 1365 | + |
| 1366 | +void QgsOptions::on_mRemoveCustomVarBtn_clicked() |
| 1367 | +{ |
| 1368 | + mCustomVariablesTable->removeRow( mCustomVariablesTable->currentRow() ); |
| 1369 | +} |
| 1370 | + |
1214 | 1371 | void QgsOptions::on_mBtnAddPluginPath_clicked()
|
1215 | 1372 | {
|
1216 | 1373 | QString myDir = QFileDialog::getExistingDirectory(
|
|
0 commit comments