2007-11-02 18:55:57 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
2007-11-02 18:50:17 +03:00
|
|
|
|
|
|
|
#include "QCMakeCacheView.h"
|
|
|
|
|
|
|
|
#include <QToolButton>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QEvent>
|
2007-11-05 21:20:54 +03:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QKeyEvent>
|
2007-11-02 18:50:17 +03:00
|
|
|
|
2007-11-06 03:26:18 +03:00
|
|
|
static QRegExp AdvancedRegExp[2] = { QRegExp("(false)"), QRegExp("(true|false)") };
|
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
QCMakeCacheView::QCMakeCacheView(QWidget* p)
|
2007-11-03 17:30:52 +03:00
|
|
|
: QTableView(p), Init(false)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2007-11-06 03:26:18 +03:00
|
|
|
// hook up our model and search/filter proxies
|
|
|
|
this->CacheModel = new QCMakeCacheModel(this);
|
|
|
|
this->AdvancedFilter = new QSortFilterProxyModel(this);
|
|
|
|
this->AdvancedFilter->setSourceModel(this->CacheModel);
|
|
|
|
this->AdvancedFilter->setFilterRole(QCMakeCacheModel::AdvancedRole);
|
|
|
|
this->AdvancedFilter->setFilterRegExp(AdvancedRegExp[0]);
|
|
|
|
this->SearchFilter = new QSortFilterProxyModel(this);
|
|
|
|
this->SearchFilter->setSourceModel(this->AdvancedFilter);
|
2007-11-06 08:02:08 +03:00
|
|
|
this->SearchFilter->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
2007-11-06 03:26:18 +03:00
|
|
|
this->setModel(this->SearchFilter);
|
2007-11-02 18:50:17 +03:00
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
// our delegate for creating our editors
|
2007-11-02 18:50:17 +03:00
|
|
|
QCMakeCacheModelDelegate* delegate = new QCMakeCacheModelDelegate(this);
|
|
|
|
this->setItemDelegate(delegate);
|
2007-11-05 21:20:54 +03:00
|
|
|
|
|
|
|
// set up headers and sizes
|
|
|
|
int h = 0;
|
|
|
|
QFontMetrics met(this->font());
|
|
|
|
h = qMax(met.height(), this->style()->pixelMetric(QStyle::PM_IndicatorHeight));
|
|
|
|
this->verticalHeader()->setDefaultSectionSize(h + 4);
|
|
|
|
this->horizontalHeader()->setStretchLastSection(true);
|
|
|
|
this->verticalHeader()->hide();
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
2007-11-03 17:30:52 +03:00
|
|
|
void QCMakeCacheView::showEvent(QShowEvent* e)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2007-11-03 17:30:52 +03:00
|
|
|
if(!this->Init)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
|
|
|
// initialize the table view column size
|
|
|
|
int colWidth = this->columnWidth(0) + this->columnWidth(1);
|
|
|
|
this->setColumnWidth(0, colWidth/2);
|
|
|
|
this->setColumnWidth(1, colWidth/2);
|
2007-11-03 17:30:52 +03:00
|
|
|
this->Init = true;
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
2007-11-03 17:30:52 +03:00
|
|
|
return QTableView::showEvent(e);
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QCMakeCacheModel* QCMakeCacheView::cacheModel() const
|
|
|
|
{
|
2007-11-06 03:26:18 +03:00
|
|
|
return this->CacheModel;
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
2007-11-03 17:30:52 +03:00
|
|
|
QModelIndex QCMakeCacheView::moveCursor(CursorAction act,
|
|
|
|
Qt::KeyboardModifiers mod)
|
|
|
|
{
|
|
|
|
// tab through values only (not names)
|
|
|
|
QModelIndex current = this->currentIndex();
|
|
|
|
if(act == MoveNext)
|
|
|
|
{
|
|
|
|
if(!current.isValid())
|
|
|
|
{
|
|
|
|
return this->model()->index(0, 1);
|
|
|
|
}
|
|
|
|
else if(current.column() == 0)
|
|
|
|
{
|
|
|
|
return this->model()->index(current.row(), 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this->model()->index(current.row()+1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(act == MovePrevious)
|
|
|
|
{
|
|
|
|
if(!current.isValid())
|
|
|
|
{
|
|
|
|
return this->model()->index(0, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this->model()->index(current.row()-1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QTableView::moveCursor(act, mod);
|
|
|
|
}
|
2007-11-06 03:26:18 +03:00
|
|
|
|
|
|
|
void QCMakeCacheView::setShowAdvanced(bool s)
|
|
|
|
{
|
|
|
|
this->AdvancedFilter->setFilterRegExp(
|
|
|
|
s ? AdvancedRegExp[1] : AdvancedRegExp[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QCMakeCacheView::showAdvanced() const
|
|
|
|
{
|
|
|
|
return this->AdvancedFilter->filterRegExp() == AdvancedRegExp[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
void QCMakeCacheView::setSearchFilter(const QString& s)
|
|
|
|
{
|
|
|
|
this->SearchFilter->setFilterRegExp(s);
|
|
|
|
}
|
2007-11-03 17:30:52 +03:00
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
QCMakeCacheModel::QCMakeCacheModel(QObject* p)
|
2007-11-04 02:48:59 +03:00
|
|
|
: QAbstractTableModel(p), NewCount(0), IsDirty(false)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QCMakeCacheModel::~QCMakeCacheModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-11-03 17:30:52 +03:00
|
|
|
bool QCMakeCacheModel::isDirty() const
|
|
|
|
{
|
|
|
|
return this->IsDirty;
|
|
|
|
}
|
|
|
|
|
2007-11-04 02:48:59 +03:00
|
|
|
static uint qHash(const QCMakeCacheProperty& p)
|
|
|
|
{
|
|
|
|
return qHash(p.Key);
|
|
|
|
}
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
void QCMakeCacheModel::clear()
|
|
|
|
{
|
|
|
|
this->setProperties(QCMakeCachePropertyList());
|
|
|
|
}
|
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
void QCMakeCacheModel::setProperties(const QCMakeCachePropertyList& props)
|
|
|
|
{
|
2007-11-04 02:48:59 +03:00
|
|
|
QSet<QCMakeCacheProperty> newProps = props.toSet();
|
|
|
|
QSet<QCMakeCacheProperty> oldProps = this->Properties.toSet();
|
|
|
|
|
|
|
|
oldProps.intersect(newProps);
|
|
|
|
newProps.subtract(oldProps);
|
|
|
|
|
|
|
|
this->NewCount = newProps.count();
|
|
|
|
this->Properties.clear();
|
|
|
|
|
|
|
|
this->Properties = newProps.toList();
|
|
|
|
qSort(this->Properties);
|
|
|
|
QCMakeCachePropertyList tmp = oldProps.toList();
|
|
|
|
qSort(tmp);
|
|
|
|
this->Properties += tmp;
|
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
this->reset();
|
2007-11-03 17:30:52 +03:00
|
|
|
this->IsDirty = false;
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QCMakeCachePropertyList QCMakeCacheModel::properties() const
|
|
|
|
{
|
|
|
|
return this->Properties;
|
|
|
|
}
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
int QCMakeCacheModel::columnCount (const QModelIndex& /*p*/ ) const
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
QVariant QCMakeCacheModel::data (const QModelIndex& idx, int role) const
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
if(idx.column() == 0 && (role == Qt::DisplayRole || role == Qt::EditRole))
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
return this->Properties[idx.row()].Key;
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-05 21:20:54 +03:00
|
|
|
else if(idx.column() == 0 && role == Qt::ToolTipRole)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
return this->data(idx, Qt::DisplayRole).toString() + "\n" +
|
|
|
|
this->data(idx, QCMakeCacheModel::HelpRole).toString();
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-05 21:20:54 +03:00
|
|
|
else if(idx.column() == 1 && (role == Qt::DisplayRole || role == Qt::EditRole))
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
if(this->Properties[idx.row()].Type != QCMakeCacheProperty::BOOL)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
return this->Properties[idx.row()].Value;
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
|
|
|
}
|
2007-11-05 21:20:54 +03:00
|
|
|
else if(idx.column() == 1 && role == Qt::CheckStateRole)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
if(this->Properties[idx.row()].Type == QCMakeCacheProperty::BOOL)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
return this->Properties[idx.row()].Value.toBool() ? Qt::Checked : Qt::Unchecked;
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
else if(role == QCMakeCacheModel::HelpRole)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
return this->Properties[idx.row()].Help;
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
else if(role == QCMakeCacheModel::TypeRole)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
return this->Properties[idx.row()].Type;
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
else if(role == QCMakeCacheModel::AdvancedRole)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
return this->Properties[idx.row()].Advanced;
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-05 21:20:54 +03:00
|
|
|
else if(role == Qt::BackgroundRole && idx.row()+1 <= this->NewCount)
|
2007-11-04 02:48:59 +03:00
|
|
|
{
|
|
|
|
return QBrush(QColor(255,100,100));
|
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
QModelIndex QCMakeCacheModel::parent (const QModelIndex& /*idx*/) const
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
int QCMakeCacheModel::rowCount (const QModelIndex& p) const
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
if(p.isValid())
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-02 18:50:17 +03:00
|
|
|
return 0;
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
return this->Properties.count();
|
|
|
|
}
|
|
|
|
|
2007-11-03 20:28:09 +03:00
|
|
|
QVariant QCMakeCacheModel::headerData (int section, Qt::Orientation orient, int role) const
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2007-11-03 17:30:52 +03:00
|
|
|
// return header labels
|
2007-11-02 18:50:17 +03:00
|
|
|
if(role == Qt::DisplayRole && orient == Qt::Horizontal)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-02 18:50:17 +03:00
|
|
|
return section == 0 ? "Name" : "Value";
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
Qt::ItemFlags QCMakeCacheModel::flags (const QModelIndex& idx) const
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2007-11-03 17:30:52 +03:00
|
|
|
Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
|
|
// all column 1's are editable
|
2007-11-05 21:20:54 +03:00
|
|
|
if(idx.column() == 1)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
|
|
|
f |= Qt::ItemIsEditable;
|
|
|
|
// booleans are editable in place
|
2007-11-05 21:20:54 +03:00
|
|
|
if(this->Properties[idx.row()].Type == QCMakeCacheProperty::BOOL)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
|
|
|
f |= Qt::ItemIsUserCheckable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return f;
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
bool QCMakeCacheModel::setData (const QModelIndex& idx, const QVariant& value, int role)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
if(idx.column() == 0 && (role == Qt::DisplayRole || role == Qt::EditRole))
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
this->Properties[idx.row()].Key = value.toString();
|
2007-11-03 17:30:52 +03:00
|
|
|
this->IsDirty = true;
|
2007-11-05 21:20:54 +03:00
|
|
|
emit this->dataChanged(idx, idx);
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-05 21:20:54 +03:00
|
|
|
else if(idx.column() == 1 && (role == Qt::DisplayRole || role == Qt::EditRole))
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
this->Properties[idx.row()].Value = value.toString();
|
2007-11-03 17:30:52 +03:00
|
|
|
this->IsDirty = true;
|
2007-11-05 21:20:54 +03:00
|
|
|
emit this->dataChanged(idx, idx);
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-05 21:20:54 +03:00
|
|
|
else if(idx.column() == 1 && (role == Qt::CheckStateRole))
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
this->Properties[idx.row()].Value = value.toInt() == Qt::Checked;
|
2007-11-03 17:30:52 +03:00
|
|
|
this->IsDirty = true;
|
2007-11-05 21:20:54 +03:00
|
|
|
emit this->dataChanged(idx, idx);
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QCMakeCacheModelDelegate::QCMakeCacheModelDelegate(QObject* p)
|
|
|
|
: QItemDelegate(p)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p,
|
|
|
|
const QStyleOptionViewItem&, const QModelIndex& idx) const
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
QVariant type = idx.data(QCMakeCacheModel::TypeRole);
|
2007-11-02 18:50:17 +03:00
|
|
|
if(type == QCMakeCacheProperty::BOOL)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
else if(type == QCMakeCacheProperty::PATH)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
return new QCMakeCachePathEditor(idx.data().toString(), false, p);
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
else if(type == QCMakeCacheProperty::FILEPATH)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
return new QCMakeCachePathEditor(idx.data().toString(), true, p);
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
return new QLineEdit(p);
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
2007-11-05 21:20:54 +03:00
|
|
|
|
|
|
|
QCMakeCachePathEditor::QCMakeCachePathEditor(const QString& file, bool fp,
|
|
|
|
QWidget* p)
|
2007-11-03 17:30:52 +03:00
|
|
|
: QWidget(p), LineEdit(this), IsFilePath(fp)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
|
|
|
QHBoxLayout* l = new QHBoxLayout(this);
|
|
|
|
l->setMargin(0);
|
|
|
|
l->setSpacing(0);
|
|
|
|
l->addWidget(&this->LineEdit);
|
|
|
|
QToolButton* tb = new QToolButton(this);
|
|
|
|
tb->setText("...");
|
|
|
|
l->addWidget(tb);
|
|
|
|
QObject::connect(tb, SIGNAL(clicked(bool)),
|
|
|
|
this, SLOT(chooseFile()));
|
|
|
|
this->LineEdit.setText(file);
|
2007-11-05 21:20:54 +03:00
|
|
|
this->LineEdit.selectAll();
|
2007-11-02 18:50:17 +03:00
|
|
|
tb->setFocusProxy(&this->LineEdit);
|
|
|
|
this->setFocusProxy(&this->LineEdit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QCMakeCachePathEditor::chooseFile()
|
|
|
|
{
|
2007-11-03 17:30:52 +03:00
|
|
|
QString path;
|
|
|
|
if(this->IsFilePath)
|
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
QFileInfo info(this->value());
|
|
|
|
path = QFileDialog::getOpenFileName(this, tr("Select File"),
|
|
|
|
info.absolutePath());
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-05 21:20:54 +03:00
|
|
|
path = QFileDialog::getExistingDirectory(this, tr("Select Path"),
|
|
|
|
this->value());
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
if(!path.isEmpty())
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2007-11-02 18:50:17 +03:00
|
|
|
this->LineEdit.setText(path);
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|