Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

Commit 3c3c26d4 authored by Frédéric Larue's avatar Frédéric Larue
Browse files

UIParamPath finalized.

parent a6f8890f
......@@ -15,11 +15,9 @@ UIParamPath::UIParamPath( const QString& id,
const QString& name,
const QString& description,
const QString& value,
bool dirOnly,
bool mustExist ) :
int flags ) :
UIParam(id,name,description),
m_DirOnly( dirOnly ),
m_MustExist( mustExist )
m_Flags( flags )
{
QHBoxLayout *l = new QHBoxLayout();
l->setContentsMargins( 0, 0, 0, 0 );
......@@ -28,7 +26,7 @@ UIParamPath::UIParamPath( const QString& id,
m_Path = new QComboBox();
m_Path->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
m_Path->setEditable( true );
m_Path->addItem( value );
SetValue( value );
connect( m_Path, SIGNAL(editTextChanged(QString)), this, SLOT(editPath(QString)) );
QPushButton *chooseButton = new QPushButton( "Choose" );
......@@ -39,8 +37,36 @@ UIParamPath::UIParamPath( const QString& id,
m_Widget = new QWidget();
m_Widget->setLayout( l );
}
void UIParamPath::SetValue( const QString &value )
{
QString linuxStyle = value;
if( !linuxStyle.isEmpty() )
{
linuxStyle.replace( '\\', '/' );
if( linuxStyle.at( linuxStyle.length()-1 ) == '/' )
linuxStyle = linuxStyle.left( linuxStyle.length()-1 );
}
connect( (QCheckBox*)m_Widget, SIGNAL(stateChanged(int)), this, SLOT(triggerValueChanged(int)) );
m_Path->clear();
m_Path->addItem( linuxStyle );
editPath( linuxStyle );
}
QString UIParamPath::Value() const
{
QString path = m_Path->currentText();
if( !path.isEmpty() )
{
if( (m_Flags & SlashAtEnd) && path.at( path.length()-1 ) != '/' )
path += '/';
if( m_Flags & WindowsStyle )
path.replace( '/', '\\' );
}
return path;
}
......@@ -48,53 +74,69 @@ void UIParamPath::openFileDialog()
{
QString selected;
if( m_DirOnly )
if( m_Flags & OnlyDirectories )
selected = QFileDialog::getExistingDirectory( NULL, "Select directory", m_Path->currentText() );
else if( m_MustExist )
else if( m_Flags & MustExist )
selected = QFileDialog::getOpenFileName( NULL, "Select directory", m_Path->currentText() );
else
selected = QFileDialog::getSaveFileName( NULL, "Select directory", m_Path->currentText() );
if( !selected.isEmpty() )
if( !selected.isEmpty() && selected != m_Path->currentText() )
{
m_Path->clear();
m_Path->addItem( selected );
emit valueChanged( Value() );
}
}
void UIParamPath::editPath( const QString& text )
{
QDir pathDir( text );
if( pathDir.exists() )
{
m_LastValidDir = text;
m_LastDirContent = pathDir.entryList( QDir::NoDotAndDotDot | (m_DirOnly? QDir::Dirs : QDir::Files), QDir::SortFlag::Name );
m_TryCompletion = (!m_LastDirContent.isEmpty() && text.at(text.length()-1) == '/');
}
disconnect( m_Path, SIGNAL(editTextChanged(QString)), this, SLOT(editPath(QString)) );
if( m_TryCompletion )
if( !text.isEmpty() )
{
disconnect( m_Path, SIGNAL(editTextChanged(QString)), this, SLOT(editPath(QString)) );
QString incompleteEntry = text.right( text.size() - m_LastValidDir.size() );
QStringList filteredContent = m_LastDirContent;
for( int n=0; n<incompleteEntry.length(); ++n )
QDir pathDir( text );
if( pathDir.exists() && text.at(text.length()-1) == '/' )
{
for( auto s=filteredContent.begin(); s!=filteredContent.end(); )
if( (*s)[n].toLower() != incompleteEntry[n].toLower() )
s = filteredContent.erase( s );
else
++ s;
m_LastValidDir = text;
m_LastDirContent = pathDir.entryList( QDir::NoDotAndDotDot | ((m_Flags & OnlyDirectories)? QDir::Dirs : QDir::Files), QDir::SortFlag::Name | QDir::IgnoreCase );
}
for( auto &s : filteredContent )
s = m_LastValidDir + s;
filteredContent.push_front( text );
m_Path->clear();
m_Path->addItems( filteredContent );
connect( m_Path, SIGNAL(editTextChanged(QString)), this, SLOT(editPath(QString)) );
if( m_LastDirContent.isEmpty() )
{
m_Path->addItem( text );
}
else
{
QString incompleteEntry = text.right( text.size() - m_LastValidDir.size() );
int pos = -1;
for( auto &s : m_LastDirContent )
{
if( pos < 0 && s.toLower() >= incompleteEntry.toLower() )
{
pos = m_Path->count();
if( s != incompleteEntry )
m_Path->addItem( text );
}
m_Path->addItem( m_LastValidDir + s );
}
m_Path->setCurrentIndex( pos );
if( incompleteEntry.isEmpty() )
m_Path->showPopup();
}
}
connect( m_Path, SIGNAL(editTextChanged(QString)), this, SLOT(editPath(QString)) );
if( !(m_Flags & MustExist) ||
( (m_Flags & OnlyDirectories) && QDir (text).exists()) ||
(!(m_Flags & OnlyDirectories) && QFile(text).exists()) )
emit valueChanged( Value() );
}
......@@ -19,24 +19,30 @@ class UIParamPath : public UIParam
{
Q_OBJECT
public:
enum Flags
{
OnlyDirectories = 1,
MustExist = 2,
WindowsStyle = 4,
SlashAtEnd = 8,
};
private:
QComboBox *m_Path;
QString m_LastValidDir;
QStringList m_LastDirContent;
bool m_TryCompletion = false;
bool m_DirOnly;
bool m_MustExist;
int m_Flags;
public:
UIParamPath( const QString& id,
const QString& name,
const QString& description,
const QString& value,
bool dirOnly,
bool mustExist );
int flags );
//inline void SetValue( const QString &value ) { m_Path->setText( value ); }
inline QString Value() const { return m_Path->currentText(); }
void SetValue( const QString &value );
QString Value() const;
inline const QWidget* Widget() const { return m_Widget; }
inline QWidget* Widget() { return m_Widget; }
......@@ -44,10 +50,9 @@ public:
inline void ConnectModificationSignal();
signals:
void valueChanged( bool );
void valueChanged( const QString& value );
private slots:
inline void triggerValueChanged( int state ) { emit valueChanged( state == Qt::Checked ); }
void openFileDialog();
void editPath( const QString& text );
};
......@@ -56,7 +61,7 @@ private slots:
inline void UIParamPath::ConnectModificationSignal()
{
QObject::connect( Widget(), SIGNAL(stateChanged(int)), this, SLOT(triggerParameterUpdate()) );
QObject::connect( this, SIGNAL(valueChanged(QString)), this, SLOT(triggerParameterUpdate()) );
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment