~ubuntu-branches/ubuntu/lucid/cmake/lucid

« back to all changes in this revision

Viewing changes to Source/QtDialog/QCMakeCacheView.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2009-12-16 11:11:54 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091216111154-6accvv6yq86h2hkc
Tags: 2.8.0-5ubuntu1
* Merge from debian testing (LP: #497349). Remaining changes:
  - Keep the Replaces: on cmake-data to cover the Kubuntu version from
    Jaunty in case someone decides to do an (unsupported) Jaunty->Lucid
    upgrade.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*=========================================================================
2
 
 
3
 
  Program:   CMake - Cross-Platform Makefile Generator
4
 
  Module:    $RCSfile: QCMakeCacheView.cxx,v $
5
 
  Language:  C++
6
 
  Date:      $Date: 2009-03-31 14:29:18 $
7
 
  Version:   $Revision: 1.26.2.5 $
8
 
 
9
 
  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
10
 
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
11
 
 
12
 
     This software is distributed WITHOUT ANY WARRANTY; without even 
13
 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14
 
     PURPOSE.  See the above copyright notices for more information.
15
 
 
16
 
=========================================================================*/
 
1
/*============================================================================
 
2
  CMake - Cross Platform Makefile Generator
 
3
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
 
4
 
 
5
  Distributed under the OSI-approved BSD License (the "License");
 
6
  see accompanying file Copyright.txt for details.
 
7
 
 
8
  This software is distributed WITHOUT ANY WARRANTY; without even the
 
9
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
10
  See the License for more information.
 
11
============================================================================*/
17
12
 
18
13
#include "QCMakeCacheView.h"
19
14
 
23
18
#include <QStyle>
24
19
#include <QKeyEvent>
25
20
#include <QSortFilterProxyModel>
 
21
#include <QMetaProperty>
 
22
#include <QApplication>
26
23
 
27
24
#include "QCMakeWidgets.h"
28
25
 
138
135
  QCMakeCacheModelDelegate* delegate = new QCMakeCacheModelDelegate(this);
139
136
  this->setItemDelegate(delegate);
140
137
  
141
 
  this->setEditTriggers(QAbstractItemView::DoubleClicked |
142
 
                        QAbstractItemView::SelectedClicked |
143
 
                        QAbstractItemView::EditKeyPressed |
144
 
                        QAbstractItemView::AnyKeyPressed);
 
138
  this->setUniformRowHeights(true);
 
139
 
 
140
  this->setEditTriggers(QAbstractItemView::AllEditTriggers);
145
141
 
146
142
  // tab, backtab doesn't step through items
147
143
  this->setTabKeyNavigation(false);
249
245
    QCMakePropertyList newP2 = newProps2.toList();
250
246
    qSort(newP);
251
247
    qSort(newP2);
252
 
    int rowCount = 0;
 
248
    int row_count = 0;
253
249
    foreach(QCMakeProperty p, newP)
254
250
    {
255
 
      this->insertRow(rowCount);
256
 
      this->setPropertyData(this->index(rowCount, 0), p, true);
257
 
      rowCount++;
 
251
      this->insertRow(row_count);
 
252
      this->setPropertyData(this->index(row_count, 0), p, true);
 
253
      row_count++;
258
254
    }
259
255
    foreach(QCMakeProperty p, newP2)
260
256
    {
261
 
      this->insertRow(rowCount);
262
 
      this->setPropertyData(this->index(rowCount, 0), p, false);
263
 
      rowCount++;
 
257
      this->insertRow(row_count);
 
258
      this->setPropertyData(this->index(row_count, 0), p, false);
 
259
      row_count++;
264
260
    }
265
261
  }
266
262
  else if(this->View == GroupView)
274
270
    
275
271
    foreach(QString key, newPropsTree.keys())
276
272
      {
277
 
      QCMakePropertyList props = newPropsTree[key];
 
273
      QCMakePropertyList props2 = newPropsTree[key];
278
274
 
279
275
      QList<QStandardItem*> parentItems;
280
276
      parentItems.append(
285
281
      parentItems[1]->setData(QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
286
282
      root->appendRow(parentItems);
287
283
 
288
 
      foreach(QCMakeProperty prop, props)
 
284
      int num = props2.size();
 
285
      for(int i=0; i<num; i++)
289
286
        {
 
287
        QCMakeProperty prop = props2[i];
290
288
        QList<QStandardItem*> items;
291
289
        items.append(new QStandardItem());
292
290
        items.append(new QStandardItem());
297
295
    
298
296
    foreach(QString key, newPropsTree2.keys())
299
297
      {
300
 
      QCMakePropertyList props = newPropsTree2[key];
 
298
      QCMakePropertyList props2 = newPropsTree2[key];
301
299
 
302
300
      QStandardItem* parentItem = 
303
301
        new QStandardItem(key.isEmpty() ? tr("Ungrouped Entries") : key);
304
302
      root->appendRow(parentItem);
305
303
 
306
 
      foreach(QCMakeProperty prop, props)
 
304
      int num = props2.size();
 
305
      for(int i=0; i<num; i++)
307
306
        {
 
307
        QCMakeProperty prop = props2[i];
308
308
        QList<QStandardItem*> items;
309
309
        items.append(new QStandardItem());
310
310
        items.append(new QStandardItem());
365
365
  }
366
366
  this->setData(idx2, prop.Help, QCMakeCacheModel::HelpRole);
367
367
 
 
368
  if (!prop.Strings.isEmpty())
 
369
  {
 
370
    this->setData(idx1, prop.Strings, QCMakeCacheModel::StringsRole);
 
371
  }
 
372
 
368
373
  if(isNew)
369
374
  {
370
375
    this->setData(idx1, QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
381
386
  prop.Help = this->data(idx1, HelpRole).toString();
382
387
  prop.Type = static_cast<QCMakeProperty::PropertyType>(this->data(idx1, TypeRole).toInt());
383
388
  prop.Advanced = this->data(idx1, AdvancedRole).toBool();
 
389
  prop.Strings = this->data(idx1, QCMakeCacheModel::StringsRole).toStringList();
384
390
  if(prop.Type == QCMakeProperty::BOOL)
385
391
  {
386
392
    int check = this->data(idx2, Qt::CheckStateRole).toInt();
573
579
        SLOT(setFileDialogFlag(bool)));
574
580
    return editor;
575
581
    }
 
582
  else if(type == QCMakeProperty::STRING &&
 
583
          var.data(QCMakeCacheModel::StringsRole).isValid())
 
584
    {
 
585
    QCMakeComboBox* editor = 
 
586
      new QCMakeComboBox(p, var.data(QCMakeCacheModel::StringsRole).toStringList());
 
587
    editor->setFrame(false);
 
588
    return editor;
 
589
    }
576
590
 
577
 
  return new QLineEdit(p);
 
591
  QLineEdit* editor = new QLineEdit(p);
 
592
  editor->setFrame(false);
 
593
  return editor;
578
594
}
579
 
  
 
595
 
580
596
bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, QAbstractItemModel* model, 
581
597
       const QStyleOptionViewItem& option, const QModelIndex& index)
582
598
{
617
633
 
618
634
  Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
619
635
                          ? Qt::Unchecked : Qt::Checked);
620
 
  return model->setData(index, state, Qt::CheckStateRole);
 
636
  bool success = model->setData(index, state, Qt::CheckStateRole);
 
637
  if(success)
 
638
    {
 
639
    this->recordChange(model, index);
 
640
    }
 
641
  return success;
621
642
}
622
643
  
623
 
bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* event)
 
644
// Issue 205903 fixed in Qt 4.5.0.
 
645
// Can remove this function and FileDialogFlag when minimum Qt version is 4.5
 
646
bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* evt)
624
647
{
625
648
  // workaround for what looks like a bug in Qt on Mac OS X
626
649
  // where it doesn't create a QWidget wrapper for the native file dialog
627
650
  // so the Qt library ends up assuming the focus was lost to something else
628
 
  if(event->type() == QEvent::FocusOut && this->FileDialogFlag)
 
651
 
 
652
  if(evt->type() == QEvent::FocusOut && this->FileDialogFlag)
629
653
    {
630
654
    return false;
631
655
    }
632
 
  return QItemDelegate::eventFilter(object, event);
633
 
}
634
 
 
635
 
  
 
656
  return QItemDelegate::eventFilter(object, evt);
 
657
}
 
658
 
 
659
void QCMakeCacheModelDelegate::setModelData(QWidget* editor,
 
660
  QAbstractItemModel* model, const QModelIndex& index ) const
 
661
{
 
662
  QItemDelegate::setModelData(editor, model, index);
 
663
  const_cast<QCMakeCacheModelDelegate*>(this)->recordChange(model, index);
 
664
}
 
665
  
 
666
QSize QCMakeCacheModelDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
 
667
{
 
668
  QSize sz = QItemDelegate::sizeHint(option, index);
 
669
  QStyle *style = QApplication::style();
 
670
 
 
671
  // increase to checkbox size
 
672
  QStyleOptionButton opt;
 
673
  opt.QStyleOption::operator=(option);
 
674
  sz = sz.expandedTo(style->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, NULL).size());
 
675
 
 
676
  return sz;
 
677
}
 
678
  
 
679
QSet<QCMakeProperty> QCMakeCacheModelDelegate::changes() const
 
680
{
 
681
  return mChanges;
 
682
}
 
683
 
 
684
void QCMakeCacheModelDelegate::clearChanges()
 
685
{
 
686
  mChanges.clear();
 
687
}
 
688
 
 
689
void QCMakeCacheModelDelegate::recordChange(QAbstractItemModel* model, const QModelIndex& index)
 
690
{
 
691
  QModelIndex idx = index;
 
692
  QAbstractItemModel* mymodel = model;
 
693
  while(qobject_cast<QAbstractProxyModel*>(mymodel))
 
694
    {
 
695
    idx = static_cast<QAbstractProxyModel*>(mymodel)->mapToSource(idx);
 
696
    mymodel = static_cast<QAbstractProxyModel*>(mymodel)->sourceModel();
 
697
    }
 
698
  QCMakeCacheModel* cache_model = qobject_cast<QCMakeCacheModel*>(mymodel);
 
699
  if(cache_model && idx.isValid())
 
700
    {
 
701
    QCMakeProperty prop;
 
702
    idx = idx.sibling(idx.row(), 0);
 
703
    cache_model->getPropertyData(idx, prop);
 
704
    
 
705
    // clean out an old one
 
706
    QSet<QCMakeProperty>::iterator iter = mChanges.find(prop);
 
707
    if(iter != mChanges.end())
 
708
      {
 
709
      mChanges.erase(iter);
 
710
      }
 
711
    // now add the new item
 
712
    mChanges.insert(prop);
 
713
    }
 
714
}
 
715