Skip to content
Permalink
Browse files

basics of new dialog for the initcode python functionalities

means, some cosmetic changes should still be done in qgsattributesforminitcode.ui
  • Loading branch information
signedav committed Nov 2, 2017
1 parent c371647 commit d21d45b72b5070285493eb298c9a1dd82fc844c3
@@ -16,6 +16,7 @@ SET(QGIS_APP_SRCS
qgsattributeactionpropertiesdialog.cpp
qgsattributetypedialog.cpp
qgsattributerelationedit.cpp
qgsattributesforminitcode.cpp
qgsattributetabledialog.cpp
qgsbookmarks.cpp
qgsclipboard.cpp
@@ -222,6 +223,7 @@ SET (QGIS_APP_MOC_HDRS
qgsattributeactionpropertiesdialog.h
qgsattributetypedialog.h
qgsattributerelationedit.h
qgsattributesforminitcode.h
qgsattributetabledialog.h
qgsbookmarks.h
qgsclipboard.h
@@ -0,0 +1,84 @@
#include "qgsattributesforminitcode.h"
#include "ui_qgsattributesforminitcode.h"
#include "qgssettings.h"

#include <QFileDialog>

QgsAttributesFormInitCode::QgsAttributesFormInitCode()
{
setupUi( this );

// Init function stuff
mInitCodeSourceComboBox->addItem( tr( "" ) );
mInitCodeSourceComboBox->addItem( tr( "Load from external file" ) );
mInitCodeSourceComboBox->addItem( tr( "Provide code in this dialog" ) );
mInitCodeSourceComboBox->addItem( tr( "Load from the environment" ) );

connect( mInitCodeSourceComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsAttributesFormInitCode::mInitCodeSourceComboBox_currentIndexChanged );
connect( pbtnSelectInitFilePath, &QToolButton::clicked, this, &QgsAttributesFormInitCode::pbtnSelectInitFilePath_clicked );

}

QgsAttributesFormInitCode::~QgsAttributesFormInitCode()
{
}
void QgsAttributesFormInitCode::setCodeSource( QgsEditFormConfig::PythonInitCodeSource initCodeSource )
{
mInitCodeSourceComboBox->setCurrentIndex( initCodeSource );
mInitCodeSourceComboBox_currentIndexChanged( mInitCodeSourceComboBox->currentIndex() );

}
void QgsAttributesFormInitCode::setInitFunction( const QString &initFunction )
{
mInitFunctionLineEdit->setText( initFunction );
}
void QgsAttributesFormInitCode::setInitFilePath( const QString &initFilePath )
{
mInitFilePathLineEdit->setText( initFilePath );
}
void QgsAttributesFormInitCode::setInitCode( const QString &initCode )
{
mInitCodeEditorPython->setText( initCode );
}

QgsEditFormConfig::PythonInitCodeSource QgsAttributesFormInitCode::codeSource() const
{
return ( QgsEditFormConfig::PythonInitCodeSource )mInitCodeSourceComboBox->currentIndex();
}

QString QgsAttributesFormInitCode::initFunction() const
{
return mInitFunctionLineEdit->text();
}
QString QgsAttributesFormInitCode::initFilePath() const
{
return mInitFilePathLineEdit->text();
}
QString QgsAttributesFormInitCode::initCode() const
{
return mInitCodeEditorPython->text();
}

void QgsAttributesFormInitCode::mInitCodeSourceComboBox_currentIndexChanged( int codeSource )
{
mInitFunctionContainer->setVisible( codeSource != QgsEditFormConfig::CodeSourceNone );
mInitFilePathLineEdit->setVisible( codeSource == QgsEditFormConfig::CodeSourceFile );
mInitFilePathLabel->setVisible( codeSource == QgsEditFormConfig::CodeSourceFile );
pbtnSelectInitFilePath->setVisible( codeSource == QgsEditFormConfig::CodeSourceFile );
mInitCodeEditorPython->setVisible( codeSource == QgsEditFormConfig::CodeSourceDialog );
}

void QgsAttributesFormInitCode::pbtnSelectInitFilePath_clicked( )
{
QgsSettings myQSettings;
QString lastUsedDir = myQSettings.value( QStringLiteral( "style/lastInitFilePathDir" ), "." ).toString();
QString pyfilename = QFileDialog::getOpenFileName( this, tr( "Select Python file" ), lastUsedDir, tr( "Python file" ) + " (*.py)" );

if ( pyfilename.isNull() )
return;

QFileInfo fi( pyfilename );
myQSettings.setValue( QStringLiteral( "style/lastInitFilePathDir" ), fi.path() );
mInitFilePathLineEdit->setText( pyfilename );
}

@@ -0,0 +1,70 @@
/***************************************************************************
qgsattributesforminitcode.h
---------------------
begin : October 2017
copyright : (C) 2017 by David Signer
email : david at opengis dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSATTRIBUTESFORMINITCODE_H
#define QGSATTRIBUTESFORMINITCODE_H
/***************************************************************************
qgsattributesforminitcode.h
---------------------
begin : October 2017
copyright : (C) 2017 by David Signer
email : david at opengis dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "ui_qgsattributesforminitcode.h"

#include "qgseditorconfigwidget.h"
#include "qgsfeature.h"
#include "qgsvectordataprovider.h"
#include "qgshelp.h"
#include "qgis_app.h"
#include <QWidget>

class QDialog;

class APP_EXPORT QgsAttributesFormInitCode: public QDialog, private Ui::QgsAttributesFormInitCode
{
Q_OBJECT

public:
explicit QgsAttributesFormInitCode();
~QgsAttributesFormInitCode();

void setCodeSource( QgsEditFormConfig::PythonInitCodeSource initCodeSourceComboBoxIndex );
void setInitFunction( const QString &initFunction );
void setInitFilePath( const QString &initFilePath );
void setInitCode( const QString &initCode );

QgsEditFormConfig::PythonInitCodeSource codeSource() const;
QString initFunction() const;
QString initFilePath() const;
QString initCode() const;

private:
//Ui::QgsAttributesFormInitCode *ui;

private slots:
void mInitCodeSourceComboBox_currentIndexChanged( int codeSource );
void pbtnSelectInitFilePath_clicked();
};

#endif // QGSATTRIBUTESFORMINITCODE_H

0 comments on commit d21d45b

Please sign in to comment.
You can’t perform that action at this time.