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 <QHBoxLayout>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QEvent>
|
2007-11-05 21:20:54 +03:00
|
|
|
#include <QStyle>
|
|
|
|
#include <QKeyEvent>
|
2008-05-16 03:21:01 +04:00
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
|
|
|
#include "QCMakeWidgets.h"
|
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-16 18:40:23 +03:00
|
|
|
// filter for searches
|
|
|
|
class QCMakeSearchFilter : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QCMakeSearchFilter(QObject* o) : QSortFilterProxyModel(o) {}
|
|
|
|
protected:
|
|
|
|
bool filterAcceptsRow(int row, const QModelIndex& p) const
|
|
|
|
{
|
|
|
|
// accept row if either column matches
|
|
|
|
QModelIndex idx0 = this->sourceModel()->index(row, 0, p);
|
|
|
|
QModelIndex idx1 = this->sourceModel()->index(row, 1, p);
|
|
|
|
QString str0 = this->sourceModel()->data(idx0).toString();
|
|
|
|
QString str1 = this->sourceModel()->data(idx1).toString();
|
|
|
|
|
|
|
|
return str0.contains(this->filterRegExp()) ||
|
|
|
|
str1.contains(this->filterRegExp());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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]);
|
2007-11-13 07:54:49 +03:00
|
|
|
this->AdvancedFilter->setDynamicSortFilter(true);
|
2007-11-16 18:40:23 +03:00
|
|
|
this->SearchFilter = new QCMakeSearchFilter(this);
|
2007-11-06 03:26:18 +03:00
|
|
|
this->SearchFilter->setSourceModel(this->AdvancedFilter);
|
2007-11-06 08:02:08 +03:00
|
|
|
this->SearchFilter->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
2007-11-13 07:54:49 +03:00
|
|
|
this->SearchFilter->setDynamicSortFilter(true);
|
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-13 20:53:10 +03:00
|
|
|
|
2008-02-13 21:58:35 +03:00
|
|
|
this->setEditTriggers(QAbstractItemView::DoubleClicked |
|
|
|
|
QAbstractItemView::SelectedClicked |
|
|
|
|
QAbstractItemView::EditKeyPressed |
|
|
|
|
QAbstractItemView::AnyKeyPressed);
|
2007-11-05 21:20:54 +03:00
|
|
|
|
2008-02-15 02:18:10 +03:00
|
|
|
// tab, backtab doesn't step through items
|
|
|
|
this->setTabKeyNavigation(false);
|
|
|
|
|
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-10 19:36:09 +03:00
|
|
|
|
2007-11-03 17:30:52 +03:00
|
|
|
QModelIndex QCMakeCacheView::moveCursor(CursorAction act,
|
|
|
|
Qt::KeyboardModifiers mod)
|
|
|
|
{
|
2008-02-15 02:18:10 +03:00
|
|
|
// want home/end to go to begin/end of rows, not columns
|
|
|
|
if(act == MoveHome)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2008-02-15 02:18:10 +03:00
|
|
|
return this->model()->index(0, 1);
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2008-02-15 02:18:10 +03:00
|
|
|
else if(act == MoveEnd)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2008-02-15 02:18:10 +03:00
|
|
|
return this->model()->index(this->model()->rowCount()-1, 1);
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2007-11-08 18:17:37 +03:00
|
|
|
this->SearchFilter->setFilterFixedString(s);
|
2007-11-06 03:26:18 +03:00
|
|
|
}
|
2007-11-03 17:30:52 +03:00
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
QCMakeCacheModel::QCMakeCacheModel(QObject* p)
|
2007-11-07 18:09:02 +03:00
|
|
|
: QAbstractTableModel(p),
|
2007-11-09 23:18:49 +03:00
|
|
|
NewCount(0), EditEnabled(true)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QCMakeCacheModel::~QCMakeCacheModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-05-16 03:21:01 +04:00
|
|
|
static uint qHash(const QCMakeProperty& p)
|
2007-11-04 02:48:59 +03:00
|
|
|
{
|
|
|
|
return qHash(p.Key);
|
|
|
|
}
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
void QCMakeCacheModel::clear()
|
|
|
|
{
|
2008-05-16 03:21:01 +04:00
|
|
|
this->setProperties(QCMakePropertyList());
|
2007-11-05 21:20:54 +03:00
|
|
|
}
|
|
|
|
|
2008-05-16 03:21:01 +04:00
|
|
|
void QCMakeCacheModel::setProperties(const QCMakePropertyList& props)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2008-05-16 03:21:01 +04:00
|
|
|
QSet<QCMakeProperty> newProps = props.toSet();
|
|
|
|
QSet<QCMakeProperty> newProps2 = props.toSet();
|
|
|
|
QSet<QCMakeProperty> oldProps = this->Properties.toSet();
|
2007-11-04 02:48:59 +03:00
|
|
|
|
|
|
|
oldProps.intersect(newProps);
|
|
|
|
newProps.subtract(oldProps);
|
2007-11-10 19:36:09 +03:00
|
|
|
newProps2.subtract(newProps);
|
2007-11-04 02:48:59 +03:00
|
|
|
|
|
|
|
this->NewCount = newProps.count();
|
|
|
|
this->Properties.clear();
|
|
|
|
|
|
|
|
this->Properties = newProps.toList();
|
|
|
|
qSort(this->Properties);
|
2008-05-16 03:21:01 +04:00
|
|
|
QCMakePropertyList tmp = newProps2.toList();
|
2007-11-04 02:48:59 +03:00
|
|
|
qSort(tmp);
|
|
|
|
this->Properties += tmp;
|
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
this->reset();
|
|
|
|
}
|
|
|
|
|
2008-05-16 03:21:01 +04:00
|
|
|
QCMakePropertyList QCMakeCacheModel::properties() const
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
|
|
|
return this->Properties;
|
|
|
|
}
|
2008-05-16 03:21:01 +04:00
|
|
|
|
|
|
|
bool QCMakeCacheModel::insertProperty(int row, QCMakeProperty::PropertyType t,
|
|
|
|
const QString& name, const QString& description,
|
|
|
|
const QVariant& value, bool advanced)
|
|
|
|
{
|
|
|
|
if(this->insertRows(row, 1, QModelIndex()))
|
|
|
|
{
|
|
|
|
QModelIndex idx1 = this->index(row, 0);
|
|
|
|
QModelIndex idx2 = this->index(row, 1);
|
|
|
|
|
|
|
|
this->setData(idx1, t, QCMakeCacheModel::TypeRole);
|
|
|
|
this->setData(idx1, name, Qt::DisplayRole);
|
|
|
|
this->setData(idx1, description, QCMakeCacheModel::HelpRole);
|
|
|
|
this->setData(idx1, advanced, QCMakeCacheModel::AdvancedRole);
|
|
|
|
if(t == QCMakeProperty::BOOL)
|
|
|
|
{
|
|
|
|
this->setData(idx2, value.toBool() ? Qt::Checked : Qt::Unchecked,
|
|
|
|
Qt::CheckStateRole);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->setData(idx2, value, Qt::DisplayRole);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
|
2007-11-07 18:09:02 +03:00
|
|
|
void QCMakeCacheModel::setEditEnabled(bool e)
|
|
|
|
{
|
|
|
|
this->EditEnabled = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QCMakeCacheModel::editEnabled() const
|
|
|
|
{
|
|
|
|
return this->EditEnabled;
|
|
|
|
}
|
|
|
|
|
2007-11-09 23:18:49 +03:00
|
|
|
int QCMakeCacheModel::newCount() const
|
|
|
|
{
|
|
|
|
return this->NewCount;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2008-05-16 03:21:01 +04:00
|
|
|
if(this->Properties[idx.row()].Type != QCMakeProperty::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
|
|
|
{
|
2008-05-16 03:21:01 +04:00
|
|
|
if(this->Properties[idx.row()].Type == QCMakeProperty::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-07 18:09:02 +03:00
|
|
|
if(idx.column() == 1 && this->EditEnabled)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
|
|
|
f |= Qt::ItemIsEditable;
|
|
|
|
// booleans are editable in place
|
2008-05-16 03:21:01 +04:00
|
|
|
if(this->Properties[idx.row()].Type == QCMakeProperty::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();
|
|
|
|
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();
|
|
|
|
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;
|
|
|
|
emit this->dataChanged(idx, idx);
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2007-11-13 07:54:49 +03:00
|
|
|
else if(role == QCMakeCacheModel::HelpRole)
|
|
|
|
{
|
|
|
|
this->Properties[idx.row()].Help = value.toString();
|
|
|
|
emit this->dataChanged(idx, idx);
|
|
|
|
}
|
|
|
|
else if(role == QCMakeCacheModel::TypeRole)
|
|
|
|
{
|
2008-05-16 03:21:01 +04:00
|
|
|
this->Properties[idx.row()].Type = static_cast<QCMakeProperty::PropertyType>(value.toInt());
|
2007-11-13 07:54:49 +03:00
|
|
|
}
|
|
|
|
else if(role == QCMakeCacheModel::AdvancedRole)
|
|
|
|
{
|
|
|
|
this->Properties[idx.row()].Advanced = value.toBool();
|
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-11-13 08:17:10 +03:00
|
|
|
QModelIndex QCMakeCacheModel::buddy(const QModelIndex& idx) const
|
2007-11-08 18:17:37 +03:00
|
|
|
{
|
|
|
|
if(idx.column() == 0)
|
|
|
|
{
|
2008-05-16 03:21:01 +04:00
|
|
|
if(this->Properties[idx.row()].Type != QCMakeProperty::BOOL)
|
2007-11-13 08:17:10 +03:00
|
|
|
{
|
|
|
|
return this->index(idx.row(), 1);
|
|
|
|
}
|
2007-11-08 18:17:37 +03:00
|
|
|
}
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2007-11-10 19:36:09 +03:00
|
|
|
bool QCMakeCacheModel::removeRows(int row, int num, const QModelIndex&)
|
2007-11-08 18:17:37 +03:00
|
|
|
{
|
2007-11-10 19:36:09 +03:00
|
|
|
if(row < 0 || row+num > this->Properties.count())
|
2007-11-08 18:17:37 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2007-11-10 19:36:09 +03:00
|
|
|
this->beginRemoveRows(QModelIndex(), row, row+num-1);
|
|
|
|
for(int i=0; i<num; i++)
|
2007-11-08 18:17:37 +03:00
|
|
|
{
|
2007-11-10 19:36:09 +03:00
|
|
|
this->Properties.removeAt(row);
|
|
|
|
if(this->NewCount >= row+1)
|
|
|
|
{
|
|
|
|
this->NewCount--;
|
|
|
|
}
|
2007-11-08 18:17:37 +03:00
|
|
|
}
|
|
|
|
this->endRemoveRows();
|
|
|
|
return true;
|
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
|
2007-11-13 07:54:49 +03:00
|
|
|
bool QCMakeCacheModel::insertRows(int row, int num, const QModelIndex&)
|
|
|
|
{
|
|
|
|
if(row < 0)
|
|
|
|
row = 0;
|
|
|
|
if(row > this->rowCount())
|
|
|
|
row = this->rowCount();
|
|
|
|
|
|
|
|
this->beginInsertRows(QModelIndex(), row, row+num-1);
|
|
|
|
for(int i=0; i<num; i++)
|
|
|
|
{
|
2008-05-16 03:21:01 +04:00
|
|
|
this->Properties.insert(row+i, QCMakeProperty());
|
2007-11-13 07:54:49 +03:00
|
|
|
if(this->NewCount >= row)
|
|
|
|
{
|
|
|
|
this->NewCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->endInsertRows();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
QCMakeCacheModelDelegate::QCMakeCacheModelDelegate(QObject* p)
|
2008-04-02 23:28:17 +04:00
|
|
|
: QItemDelegate(p), FileDialogFlag(false)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-02 23:28:17 +04:00
|
|
|
void QCMakeCacheModelDelegate::setFileDialogFlag(bool f)
|
|
|
|
{
|
|
|
|
this->FileDialogFlag = f;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2008-02-08 01:58:57 +03:00
|
|
|
const QAbstractItemModel* model = idx.model();
|
|
|
|
QModelIndex var = model->index(idx.row(), 0);
|
2007-11-05 21:20:54 +03:00
|
|
|
QVariant type = idx.data(QCMakeCacheModel::TypeRole);
|
2008-05-16 03:21:01 +04:00
|
|
|
if(type == QCMakeProperty::BOOL)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-05-16 03:21:01 +04:00
|
|
|
else if(type == QCMakeProperty::PATH)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2008-05-16 03:21:01 +04:00
|
|
|
QCMakePathEditor* editor =
|
|
|
|
new QCMakePathEditor(p,
|
2008-02-08 01:58:57 +03:00
|
|
|
var.data(Qt::DisplayRole).toString());
|
2008-04-02 23:28:17 +04:00
|
|
|
QObject::connect(editor, SIGNAL(fileDialogExists(bool)), this,
|
|
|
|
SLOT(setFileDialogFlag(bool)));
|
|
|
|
return editor;
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2008-05-16 03:21:01 +04:00
|
|
|
else if(type == QCMakeProperty::FILEPATH)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2008-05-16 03:21:01 +04:00
|
|
|
QCMakeFilePathEditor* editor =
|
|
|
|
new QCMakeFilePathEditor(p,
|
2008-02-08 01:58:57 +03:00
|
|
|
var.data(Qt::DisplayRole).toString());
|
2008-04-02 23:28:17 +04:00
|
|
|
QObject::connect(editor, SIGNAL(fileDialogExists(bool)), this,
|
|
|
|
SLOT(setFileDialogFlag(bool)));
|
|
|
|
return editor;
|
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
|
|
|
|
2007-11-15 07:30:05 +03:00
|
|
|
bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, QAbstractItemModel* model,
|
2007-11-13 08:17:10 +03:00
|
|
|
const QStyleOptionViewItem& option, const QModelIndex& index)
|
|
|
|
{
|
|
|
|
Qt::ItemFlags flags = model->flags(index);
|
|
|
|
if (!(flags & Qt::ItemIsUserCheckable) || !(option.state & QStyle::State_Enabled)
|
|
|
|
|| !(flags & Qt::ItemIsEnabled))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant value = index.data(Qt::CheckStateRole);
|
|
|
|
if (!value.isValid())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-11-15 07:30:05 +03:00
|
|
|
if ((e->type() == QEvent::MouseButtonRelease)
|
|
|
|
|| (e->type() == QEvent::MouseButtonDblClick))
|
2007-11-13 08:17:10 +03:00
|
|
|
{
|
|
|
|
// eat the double click events inside the check rect
|
2007-11-15 07:30:05 +03:00
|
|
|
if (e->type() == QEvent::MouseButtonDblClick)
|
2007-11-13 08:17:10 +03:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 07:30:05 +03:00
|
|
|
else if (e->type() == QEvent::KeyPress)
|
2007-11-13 08:17:10 +03:00
|
|
|
{
|
2007-11-15 07:30:05 +03:00
|
|
|
if(static_cast<QKeyEvent*>(e)->key() != Qt::Key_Space &&
|
|
|
|
static_cast<QKeyEvent*>(e)->key() != Qt::Key_Select)
|
2007-11-13 08:17:10 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
|
|
|
|
? Qt::Unchecked : Qt::Checked);
|
|
|
|
return model->setData(index, state, Qt::CheckStateRole);
|
|
|
|
}
|
|
|
|
|
2008-04-02 23:28:17 +04:00
|
|
|
bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* event)
|
|
|
|
{
|
|
|
|
// workaround for what looks like a bug in Qt on Mac OS X
|
|
|
|
if(event->type() == QEvent::FocusOut && this->FileDialogFlag)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return QItemDelegate::eventFilter(object, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|