BUG: Keep editor alive when file dialog comes up to pick another file or path.
The editor going away prematurely Seems to only happen on Mac OS X.
This commit is contained in:
parent
76ed89cede
commit
1e61bb1f4c
@ -372,10 +372,15 @@ bool QCMakeCacheModel::insertRows(int row, int num, const QModelIndex&)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QCMakeCacheModelDelegate::QCMakeCacheModelDelegate(QObject* p)
|
QCMakeCacheModelDelegate::QCMakeCacheModelDelegate(QObject* p)
|
||||||
: QItemDelegate(p)
|
: QItemDelegate(p), FileDialogFlag(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QCMakeCacheModelDelegate::setFileDialogFlag(bool f)
|
||||||
|
{
|
||||||
|
this->FileDialogFlag = f;
|
||||||
|
}
|
||||||
|
|
||||||
QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p,
|
QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p,
|
||||||
const QStyleOptionViewItem&, const QModelIndex& idx) const
|
const QStyleOptionViewItem&, const QModelIndex& idx) const
|
||||||
{
|
{
|
||||||
@ -388,13 +393,21 @@ QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p,
|
|||||||
}
|
}
|
||||||
else if(type == QCMakeCacheProperty::PATH)
|
else if(type == QCMakeCacheProperty::PATH)
|
||||||
{
|
{
|
||||||
return new QCMakeCachePathEditor(p,
|
QCMakeCachePathEditor* editor =
|
||||||
|
new QCMakeCachePathEditor(p,
|
||||||
var.data(Qt::DisplayRole).toString());
|
var.data(Qt::DisplayRole).toString());
|
||||||
|
QObject::connect(editor, SIGNAL(fileDialogExists(bool)), this,
|
||||||
|
SLOT(setFileDialogFlag(bool)));
|
||||||
|
return editor;
|
||||||
}
|
}
|
||||||
else if(type == QCMakeCacheProperty::FILEPATH)
|
else if(type == QCMakeCacheProperty::FILEPATH)
|
||||||
{
|
{
|
||||||
return new QCMakeCacheFilePathEditor(p,
|
QCMakeCacheFilePathEditor* editor =
|
||||||
|
new QCMakeCacheFilePathEditor(p,
|
||||||
var.data(Qt::DisplayRole).toString());
|
var.data(Qt::DisplayRole).toString());
|
||||||
|
QObject::connect(editor, SIGNAL(fileDialogExists(bool)), this,
|
||||||
|
SLOT(setFileDialogFlag(bool)));
|
||||||
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new QLineEdit(p);
|
return new QLineEdit(p);
|
||||||
@ -443,6 +456,17 @@ bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, QAbstractItemModel* model,
|
|||||||
return model->setData(index, state, Qt::CheckStateRole);
|
return model->setData(index, state, Qt::CheckStateRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* event)
|
||||||
|
{
|
||||||
|
// workaround for what looks like a bug in Qt on Mac OS X
|
||||||
|
if(event->type() == QEvent::FocusOut && this->FileDialogFlag)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return QItemDelegate::eventFilter(object, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QCMakeCacheFileEditor::QCMakeCacheFileEditor(QWidget* p, const QString& var)
|
QCMakeCacheFileEditor::QCMakeCacheFileEditor(QWidget* p, const QString& var)
|
||||||
: QLineEdit(p), Variable(var)
|
: QLineEdit(p), Variable(var)
|
||||||
{
|
{
|
||||||
@ -492,7 +516,9 @@ void QCMakeCacheFilePathEditor::chooseFile()
|
|||||||
title = tr("Select File for %1");
|
title = tr("Select File for %1");
|
||||||
title = title.arg(this->Variable);
|
title = title.arg(this->Variable);
|
||||||
}
|
}
|
||||||
|
this->fileDialogExists(true);
|
||||||
path = QFileDialog::getOpenFileName(this, title, info.absolutePath());
|
path = QFileDialog::getOpenFileName(this, title, info.absolutePath());
|
||||||
|
this->fileDialogExists(false);
|
||||||
|
|
||||||
if(!path.isEmpty())
|
if(!path.isEmpty())
|
||||||
{
|
{
|
||||||
@ -514,7 +540,9 @@ void QCMakeCachePathEditor::chooseFile()
|
|||||||
title = tr("Select Path for %1");
|
title = tr("Select Path for %1");
|
||||||
title = title.arg(this->Variable);
|
title = title.arg(this->Variable);
|
||||||
}
|
}
|
||||||
|
this->fileDialogExists(true);
|
||||||
path = QFileDialog::getExistingDirectory(this, title, this->text());
|
path = QFileDialog::getExistingDirectory(this, title, this->text());
|
||||||
|
this->fileDialogExists(false);
|
||||||
if(!path.isEmpty())
|
if(!path.isEmpty())
|
||||||
{
|
{
|
||||||
this->setText(QDir::fromNativeSeparators(path));
|
this->setText(QDir::fromNativeSeparators(path));
|
||||||
|
@ -108,6 +108,11 @@ public:
|
|||||||
const QModelIndex& index ) const;
|
const QModelIndex& index ) const;
|
||||||
bool editorEvent (QEvent* event, QAbstractItemModel* model,
|
bool editorEvent (QEvent* event, QAbstractItemModel* model,
|
||||||
const QStyleOptionViewItem& option, const QModelIndex& index);
|
const QStyleOptionViewItem& option, const QModelIndex& index);
|
||||||
|
bool eventFilter(QObject* object, QEvent* event);
|
||||||
|
protected slots:
|
||||||
|
void setFileDialogFlag(bool);
|
||||||
|
protected:
|
||||||
|
bool FileDialogFlag;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Editor widget for editing paths or file paths
|
/// Editor widget for editing paths or file paths
|
||||||
@ -118,6 +123,8 @@ public:
|
|||||||
QCMakeCacheFileEditor(QWidget* p, const QString& var);
|
QCMakeCacheFileEditor(QWidget* p, const QString& var);
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void chooseFile() = 0;
|
virtual void chooseFile() = 0;
|
||||||
|
signals:
|
||||||
|
void fileDialogExists(bool);
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent* e);
|
void resizeEvent(QResizeEvent* e);
|
||||||
QToolButton* ToolButton;
|
QToolButton* ToolButton;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user