1
/*=========================================================================
3
Program: CMake - Cross-Platform Makefile Generator
4
Module: $RCSfile: QCMakeCacheView.cxx,v $
6
Date: $Date: 2009-03-31 14:29:18 $
7
Version: $Revision: 1.26.2.5 $
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.
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.
16
=========================================================================*/
1
/*============================================================================
2
CMake - Cross Platform Makefile Generator
3
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5
Distributed under the OSI-approved BSD License (the "License");
6
see accompanying file Copyright.txt for details.
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
============================================================================*/
18
13
#include "QCMakeCacheView.h"
138
135
QCMakeCacheModelDelegate* delegate = new QCMakeCacheModelDelegate(this);
139
136
this->setItemDelegate(delegate);
141
this->setEditTriggers(QAbstractItemView::DoubleClicked |
142
QAbstractItemView::SelectedClicked |
143
QAbstractItemView::EditKeyPressed |
144
QAbstractItemView::AnyKeyPressed);
138
this->setUniformRowHeights(true);
140
this->setEditTriggers(QAbstractItemView::AllEditTriggers);
146
142
// tab, backtab doesn't step through items
147
143
this->setTabKeyNavigation(false);
249
245
QCMakePropertyList newP2 = newProps2.toList();
253
249
foreach(QCMakeProperty p, newP)
255
this->insertRow(rowCount);
256
this->setPropertyData(this->index(rowCount, 0), p, true);
251
this->insertRow(row_count);
252
this->setPropertyData(this->index(row_count, 0), p, true);
259
255
foreach(QCMakeProperty p, newP2)
261
this->insertRow(rowCount);
262
this->setPropertyData(this->index(rowCount, 0), p, false);
257
this->insertRow(row_count);
258
this->setPropertyData(this->index(row_count, 0), p, false);
266
262
else if(this->View == GroupView)
285
281
parentItems[1]->setData(QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
286
282
root->appendRow(parentItems);
288
foreach(QCMakeProperty prop, props)
284
int num = props2.size();
285
for(int i=0; i<num; i++)
287
QCMakeProperty prop = props2[i];
290
288
QList<QStandardItem*> items;
291
289
items.append(new QStandardItem());
292
290
items.append(new QStandardItem());
298
296
foreach(QString key, newPropsTree2.keys())
300
QCMakePropertyList props = newPropsTree2[key];
298
QCMakePropertyList props2 = newPropsTree2[key];
302
300
QStandardItem* parentItem =
303
301
new QStandardItem(key.isEmpty() ? tr("Ungrouped Entries") : key);
304
302
root->appendRow(parentItem);
306
foreach(QCMakeProperty prop, props)
304
int num = props2.size();
305
for(int i=0; i<num; i++)
307
QCMakeProperty prop = props2[i];
308
308
QList<QStandardItem*> items;
309
309
items.append(new QStandardItem());
310
310
items.append(new QStandardItem());
366
366
this->setData(idx2, prop.Help, QCMakeCacheModel::HelpRole);
368
if (!prop.Strings.isEmpty())
370
this->setData(idx1, prop.Strings, QCMakeCacheModel::StringsRole);
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)
386
392
int check = this->data(idx2, Qt::CheckStateRole).toInt();
573
579
SLOT(setFileDialogFlag(bool)));
582
else if(type == QCMakeProperty::STRING &&
583
var.data(QCMakeCacheModel::StringsRole).isValid())
585
QCMakeComboBox* editor =
586
new QCMakeComboBox(p, var.data(QCMakeCacheModel::StringsRole).toStringList());
587
editor->setFrame(false);
577
return new QLineEdit(p);
591
QLineEdit* editor = new QLineEdit(p);
592
editor->setFrame(false);
580
596
bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, QAbstractItemModel* model,
581
597
const QStyleOptionViewItem& option, const QModelIndex& index)
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);
639
this->recordChange(model, index);
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)
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)
652
if(evt->type() == QEvent::FocusOut && this->FileDialogFlag)
632
return QItemDelegate::eventFilter(object, event);
656
return QItemDelegate::eventFilter(object, evt);
659
void QCMakeCacheModelDelegate::setModelData(QWidget* editor,
660
QAbstractItemModel* model, const QModelIndex& index ) const
662
QItemDelegate::setModelData(editor, model, index);
663
const_cast<QCMakeCacheModelDelegate*>(this)->recordChange(model, index);
666
QSize QCMakeCacheModelDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
668
QSize sz = QItemDelegate::sizeHint(option, index);
669
QStyle *style = QApplication::style();
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());
679
QSet<QCMakeProperty> QCMakeCacheModelDelegate::changes() const
684
void QCMakeCacheModelDelegate::clearChanges()
689
void QCMakeCacheModelDelegate::recordChange(QAbstractItemModel* model, const QModelIndex& index)
691
QModelIndex idx = index;
692
QAbstractItemModel* mymodel = model;
693
while(qobject_cast<QAbstractProxyModel*>(mymodel))
695
idx = static_cast<QAbstractProxyModel*>(mymodel)->mapToSource(idx);
696
mymodel = static_cast<QAbstractProxyModel*>(mymodel)->sourceModel();
698
QCMakeCacheModel* cache_model = qobject_cast<QCMakeCacheModel*>(mymodel);
699
if(cache_model && idx.isValid())
702
idx = idx.sibling(idx.row(), 0);
703
cache_model->getPropertyData(idx, prop);
705
// clean out an old one
706
QSet<QCMakeProperty>::iterator iter = mChanges.find(prop);
707
if(iter != mChanges.end())
709
mChanges.erase(iter);
711
// now add the new item
712
mChanges.insert(prop);