[Cmake-commits] [cmake-commits] clinton committed CMakeSetupDialog.cxx 1.58 1.59 CMakeSetupDialog.h 1.29 1.30 QCMakeCacheView.cxx 1.40 1.41 QCMakeCacheView.h 1.22 1.23

cmake-commits at cmake.org cmake-commits at cmake.org
Fri Jul 17 14:38:38 EDT 2009


Update of /cvsroot/CMake/CMake/Source/QtDialog
In directory public:/mounts/ram/cvs-serv21479

Modified Files:
	CMakeSetupDialog.cxx CMakeSetupDialog.h QCMakeCacheView.cxx 
	QCMakeCacheView.h 
Log Message:

ENH:  Add a "Show my changes" to the Tools menu.
      Changes by the user are recorded and when requested, it shows
      -D arguments for commandline or contents for a cache file.



Index: CMakeSetupDialog.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/QtDialog/CMakeSetupDialog.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -C 2 -d -r1.29 -r1.30
*** CMakeSetupDialog.h	5 Jul 2008 17:25:04 -0000	1.29
--- CMakeSetupDialog.h	17 Jul 2009 18:38:36 -0000	1.30
***************
*** 77,80 ****
--- 77,81 ----
    void setDebugOutput(bool);
    void setViewType(int);
+   void showUserChanges();
  
  protected:

Index: QCMakeCacheView.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/QtDialog/QCMakeCacheView.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -C 2 -d -r1.22 -r1.23
*** QCMakeCacheView.h	12 Mar 2009 15:19:27 -0000	1.22
--- QCMakeCacheView.h	17 Jul 2009 18:38:36 -0000	1.23
***************
*** 21,24 ****
--- 21,25 ----
  #include "QCMake.h"
  #include <QTreeView>
+ #include <QSet>
  #include <QStandardItemModel>
  #include <QItemDelegate>
***************
*** 112,115 ****
--- 113,120 ----
    Qt::ItemFlags flags (const QModelIndex& index) const;
    QModelIndex buddy(const QModelIndex& idx) const;
+   
+   // get the data in the model for this property
+   void getPropertyData(const QModelIndex& idx1,
+                        QCMakeProperty& prop) const;
  
  protected:
***************
*** 121,127 ****
    void setPropertyData(const QModelIndex& idx1, 
                         const QCMakeProperty& p, bool isNew);
-   // get the data in the model for this property
-   void getPropertyData(const QModelIndex& idx1,
-                        QCMakeProperty& prop) const;
  
    // breaks up he property list into groups
--- 126,129 ----
***************
*** 148,155 ****
--- 150,168 ----
         const QStyleOptionViewItem& option, const QModelIndex& index);
    bool eventFilter(QObject* object, QEvent* event);
+   void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index ) const;
+ 
+   QSet<QCMakeProperty> changes() const;
+   void clearChanges();
+ 
  protected slots:
    void setFileDialogFlag(bool);
  protected:
    bool FileDialogFlag;
+   // record a change to an item in the model.
+   // this simply saves the item in the set of changes
+   void recordChange(QAbstractItemModel* model, const QModelIndex& index);
+ 
+   // properties changed by user via this delegate
+   QSet<QCMakeProperty> mChanges;
  };
  

Index: QCMakeCacheView.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/QtDialog/QCMakeCacheView.cxx,v
retrieving revision 1.40
retrieving revision 1.41
diff -C 2 -d -r1.40 -r1.41
*** QCMakeCacheView.cxx	26 Mar 2009 15:42:37 -0000	1.40
--- QCMakeCacheView.cxx	17 Jul 2009 18:38:36 -0000	1.41
***************
*** 24,27 ****
--- 24,28 ----
  #include <QKeyEvent>
  #include <QSortFilterProxyModel>
+ #include <QMetaProperty>
  
  #include "QCMakeWidgets.h"
***************
*** 634,640 ****
    Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
                            ? Qt::Unchecked : Qt::Checked);
!   return model->setData(index, state, Qt::CheckStateRole);
  }
    
  bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* event)
  {
--- 635,648 ----
    Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
                            ? Qt::Unchecked : Qt::Checked);
!   bool success = model->setData(index, state, Qt::CheckStateRole);
!   if(success)
!     {
!     this->recordChange(model, index);
!     }
!   return success;
  }
    
+ // Issue 205903 fixed in Qt 4.5.0.
+ // Can remove this function and FileDialogFlag when minimum Qt version is 4.5
  bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* event)
  {
***************
*** 642,645 ****
--- 650,654 ----
    // where it doesn't create a QWidget wrapper for the native file dialog
    // so the Qt library ends up assuming the focus was lost to something else
+ 
    if(event->type() == QEvent::FocusOut && this->FileDialogFlag)
      {
***************
*** 649,651 ****
--- 658,703 ----
  }
  
+ void QCMakeCacheModelDelegate::setModelData(QWidget* editor,
+   QAbstractItemModel* model, const QModelIndex& index ) const
+ {
+   QItemDelegate::setModelData(editor, model, index);
+   const_cast<QCMakeCacheModelDelegate*>(this)->recordChange(model, index);
+ }
    
+ QSet<QCMakeProperty> QCMakeCacheModelDelegate::changes() const
+ {
+   return mChanges;
+ }
+ 
+ void QCMakeCacheModelDelegate::clearChanges()
+ {
+   mChanges.clear();
+ }
+ 
+ void QCMakeCacheModelDelegate::recordChange(QAbstractItemModel* model, const QModelIndex& index)
+ {
+   QModelIndex idx = index;
+   QAbstractItemModel* mymodel = model;
+   while(qobject_cast<QAbstractProxyModel*>(mymodel))
+     {
+     idx = static_cast<QAbstractProxyModel*>(mymodel)->mapToSource(idx);
+     mymodel = static_cast<QAbstractProxyModel*>(mymodel)->sourceModel();
+     }
+   QCMakeCacheModel* cache_model = qobject_cast<QCMakeCacheModel*>(mymodel);
+   if(cache_model && idx.isValid())
+     {
+     QCMakeProperty property;
+     idx = idx.sibling(idx.row(), 0);
+     cache_model->getPropertyData(idx, property);
+     
+     // clean out an old one
+     QSet<QCMakeProperty>::iterator iter = mChanges.find(property);
+     if(iter != mChanges.end())
+       {
+       mChanges.erase(iter);
+       }
+     // now add the new item
+     mChanges.insert(property);
+     }
+ }
+ 

Index: CMakeSetupDialog.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/QtDialog/CMakeSetupDialog.cxx,v
retrieving revision 1.58
retrieving revision 1.59
diff -C 2 -d -r1.58 -r1.59
*** CMakeSetupDialog.cxx	24 Jun 2009 20:50:52 -0000	1.58
--- CMakeSetupDialog.cxx	17 Jul 2009 18:38:36 -0000	1.59
***************
*** 109,112 ****
--- 109,115 ----
    QObject::connect(this->GenerateAction, SIGNAL(triggered(bool)), 
                     this, SLOT(doGenerate()));
+   QAction* showChangesAction = ToolsMenu->addAction(tr("&Show My Changes"));
+   QObject::connect(showChangesAction, SIGNAL(triggered(bool)), 
+                    this, SLOT(showUserChanges()));
  #if defined(Q_WS_MAC)
    this->InstallForCommandLineAction 
***************
*** 513,516 ****
--- 516,520 ----
    this->CacheModified = false;
    this->CacheValues->cacheModel()->clear();
+   qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())->clearChanges();
    this->Output->clear();
    QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
***************
*** 963,964 ****
--- 967,1033 ----
  }
  
+ void CMakeSetupDialog::showUserChanges()
+ {
+   QSet<QCMakeProperty> changes =
+     qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())->changes();
+ 
+   QDialog dialog(this);
+   dialog.setWindowTitle(tr("My Changes"));
+   dialog.resize(600, 400);
+   QVBoxLayout* l = new QVBoxLayout(&dialog);
+   QTextEdit* textedit = new QTextEdit(&dialog);
+   textedit->setReadOnly(true);
+   l->addWidget(textedit);
+   QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
+                                                 Qt::Horizontal, &dialog);
+   QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
+   l->addWidget(btns);
+ 
+   QString command;
+   QString cache;
+   
+   foreach(QCMakeProperty prop, changes)
+     {
+     QString type;
+     switch(prop.Type)
+       {
+       case QCMakeProperty::BOOL:
+         type = "BOOL";
+         break;
+       case QCMakeProperty::PATH:
+         type = "PATH";
+         break;
+       case QCMakeProperty::FILEPATH:
+         type = "FILEPATH";
+         break;
+       case QCMakeProperty::STRING:
+         type = "STRING";
+         break;
+       }
+     QString value;
+     if(prop.Type == QCMakeProperty::BOOL)
+       {
+       value = prop.Value.toBool() ? "1" : "0";
+       }
+     else
+       {
+       value = prop.Value.toString();
+       }
+ 
+     QString line("%1:%2=");
+     line = line.arg(prop.Key);
+     line = line.arg(type);
+ 
+     command += QString("-D%1\"%2\" ").arg(line).arg(value);
+     cache += QString("%1%2\n").arg(line).arg(value);
+     }
+   
+   textedit->append(tr("Commandline options:"));
+   textedit->append(command);
+   textedit->append("\n");
+   textedit->append(tr("Cache file:"));
+   textedit->append(cache);
+   
+   dialog.exec();
+ }
+ 



More information about the Cmake-commits mailing list