From df789695cf0c5f29fbd1de448e1f27cbe3aecc4e Mon Sep 17 00:00:00 2001 From: stv Date: Fri, 6 Jul 2007 09:11:22 +0000 Subject: [PATCH] no message --- src/Qtx/Qtx.cxx | 39 ++++++++++- src/Qtx/Qtx.h | 67 ++++++++++--------- src/Qtx/QtxPagePrefMgr.cxx | 58 ++++++++--------- src/Qtx/QtxPagePrefMgr.h | 25 +++---- src/Qtx/QtxPathDialog.cxx | 24 ++++++- src/Qtx/QtxPathEdit.cxx | 90 +++++++++++++------------- src/Qtx/QtxPathEdit.h | 31 ++++----- src/Qtx/QtxPathListEdit.cxx | 111 ++++++++++++++++++++++++++------ src/Qtx/QtxPathListEdit.h | 20 +++--- src/SUIT/SUIT_PreferenceMgr.cxx | 4 +- 10 files changed, 293 insertions(+), 176 deletions(-) diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index 56ab7f332..56392249a 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -22,12 +22,15 @@ #include "Qtx.h" #include -#include #include +#include #include #include #include #include +#include +#include +#include #include #include @@ -538,6 +541,40 @@ bool Qtx::dos2unix( const QString& absName ) return QDir().rename( QString( temp ), absName ); } +QCompleter* Qtx::pathCompleter( const PathType type, const QString& filter ) +{ + QStringList extList; + QStringList filterList = filter.split( ";;" ); + for ( QStringList::const_iterator it = filterList.begin(); it != filterList.end(); ++it ) + { + QRegExp rx( "[\\s\\w,;]*\\(?\\*\\.([\\w]+)\\)?[\\d\\s\\w]*" ); + int index = 0; + while ( ( index = rx.indexIn( *it, index ) ) != -1 ) + { + extList.append( QString( "*.%1" ).arg( rx.cap( 1 ) ) ); + index += rx.matchedLength(); + } + } + + QDir::Filters filters = 0; + switch ( type ) + { + case PT_OpenFile: + case PT_SaveFile: + filters = QDir::AllEntries | QDir::AllDirs | QDir::NoDotAndDotDot; + break; + case PT_Directory: + filters = QDir::Drives | QDir::Dirs | QDir::NoDotAndDotDot; + break; + } + + QDirModel* dm = new QDirModel( extList, filters, QDir::Unsorted ); + QCompleter* cmp = new QCompleter( dm, 0 ); + dm->setParent( cmp ); + + return cmp; +} + /*! \brief Pack the specified color into integer RGB set. \param c unpacked color diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index cd43bd5a6..1c8c004f8 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -50,6 +50,7 @@ class QObject; class QWidget; +class QCompleter; typedef QList QIntList; //!< list of int values typedef QList QShortList; //!< list of short int values @@ -60,7 +61,7 @@ class QTX_EXPORT Qtx { public: //! Widget alignment flags - enum AlignmentFlags + typedef enum { AlignLeft = Qt::AlignLeft, //!< align left side of one widget to the left side of another widget AlignLeading = Qt::AlignLeading, //!< synonim for AlignLeft @@ -82,47 +83,51 @@ public: AlignOutRight = AlignOutLeft << 2, //!< align left side of one widget to the right side of another widget AlignOutTop = AlignOutRight << 2, //!< align bottom side of one widget to the top side of another widget AlignOutBottom = AlignOutTop << 2 //!< align top side of one widget to the bottom side of another widget - }; + } AlignmentFlags; - static QString toQString( const char*, const int = -1 ); - static QString toQString( const short*, const int = -1 ); - static QString toQString( const unsigned char*, const int = -1 ); - static QString toQString( const unsigned short*, const int = -1 ); + typedef enum { PT_OpenFile, PT_SaveFile, PT_Directory } PathType; - static void setTabOrder( QWidget*, ... ); - static void setTabOrder( const QWidgetList& ); - static void alignWidget( QWidget*, const QWidget*, const int ); + static QString toQString( const char*, const int = -1 ); + static QString toQString( const short*, const int = -1 ); + static QString toQString( const unsigned char*, const int = -1 ); + static QString toQString( const unsigned short*, const int = -1 ); - static void simplifySeparators( QWidget*, const bool = true ); + static void setTabOrder( QWidget*, ... ); + static void setTabOrder( const QWidgetList& ); + static void alignWidget( QWidget*, const QWidget*, const int ); - static bool isParent( QObject*, QObject* ); + static void simplifySeparators( QWidget*, const bool = true ); - static QString dir( const QString&, const bool = true ); - static QString file( const QString&, const bool = true ); - static QString extension( const QString&, const bool = false ); + static bool isParent( QObject*, QObject* ); - static QString library( const QString& ); + static QString dir( const QString&, const bool = true ); + static QString file( const QString&, const bool = true ); + static QString extension( const QString&, const bool = false ); - static QString tmpDir(); - static bool mkDir( const QString& ); - static bool rmDir( const QString& ); - static bool dos2unix( const QString& ); - static QString addSlash( const QString& ); + static QString library( const QString& ); - static int rgbSet( const QColor& ); - static int rgbSet( const int, const int, const int ); + static QString tmpDir(); + static bool mkDir( const QString& ); + static bool rmDir( const QString& ); + static bool dos2unix( const QString& ); + static QString addSlash( const QString& ); - static QColor rgbSet( const int ); - static void rgbSet( const int, int&, int&, int& ); + static QCompleter* pathCompleter( const PathType, const QString& = QString() ); - static QColor scaleColor( const int, const int, const int ); - static void scaleColors( const int, QColorList& ); + static int rgbSet( const QColor& ); + static int rgbSet( const int, const int, const int ); - static QImage grayscale( const QImage& ); - static QPixmap grayscale( const QPixmap& ); - static QImage transparentImage( const int, const int, const int = -1 ); - static QPixmap transparentPixmap( const int, const int, const int = -1 ); - static QPixmap composite( const QPixmap&, const int, const int, const QPixmap& = QPixmap() ); + static QColor rgbSet( const int ); + static void rgbSet( const int, int&, int&, int& ); + + static QColor scaleColor( const int, const int, const int ); + static void scaleColors( const int, QColorList& ); + + static QImage grayscale( const QImage& ); + static QPixmap grayscale( const QPixmap& ); + static QImage transparentImage( const int, const int, const int = -1 ); + static QPixmap transparentPixmap( const int, const int, const int = -1 ); + static QPixmap composite( const QPixmap&, const int, const int, const QPixmap& = QPixmap() ); }; #endif diff --git a/src/Qtx/QtxPagePrefMgr.cxx b/src/Qtx/QtxPagePrefMgr.cxx index 7ce6dfcff..cad550c6d 100644 --- a/src/Qtx/QtxPagePrefMgr.cxx +++ b/src/Qtx/QtxPagePrefMgr.cxx @@ -1809,11 +1809,11 @@ void QtxPagePrefFontItem::setOptionValue( const QString& name, const QVariant& v \class QtxPagePrefPathItem GUI implementation of resources path item. */ -QtxPagePrefPathItem::QtxPagePrefPathItem( const int mode, const QString& title, +QtxPagePrefPathItem::QtxPagePrefPathItem( const Qtx::PathType type, const QString& title, QtxPreferenceItem* parent, const QString& sect, const QString& param ) : QtxPageNamedPrefItem( title, parent, sect, param ) { - setControl( myPath = new QtxPathEdit( mode ) ); + setControl( myPath = new QtxPathEdit( type ) ); } QtxPagePrefPathItem::QtxPagePrefPathItem( const QString& title, QtxPreferenceItem* parent, @@ -1827,24 +1827,24 @@ QtxPagePrefPathItem::~QtxPagePrefPathItem() { } -int QtxPagePrefPathItem::mode() const +Qtx::PathType QtxPagePrefPathItem::pathType() const { - return myPath->mode(); + return myPath->pathType(); } -void QtxPagePrefPathItem::setMode( const int mode ) +void QtxPagePrefPathItem::setPathType( const Qtx::PathType type ) { - myPath->setMode( mode ); + myPath->setPathType( type ); } -QString QtxPagePrefPathItem::filter() const +QString QtxPagePrefPathItem::pathFilter() const { - return myPath->filter(); + return myPath->pathFilter(); } -void QtxPagePrefPathItem::setFilter( const QString& f ) +void QtxPagePrefPathItem::setPathFilter( const QString& f ) { - myPath->setFilter( f ); + myPath->setPathFilter( f ); } void QtxPagePrefPathItem::store() @@ -1859,25 +1859,25 @@ void QtxPagePrefPathItem::retrieve() QVariant QtxPagePrefPathItem::optionValue( const QString& name ) const { - if ( name == "mode" ) - return mode(); - else if ( name == "filter" ) - return filter(); + if ( name == "path_type" ) + return pathType(); + else if ( name == "path_filter" ) + return pathFilter(); else return QtxPageNamedPrefItem::optionValue( name ); } void QtxPagePrefPathItem::setOptionValue( const QString& name, const QVariant& val ) { - if ( name == "mode" ) + if ( name == "path_type" ) { if ( val.canConvert( QVariant::Int ) ) - setMode( val.toInt() ); + setPathType( (Qtx::PathType)val.toInt() ); } - else if ( name == "filter" ) + else if ( name == "path_filter" ) { if ( val.canConvert( QVariant::String ) ) - setFilter( val.toString() ); + setPathFilter( val.toString() ); } else QtxPageNamedPrefItem::setOptionValue( name, val ); @@ -1893,11 +1893,11 @@ QtxPagePrefPathsItem::QtxPagePrefPathsItem( QtxPreferenceItem* parent, const QSt setControl( myPaths = new QtxPathListEdit() ); } -QtxPagePrefPathsItem::QtxPagePrefPathsItem( const int mode, const QString& title, QtxPreferenceItem* parent, - const QString& sect, const QString& param ) +QtxPagePrefPathsItem::QtxPagePrefPathsItem( const Qtx::PathType type, const QString& title, + QtxPreferenceItem* parent, const QString& sect, const QString& param ) : QtxPageNamedPrefItem( title, parent, sect, param ) { - setControl( myPaths = new QtxPathListEdit( mode ) ); + setControl( myPaths = new QtxPathListEdit( type ) ); } QtxPagePrefPathsItem::QtxPagePrefPathsItem( const QString& title, QtxPreferenceItem* parent, @@ -1911,14 +1911,14 @@ QtxPagePrefPathsItem::~QtxPagePrefPathsItem() { } -int QtxPagePrefPathsItem::mode() const +Qtx::PathType QtxPagePrefPathsItem::pathType() const { - return myPaths->mode(); + return myPaths->pathType(); } -void QtxPagePrefPathsItem::setMode( const int mode ) +void QtxPagePrefPathsItem::setPathType( const Qtx::PathType type ) { - myPaths->setMode( mode ); + myPaths->setPathType( type ); } void QtxPagePrefPathsItem::store() @@ -1933,18 +1933,18 @@ void QtxPagePrefPathsItem::retrieve() QVariant QtxPagePrefPathsItem::optionValue( const QString& name ) const { - if ( name == "mode" ) - return mode(); + if ( name == "path_type" ) + return pathType(); else return QtxPageNamedPrefItem::optionValue( name ); } void QtxPagePrefPathsItem::setOptionValue( const QString& name, const QVariant& val ) { - if ( name == "mode" ) + if ( name == "path_type" ) { if ( val.canConvert( QVariant::Int ) ) - setMode( val.toInt() ); + setPathType( (Qtx::PathType)val.toInt() ); } else QtxPageNamedPrefItem::setOptionValue( name, val ); diff --git a/src/Qtx/QtxPagePrefMgr.h b/src/Qtx/QtxPagePrefMgr.h index b83998070..eb06e0373 100644 --- a/src/Qtx/QtxPagePrefMgr.h +++ b/src/Qtx/QtxPagePrefMgr.h @@ -557,22 +557,17 @@ private: class QTX_EXPORT QtxPagePrefPathItem : public QtxPageNamedPrefItem { public: - typedef enum { OpenFile = QtxPathEdit::OpenFile, - SaveFile = QtxPathEdit::SaveFile, - Directory = QtxPathEdit::Directory } Mode; - -public: - QtxPagePrefPathItem( const int, const QString&, QtxPreferenceItem* = 0, + QtxPagePrefPathItem( const Qtx::PathType, const QString&, QtxPreferenceItem* = 0, const QString& = QString(), const QString& = QString() ); QtxPagePrefPathItem( const QString&, QtxPreferenceItem* = 0, const QString& = QString(), const QString& = QString() ); virtual ~QtxPagePrefPathItem(); - int mode() const; - void setMode( const int ); + Qtx::PathType pathType() const; + void setPathType( const Qtx::PathType ); - QString filter() const; - void setFilter( const QString& ); + QString pathFilter() const; + void setPathFilter( const QString& ); virtual void store(); virtual void retrieve(); @@ -591,21 +586,17 @@ private: */ class QTX_EXPORT QtxPagePrefPathsItem : public QtxPageNamedPrefItem { -public: - typedef enum { File = QtxPathListEdit::File, - Directory = QtxPathListEdit::Directory } Mode; - public: QtxPagePrefPathsItem( QtxPreferenceItem* = 0, const QString& = QString(), const QString& = QString() ); QtxPagePrefPathsItem( const QString&, QtxPreferenceItem* = 0, const QString& = QString(), const QString& = QString() ); - QtxPagePrefPathsItem( const int, const QString&, QtxPreferenceItem* = 0, + QtxPagePrefPathsItem( const Qtx::PathType, const QString&, QtxPreferenceItem* = 0, const QString& = QString(), const QString& = QString() ); virtual ~QtxPagePrefPathsItem(); - int mode() const; - void setMode( const int ); + Qtx::PathType pathType() const; + void setPathType( const Qtx::PathType ); virtual void store(); virtual void retrieve(); diff --git a/src/Qtx/QtxPathDialog.cxx b/src/Qtx/QtxPathDialog.cxx index 4aa71bc80..d6989e6b6 100755 --- a/src/Qtx/QtxPathDialog.cxx +++ b/src/Qtx/QtxPathDialog.cxx @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -536,7 +536,7 @@ QLineEdit* QtxPathDialog::fileEntry( const int theId, int& theMode ) const \return created file entry ID */ int QtxPathDialog::createFileEntry( const QString& lab, const int mode, - const QString& filter, const int id ) + const QString& filter, const int id ) { int num = id; if ( num == -1 ) @@ -553,10 +553,28 @@ int QtxPathDialog::createFileEntry( const QString& lab, const int mode, new QLabel( lab, myEntriesFrame ); entry.edit = new QLineEdit( myEntriesFrame ); + entry.btn = new QPushButton( myEntriesFrame ); entry.btn->setAutoDefault( false ); entry.btn->setIcon( QPixmap( open_icon ) ); - + + Qtx::PathType type = Qtx::PT_OpenFile; + switch ( mode ) + { + case OpenFile: + type = Qtx::PT_OpenFile; + break; + case SaveFile: + type = Qtx::PT_SaveFile; + break; + case OpenDir: + case SaveDir: + case NewDir: + type = Qtx::PT_Directory; + break; + } + entry.edit->setCompleter( Qtx::pathCompleter( type, filter ) ); + connect( entry.btn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) ); connect( entry.edit, SIGNAL( returnPressed() ), this, SLOT( onReturnPressed() ) ); connect( entry.edit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); diff --git a/src/Qtx/QtxPathEdit.cxx b/src/Qtx/QtxPathEdit.cxx index aa31f4fe8..dfbcb7831 100644 --- a/src/Qtx/QtxPathEdit.cxx +++ b/src/Qtx/QtxPathEdit.cxx @@ -29,16 +29,41 @@ #include #include -QtxPathEdit::QtxPathEdit( const int mode, QWidget* parent ) +static const char* browse_icon[] = { +"16 16 5 1", +" c none", +". c #ffff00", +"# c #848200", +"a c #ffffff", +"b c #000000", +" ", +" bbb ", +" b b b", +" bb", +" bbb bbb", +" ba.abbbbbbb ", +" b.a.a.a.a.b ", +" ba.a.a.a.ab ", +" b.a.abbbbbbbbbb", +" ba.ab#########b", +" b.ab#########b ", +" bab#########b ", +" bb#########b ", +" bbbbbbbbbbb ", +" ", +" " +}; + +QtxPathEdit::QtxPathEdit( const Qtx::PathType type, QWidget* parent ) : QFrame( parent ), -myMode( mode ) +myType( type ) { initialize(); } QtxPathEdit::QtxPathEdit( QWidget* parent ) : QFrame( parent ), -myMode( OpenFile ) +myType( Qtx::PT_OpenFile ) { initialize(); } @@ -47,17 +72,17 @@ QtxPathEdit::~QtxPathEdit() { } -int QtxPathEdit::mode() const +Qtx::PathType QtxPathEdit::pathType() const { - return myMode; + return myType; } -void QtxPathEdit::setMode( const int mode ) +void QtxPathEdit::setPathType( const Qtx::PathType type ) { - if ( myMode == mode ) + if ( myType == type ) return; - myMode = mode; + myType = type; updateState(); } @@ -71,12 +96,12 @@ void QtxPathEdit::setPath( const QString& txt ) myPath->setText( txt ); } -QString QtxPathEdit::filter() const +QString QtxPathEdit::pathFilter() const { return myFilter; } -void QtxPathEdit::setFilter( const QString& f ) +void QtxPathEdit::setPathFilter( const QString& f ) { if ( myFilter == f ) return; @@ -89,15 +114,15 @@ void QtxPathEdit::onBrowse( bool ) { QString path; QString initial = QFileInfo( myPath->text() ).path(); - switch ( mode() ) + switch ( pathType() ) { - case OpenFile: - path = QFileDialog::getOpenFileName( myPath, QString(), initial, filter() ); + case Qtx::PT_OpenFile: + path = QFileDialog::getOpenFileName( myPath, QString(), initial, pathFilter() ); break; - case SaveFile: - path = QFileDialog::getSaveFileName( myPath, QString(), initial, filter() ); + case Qtx::PT_SaveFile: + path = QFileDialog::getSaveFileName( myPath, QString(), initial, pathFilter() ); break; - case Directory: + case Qtx::PT_Directory: path = QFileDialog::getExistingDirectory( myPath, QString(), initial ); break; } @@ -123,7 +148,7 @@ void QtxPathEdit::initialize() myPath->setValidator( new QRegExpValidator( QRegExp( "^([\\w/]{2}|[A-Z]:)[^:;\\*\\?]*[\\w\\\\/\\.]$" ), myPath ) ); QToolButton* browse = new QToolButton( this ); - browse->setText( "..." ); + browse->setIcon( QPixmap( browse_icon ) ); base->addWidget( browse ); connect( browse, SIGNAL( clicked( bool ) ), this, SLOT( onBrowse( bool ) ) ); @@ -135,34 +160,5 @@ void QtxPathEdit::initialize() void QtxPathEdit::updateState() { - QStringList extList; - QStringList filterList = filter().split( ";;" ); - for ( QStringList::const_iterator it = filterList.begin(); it != filterList.end(); ++it ) - { - QRegExp rx( "[\\s\\w,;]*\\(?\\*\\.([\\w]+)\\)?[\\d\\s\\w]*" ); - int index = 0; - while ( ( index = rx.indexIn( *it, index ) ) != -1 ) - { - extList.append( QString( "*.%1" ).arg( rx.cap( 1 ) ) ); - index += rx.matchedLength(); - } - } - - QDir::Filters filters = 0; - switch ( mode() ) - { - case OpenFile: - case SaveFile: - filters = QDir::AllEntries | QDir::AllDirs | QDir::NoDotAndDotDot; - break; - case Directory: - filters = QDir::Drives | QDir::Dirs | QDir::NoDotAndDotDot; - break; - } - - QDirModel* dm = new QDirModel( extList, filters, QDir::Unsorted ); - QCompleter* cmp = new QCompleter( dm, myPath ); - dm->setParent( cmp ); - - myPath->setCompleter( cmp ); + myPath->setCompleter( Qtx::pathCompleter( pathType(), pathFilter() ) ); } diff --git a/src/Qtx/QtxPathEdit.h b/src/Qtx/QtxPathEdit.h index ff74539d1..c4fe189c6 100644 --- a/src/Qtx/QtxPathEdit.h +++ b/src/Qtx/QtxPathEdit.h @@ -33,36 +33,33 @@ class QTX_EXPORT QtxPathEdit : public QFrame Q_OBJECT public: - typedef enum { OpenFile, SaveFile, Directory } Mode; - -public: - QtxPathEdit( const int, QWidget* = 0 ); + QtxPathEdit( const Qtx::PathType, QWidget* = 0 ); QtxPathEdit( QWidget* = 0 ); virtual ~QtxPathEdit(); - int mode() const; - void setMode( const int ); + QString path() const; + void setPath( const QString& ); - QString path() const; - void setPath( const QString& ); + Qtx::PathType pathType() const; + void setPathType( const Qtx::PathType ); - QString filter() const; - void setFilter( const QString& ); + QString pathFilter() const; + void setPathFilter( const QString& ); private slots: - void onBrowse( bool = false ); + void onBrowse( bool = false ); protected: - QLineEdit* lineEdit() const; + QLineEdit* lineEdit() const; private: - void initialize(); - void updateState(); + void initialize(); + void updateState(); private: - int myMode; - QLineEdit* myPath; - QString myFilter; + QLineEdit* myPath; + Qtx::PathType myType; + QString myFilter; }; #endif diff --git a/src/Qtx/QtxPathListEdit.cxx b/src/Qtx/QtxPathListEdit.cxx index 64b356073..c2de46f61 100644 --- a/src/Qtx/QtxPathListEdit.cxx +++ b/src/Qtx/QtxPathListEdit.cxx @@ -218,10 +218,11 @@ void QtxPathListEdit::Delegate::drawFocus( QPainter* painter, const QStyleOption /*! \class QtxPathListEdit */ -QtxPathListEdit::QtxPathListEdit( const int mode, QWidget* parent ) +QtxPathListEdit::QtxPathListEdit( const Qtx::PathType type, QWidget* parent ) : QFrame( parent ), myCompleter( 0 ), -myMode( mode ) +myType( type ), +myDuplicate( false ) { initialize(); } @@ -229,7 +230,8 @@ myMode( mode ) QtxPathListEdit::QtxPathListEdit( QWidget* parent ) : QFrame( parent ), myCompleter( 0 ), -myMode( File ) +myType( Qtx::PT_OpenFile ), +myDuplicate( false ) { initialize(); } @@ -241,17 +243,18 @@ QtxPathListEdit::~QtxPathListEdit() { } -int QtxPathListEdit::mode() const +Qtx::PathType QtxPathListEdit::pathType() const { - return myMode; + return myType; } -void QtxPathListEdit::setMode( const int m ) +void QtxPathListEdit::setPathType( const Qtx::PathType t ) { - if ( myMode == m ) + if ( myType == t ) return; - myMode = m; + myType = t; + delete myCompleter; myCompleter = 0; } @@ -266,6 +269,16 @@ void QtxPathListEdit::setPathList( const QStringList& lst ) myModel->setStringList( lst ); } +bool QtxPathListEdit::isDuplicateEnabled() const +{ + return myDuplicate; +} + +void QtxPathListEdit::setDuplicateEnabled( const bool on ) +{ + myDuplicate = on; +} + int QtxPathListEdit::count() const { return myModel->rowCount(); @@ -399,8 +412,18 @@ bool QtxPathListEdit::eventFilter( QObject* o, QEvent* e ) void QtxPathListEdit::onInsert( bool ) { - myModel->insertRows( myModel->rowCount(), 1 ); - QModelIndex idx = myModel->index( myModel->rowCount() - 1, 0 ); + int empty = -1; + QStringList lst = myModel->stringList(); + for ( int r = 0; r < lst.count() && empty == -1; r++ ) + { + if ( lst.at( r ).isEmpty() ) + empty = r; + } + + if ( empty == -1 ) + myModel->insertRows( empty = myModel->rowCount(), 1 ); + + QModelIndex idx = myModel->index( empty, 0 ); myList->setCurrentIndex( idx ); myList->edit( idx ); } @@ -492,6 +515,7 @@ void QtxPathListEdit::initialize() myList->setSelectionMode( QListView::SingleSelection ); myList->setSelectionBehavior( QListView::SelectRows ); myList->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + myList->setEditTriggers( QListView::DoubleClicked ); myList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); myList->installEventFilter( this ); @@ -506,16 +530,7 @@ void QtxPathListEdit::initialize() QWidget* QtxPathListEdit::createEditor( QWidget* parent ) { QtxPathEdit* edit = new Editor( parent ); - switch ( mode() ) - { - case File: - edit->setMode( QtxPathEdit::OpenFile ); - break; - case Directory: - edit->setMode( QtxPathEdit::Directory ); - break; - } - + edit->setPathType( pathType() ); return edit; } @@ -525,7 +540,15 @@ void QtxPathListEdit::setModelData( QWidget* editor, const QModelIndex& index ) if ( !edit ) return; - myModel->setData( index, edit->path(), Qt::EditRole ); + QString path = edit->path().trimmed(); + + if ( !isDuplicateEnabled() && !checkDuplicate( path, index.row() ) ) + return; + + if ( !checkExistance( path ) ) + return; + + myModel->setData( index, path, Qt::EditRole ); } void QtxPathListEdit::setEditorData( QWidget* editor, const QModelIndex& index ) @@ -537,3 +560,49 @@ void QtxPathListEdit::setEditorData( QWidget* editor, const QModelIndex& index ) QVariant v = myModel->data( index, Qt::EditRole ); edit->setPath( v.toString() ); } + +bool QtxPathListEdit::checkExistance( const QString& str, const bool msg ) +{ + if ( pathType() == Qtx::PT_SaveFile ) + return true; + + bool ok = QFileInfo( str ).exists(); + if ( !ok && msg ) + ok = QMessageBox::question( this, tr( "Warning" ), tr( "Path \"%1\" doesn't exist. Add it to list anyway?" ).arg( str ), + QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes; + + if ( ok && QFileInfo( str ).exists() ) + { + switch ( pathType() ) + { + case Qtx::PT_OpenFile: + ok = QFileInfo( str ).isFile(); + if ( !ok && msg ) + QMessageBox::warning( this, tr( "Error" ), tr( "Location \"%1\" doesn't point to file" ).arg( str ) ); + break; + case Qtx::PT_Directory: + ok = QFileInfo( str ).isDir(); + if ( !ok && msg ) + QMessageBox::warning( this, tr( "Error" ), tr( "Location \"%1\" doesn't point to directory" ).arg( str ) ); + break; + } + } + + return ok; +} + +bool QtxPathListEdit::checkDuplicate( const QString& str, const int row, const bool msg ) +{ + int cur = -1; + QStringList lst = myModel->stringList(); + for ( int r = 0; r < lst.count() && cur == -1; r++ ) + { + if ( r != row && lst.at( r ) == str ) + cur = r; + } + + if ( cur != -1 && msg ) + QMessageBox::warning( this, tr( "Error" ), tr( "Path \"%1\" already exist in the list" ).arg( str ) ); + + return cur == -1; +} diff --git a/src/Qtx/QtxPathListEdit.h b/src/Qtx/QtxPathListEdit.h index 10d4dbe33..de24b82fa 100644 --- a/src/Qtx/QtxPathListEdit.h +++ b/src/Qtx/QtxPathListEdit.h @@ -46,19 +46,19 @@ class QTX_EXPORT QtxPathListEdit : public QFrame class Delegate; public: - typedef enum { File, Directory } PathMode; - -public: - QtxPathListEdit( const int, QWidget* = 0 ); + QtxPathListEdit( const Qtx::PathType, QWidget* = 0 ); QtxPathListEdit( QWidget* = 0 ); virtual ~QtxPathListEdit(); - int mode() const; - void setMode( const int ); + Qtx::PathType pathType() const; + void setPathType( const Qtx::PathType ); QStringList pathList() const; void setPathList( const QStringList& ); + bool isDuplicateEnabled() const; + void setDuplicateEnabled( const bool ); + int count() const; bool contains( const QString& ) const; @@ -81,13 +81,17 @@ private: void setModelData( QWidget*, const QModelIndex& ); void setEditorData( QWidget*, const QModelIndex& ); + bool checkExistance( const QString&, const bool = true ); + bool checkDuplicate( const QString&, const int, const bool = true ); + private: - int myMode; QListView* myList; + Qtx::PathType myType; QStringListModel* myModel; QCompleter* myCompleter; + bool myDuplicate; friend class QtxPathListEdit::Delegate; }; -#endif // QTXPATHLISTEDIT_H +#endif diff --git a/src/SUIT/SUIT_PreferenceMgr.cxx b/src/SUIT/SUIT_PreferenceMgr.cxx index 5f64e9544..d4872d922 100644 --- a/src/SUIT/SUIT_PreferenceMgr.cxx +++ b/src/SUIT/SUIT_PreferenceMgr.cxx @@ -119,10 +119,10 @@ int SUIT_PreferenceMgr::addItem( const QString& title, const int pId, item = new QtxPagePrefFontItem( title, parent, sect, param ); break; case File: - item = new QtxPagePrefPathItem( QtxPagePrefPathItem::OpenFile, title, parent, sect, param ); + item = new QtxPagePrefPathItem( Qtx::PT_OpenFile, title, parent, sect, param ); break; case DirList: - item = new QtxPagePrefPathsItem( QtxPagePrefPathsItem::Directory, title, parent, sect, param ); + item = new QtxPagePrefPathsItem( Qtx::PT_Directory, title, parent, sect, param ); break; } -- 2.39.2