Browse Source

ENH: Show cache variable name in title of file dialogs.

Clinton Stimpson 17 years ago
parent
commit
dcd29a14b0
2 changed files with 38 additions and 15 deletions
  1. 34 12
      Source/QtDialog/QCMakeCacheView.cxx
  2. 4 3
      Source/QtDialog/QCMakeCacheView.h

+ 34 - 12
Source/QtDialog/QCMakeCacheView.cxx

@@ -393,6 +393,8 @@ QCMakeCacheModelDelegate::QCMakeCacheModelDelegate(QObject* p)
 QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p, 
 QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p, 
     const QStyleOptionViewItem&, const QModelIndex& idx) const
     const QStyleOptionViewItem&, const QModelIndex& idx) const
 {
 {
+  const QAbstractItemModel* model = idx.model();
+  QModelIndex var = model->index(idx.row(), 0);
   QVariant type = idx.data(QCMakeCacheModel::TypeRole);
   QVariant type = idx.data(QCMakeCacheModel::TypeRole);
   if(type == QCMakeCacheProperty::BOOL)
   if(type == QCMakeCacheProperty::BOOL)
     {
     {
@@ -400,11 +402,13 @@ QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p,
     }
     }
   else if(type == QCMakeCacheProperty::PATH)
   else if(type == QCMakeCacheProperty::PATH)
     {
     {
-    return new QCMakeCachePathEditor(p);
+    return new QCMakeCachePathEditor(p, 
+      var.data(Qt::DisplayRole).toString());
     }
     }
   else if(type == QCMakeCacheProperty::FILEPATH)
   else if(type == QCMakeCacheProperty::FILEPATH)
     {
     {
-    return new QCMakeCacheFilePathEditor(p);
+    return new QCMakeCacheFilePathEditor(p, 
+      var.data(Qt::DisplayRole).toString());
     }
     }
 
 
   return new QLineEdit(p);
   return new QLineEdit(p);
@@ -453,8 +457,8 @@ bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, QAbstractItemModel* model,
   return model->setData(index, state, Qt::CheckStateRole);
   return model->setData(index, state, Qt::CheckStateRole);
 }
 }
   
   
-QCMakeCacheFileEditor::QCMakeCacheFileEditor(QWidget* p)
-  : QLineEdit(p)
+QCMakeCacheFileEditor::QCMakeCacheFileEditor(QWidget* p, const QString& var)
+  : QLineEdit(p), Variable(var)
 {
 {
   // this *is* instead of has a line edit so QAbstractItemView
   // this *is* instead of has a line edit so QAbstractItemView
   // doesn't get confused with what the editor really is
   // doesn't get confused with what the editor really is
@@ -466,8 +470,8 @@ QCMakeCacheFileEditor::QCMakeCacheFileEditor(QWidget* p)
                    this, SLOT(chooseFile()));
                    this, SLOT(chooseFile()));
 }
 }
 
 
-QCMakeCacheFilePathEditor::QCMakeCacheFilePathEditor(QWidget* p)
- : QCMakeCacheFileEditor(p)
+QCMakeCacheFilePathEditor::QCMakeCacheFilePathEditor(QWidget* p, const QString& var)
+ : QCMakeCacheFileEditor(p, var)
 {
 {
   QCompleter* comp = new QCompleter(this);
   QCompleter* comp = new QCompleter(this);
   QDirModel* model = new QDirModel(comp);
   QDirModel* model = new QDirModel(comp);
@@ -475,8 +479,8 @@ QCMakeCacheFilePathEditor::QCMakeCacheFilePathEditor(QWidget* p)
   this->setCompleter(comp);
   this->setCompleter(comp);
 }
 }
 
 
-QCMakeCachePathEditor::QCMakeCachePathEditor(QWidget* p)
- : QCMakeCacheFileEditor(p)
+QCMakeCachePathEditor::QCMakeCachePathEditor(QWidget* p, const QString& var)
+ : QCMakeCacheFileEditor(p, var)
 {
 {
   QCompleter* comp = new QCompleter(this);
   QCompleter* comp = new QCompleter(this);
   QDirModel* model = new QDirModel(comp);
   QDirModel* model = new QDirModel(comp);
@@ -499,8 +503,17 @@ void QCMakeCacheFilePathEditor::chooseFile()
   // choose a file and set it
   // choose a file and set it
   QString path;
   QString path;
   QFileInfo info(this->text());
   QFileInfo info(this->text());
-  path = QFileDialog::getOpenFileName(this, tr("Select File"), 
-      info.absolutePath());
+  QString title;
+  if(this->Variable.isEmpty())
+    {
+    title = tr("Select File");
+    }
+  else
+    {
+    title = tr("Select File for %1");
+    title = title.arg(this->Variable);
+    }
+  path = QFileDialog::getOpenFileName(this, title, info.absolutePath());
   
   
   if(!path.isEmpty())
   if(!path.isEmpty())
     {
     {
@@ -512,8 +525,17 @@ void QCMakeCachePathEditor::chooseFile()
 {
 {
   // choose a file and set it
   // choose a file and set it
   QString path;
   QString path;
-  path = QFileDialog::getExistingDirectory(this, tr("Select Path"), 
-      this->text());
+  QString title;
+  if(this->Variable.isEmpty())
+    {
+    title = tr("Select Path");
+    }
+  else
+    {
+    title = tr("Select Path for %1");
+    title = title.arg(this->Variable);
+    }
+  path = QFileDialog::getExistingDirectory(this, title, this->text());
   if(!path.isEmpty())
   if(!path.isEmpty())
     {
     {
     this->setText(path);
     this->setText(path);

+ 4 - 3
Source/QtDialog/QCMakeCacheView.h

@@ -114,19 +114,20 @@ class QCMakeCacheFileEditor : public QLineEdit
 {
 {
   Q_OBJECT
   Q_OBJECT
 public:
 public:
-  QCMakeCacheFileEditor(QWidget* p);
+  QCMakeCacheFileEditor(QWidget* p, const QString& var);
 protected slots:
 protected slots:
   virtual void chooseFile() = 0;
   virtual void chooseFile() = 0;
 protected:
 protected:
   void resizeEvent(QResizeEvent* e);
   void resizeEvent(QResizeEvent* e);
   QToolButton* ToolButton;
   QToolButton* ToolButton;
+  QString Variable;
 };
 };
 
 
 class QCMakeCachePathEditor : public QCMakeCacheFileEditor
 class QCMakeCachePathEditor : public QCMakeCacheFileEditor
 {
 {
   Q_OBJECT
   Q_OBJECT
 public:
 public:
-  QCMakeCachePathEditor(QWidget* p = NULL);
+  QCMakeCachePathEditor(QWidget* p = NULL, const QString& var = QString());
   void chooseFile();
   void chooseFile();
 };
 };
 
 
@@ -134,7 +135,7 @@ class QCMakeCacheFilePathEditor : public QCMakeCacheFileEditor
 {
 {
   Q_OBJECT
   Q_OBJECT
 public:
 public:
-  QCMakeCacheFilePathEditor(QWidget* p = NULL);
+  QCMakeCacheFilePathEditor(QWidget* p = NULL, const QString& var = QString());
   void chooseFile();
   void chooseFile();
 };
 };