ENH: Convert native paths from QFileDialog and QDirModel/QCompleter.

BUG:  Block possible completion loop.
This commit is contained in:
Clinton Stimpson 2008-02-14 19:58:31 -05:00
parent df3169273a
commit d0d67d0015
3 changed files with 35 additions and 27 deletions

View File

@ -24,8 +24,6 @@
#include <QDialogButtonBox>
#include <QCloseEvent>
#include <QCoreApplication>
#include <QCompleter>
#include <QDirModel>
#include <QSettings>
#include <QMenu>
#include <QMenuBar>
@ -117,16 +115,8 @@ CMakeSetupDialog::CMakeSetupDialog()
QStringList buildPaths = this->loadBuildPaths();
this->BinaryDirectory->addItems(buildPaths);
QCompleter* compBinaryDir = new QCompleter(this);
QDirModel* modelBinaryDir = new QDirModel(compBinaryDir);
modelBinaryDir->setFilter(QDir::NoDotAndDotDot | QDir::Dirs);
compBinaryDir->setModel(modelBinaryDir);
this->BinaryDirectory->setCompleter(compBinaryDir);
QCompleter* compSourceDir = new QCompleter(this);
QDirModel* modelSourceDir = new QDirModel(compSourceDir);
modelSourceDir->setFilter(QDir::NoDotAndDotDot | QDir::Dirs);
compSourceDir->setModel(modelSourceDir);
this->SourceDirectory->setCompleter(compSourceDir);
this->BinaryDirectory->setCompleter(new QCMakeFileCompleter(this, true));
this->SourceDirectory->setCompleter(new QCMakeFileCompleter(this, true));
// start the cmake worker thread
@ -416,7 +406,7 @@ void CMakeSetupDialog::doSourceBrowse()
tr("Enter Path to Source"), this->SourceDirectory->text());
if(!dir.isEmpty())
{
this->setSourceDirectory(dir);
this->setSourceDirectory(QDir::fromNativeSeparators(dir));
}
}
@ -424,7 +414,9 @@ void CMakeSetupDialog::updateSourceDirectory(const QString& dir)
{
if(this->SourceDirectory->text() != dir)
{
this->setSourceDirectory(dir);
this->SourceDirectory->blockSignals(true);
this->SourceDirectory->setText(dir);
this->SourceDirectory->blockSignals(false);
}
}
@ -434,7 +426,7 @@ void CMakeSetupDialog::doBinaryBrowse()
tr("Enter Path to Build"), this->BinaryDirectory->currentText());
if(!dir.isEmpty() && dir != this->BinaryDirectory->currentText())
{
this->setBinaryDirectory(dir);
this->setBinaryDirectory(QDir::fromNativeSeparators(dir));
}
}

View File

@ -27,7 +27,6 @@
#include <QKeyEvent>
#include <QMenu>
#include <QDirModel>
#include <QCompleter>
static QRegExp AdvancedRegExp[2] = { QRegExp("(false)"), QRegExp("(true|false)") };
@ -460,20 +459,13 @@ QCMakeCacheFileEditor::QCMakeCacheFileEditor(QWidget* p, const QString& var)
QCMakeCacheFilePathEditor::QCMakeCacheFilePathEditor(QWidget* p, const QString& var)
: QCMakeCacheFileEditor(p, var)
{
QCompleter* comp = new QCompleter(this);
QDirModel* model = new QDirModel(comp);
comp->setModel(model);
this->setCompleter(comp);
this->setCompleter(new QCMakeFileCompleter(this, false));
}
QCMakeCachePathEditor::QCMakeCachePathEditor(QWidget* p, const QString& var)
: QCMakeCacheFileEditor(p, var)
{
QCompleter* comp = new QCompleter(this);
QDirModel* model = new QDirModel(comp);
model->setFilter(QDir::AllDirs | QDir::Drives);
comp->setModel(model);
this->setCompleter(comp);
this->setCompleter(new QCMakeFileCompleter(this, true));
}
void QCMakeCacheFileEditor::resizeEvent(QResizeEvent* e)
@ -504,7 +496,7 @@ void QCMakeCacheFilePathEditor::chooseFile()
if(!path.isEmpty())
{
this->setText(path);
this->setText(QDir::fromNativeSeparators(path));
}
}
@ -525,8 +517,23 @@ void QCMakeCachePathEditor::chooseFile()
path = QFileDialog::getExistingDirectory(this, title, this->text());
if(!path.isEmpty())
{
this->setText(path);
this->setText(QDir::fromNativeSeparators(path));
}
}
QCMakeFileCompleter::QCMakeFileCompleter(QObject* o, bool dirs)
: QCompleter(o)
{
QDirModel* model = new QDirModel(this);
if(dirs)
{
model->setFilter(QDir::AllDirs | QDir::Drives | QDir::NoDotAndDotDot);
}
this->setModel(model);
}
QString QCMakeFileCompleter::pathFromIndex(const QModelIndex& idx) const
{
return QDir::fromNativeSeparators(QCompleter::pathFromIndex(idx));
}

View File

@ -25,6 +25,7 @@
#include <QLineEdit>
#include <QItemDelegate>
#include <QSortFilterProxyModel>
#include <QCompleter>
class QCMakeCacheModel;
class QToolButton;
@ -139,5 +140,13 @@ public:
void chooseFile();
};
/// completer class that returns native cmake paths
class QCMakeFileCompleter : public QCompleter
{
public:
QCMakeFileCompleter(QObject* o, bool dirs);
virtual QString pathFromIndex(const QModelIndex& idx) const;
};
#endif