2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2007-11-02 18:55:57 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2007-11-02 18:55:57 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License 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>
|
2009-07-17 22:38:36 +04:00
|
|
|
#include <QMetaProperty>
|
2009-08-10 21:25:22 +04:00
|
|
|
#include <QApplication>
|
2008-05-16 03:21:01 +04:00
|
|
|
|
|
|
|
#include "QCMakeWidgets.h"
|
2007-11-02 18:50:17 +03:00
|
|
|
|
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
|
|
|
|
{
|
2008-06-10 08:17:00 +04:00
|
|
|
QStringList strs;
|
|
|
|
const QAbstractItemModel* m = this->sourceModel();
|
|
|
|
QModelIndex idx = m->index(row, 0, p);
|
2007-11-16 18:40:23 +03:00
|
|
|
|
2008-06-10 08:17:00 +04:00
|
|
|
// if there are no children, get strings for column 0 and 1
|
|
|
|
if(!m->hasChildren(idx))
|
|
|
|
{
|
|
|
|
strs.append(m->data(idx).toString());
|
|
|
|
idx = m->index(row, 1, p);
|
|
|
|
strs.append(m->data(idx).toString());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// get strings for children entries to compare with
|
|
|
|
// instead of comparing with the parent
|
|
|
|
int num = m->rowCount(idx);
|
|
|
|
for(int i=0; i<num; i++)
|
|
|
|
{
|
|
|
|
QModelIndex tmpidx = m->index(i, 0, idx);
|
|
|
|
strs.append(m->data(tmpidx).toString());
|
|
|
|
tmpidx = m->index(i, 1, idx);
|
|
|
|
strs.append(m->data(tmpidx).toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check all strings for a match
|
|
|
|
foreach(QString str, strs)
|
|
|
|
{
|
|
|
|
if(str.contains(this->filterRegExp()))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-06-10 08:17:00 +04:00
|
|
|
return false;
|
2007-11-16 18:40:23 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
// filter for searches
|
|
|
|
class QCMakeAdvancedFilter : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
public:
|
2012-08-13 21:42:58 +04:00
|
|
|
QCMakeAdvancedFilter(QObject* o)
|
2008-06-13 19:19:53 +04:00
|
|
|
: QSortFilterProxyModel(o), ShowAdvanced(false) {}
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
void setShowAdvanced(bool f)
|
|
|
|
{
|
2008-06-13 19:19:53 +04:00
|
|
|
this->ShowAdvanced = f;
|
|
|
|
this->invalidate();
|
|
|
|
}
|
|
|
|
bool showAdvanced() const { return this->ShowAdvanced; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
bool ShowAdvanced;
|
|
|
|
|
|
|
|
bool filterAcceptsRow(int row, const QModelIndex& p) const
|
|
|
|
{
|
|
|
|
const QAbstractItemModel* m = this->sourceModel();
|
|
|
|
QModelIndex idx = m->index(row, 0, p);
|
|
|
|
|
|
|
|
// if there are no children
|
|
|
|
if(!m->hasChildren(idx))
|
|
|
|
{
|
|
|
|
bool adv = m->data(idx, QCMakeCacheModel::AdvancedRole).toBool();
|
|
|
|
if(!adv || (adv && this->ShowAdvanced))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
// check children
|
|
|
|
int num = m->rowCount(idx);
|
|
|
|
for(int i=0; i<num; i++)
|
|
|
|
{
|
|
|
|
bool accept = this->filterAcceptsRow(i, idx);
|
|
|
|
if(accept)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
QCMakeCacheView::QCMakeCacheView(QWidget* p)
|
2008-06-13 19:19:53 +04:00
|
|
|
: QTreeView(p)
|
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);
|
2008-06-13 19:19:53 +04:00
|
|
|
this->AdvancedFilter = new QCMakeAdvancedFilter(this);
|
2007-11-06 03:26:18 +03:00
|
|
|
this->AdvancedFilter->setSourceModel(this->CacheModel);
|
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);
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2009-08-10 21:25:22 +04:00
|
|
|
this->setUniformRowHeights(true);
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2009-08-10 21:25:22 +04:00
|
|
|
this->setEditTriggers(QAbstractItemView::AllEditTriggers);
|
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);
|
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
this->setRootIsDecorated(false);
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
bool QCMakeCacheView::event(QEvent* e)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2008-06-30 22:29:08 +04:00
|
|
|
if(e->type() == QEvent::Show)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2008-06-13 19:19:53 +04:00
|
|
|
this->header()->setDefaultSectionSize(this->viewport()->width()/2);
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
2008-06-13 19:19:53 +04:00
|
|
|
return QTreeView::event(e);
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
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
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
|
|
|
QModelIndex QCMakeCacheView::moveCursor(CursorAction act,
|
2007-11-03 17:30:52 +03:00
|
|
|
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
|
|
|
}
|
2008-06-10 08:17:00 +04:00
|
|
|
return QTreeView::moveCursor(act, mod);
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2007-11-06 03:26:18 +03:00
|
|
|
void QCMakeCacheView::setShowAdvanced(bool s)
|
|
|
|
{
|
2008-06-11 22:47:56 +04:00
|
|
|
#if QT_VERSION >= 040300
|
|
|
|
// new 4.3 api that needs to be called. what about an older Qt?
|
|
|
|
this->SearchFilter->invalidate();
|
|
|
|
#endif
|
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
this->AdvancedFilter->setShowAdvanced(s);
|
2007-11-06 03:26:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QCMakeCacheView::showAdvanced() const
|
|
|
|
{
|
2008-06-13 19:19:53 +04:00
|
|
|
return this->AdvancedFilter->showAdvanced();
|
2007-11-06 03:26:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2008-06-13 19:19:53 +04:00
|
|
|
: QStandardItemModel(p),
|
|
|
|
EditEnabled(true),
|
|
|
|
NewPropertyCount(0),
|
|
|
|
View(FlatView)
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2010-12-18 05:04:57 +03:00
|
|
|
this->ShowNewProperties = true;
|
2008-06-13 19:19:53 +04:00
|
|
|
QStringList labels;
|
|
|
|
labels << tr("Name") << tr("Value");
|
|
|
|
this->setHorizontalHeaderLabels(labels);
|
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);
|
|
|
|
}
|
|
|
|
|
2010-12-18 05:04:57 +03:00
|
|
|
void QCMakeCacheModel::setShowNewProperties(bool f)
|
|
|
|
{
|
|
|
|
this->ShowNewProperties = f;
|
|
|
|
}
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
void QCMakeCacheModel::clear()
|
|
|
|
{
|
2008-06-13 19:19:53 +04:00
|
|
|
this->QStandardItemModel::clear();
|
|
|
|
this->NewPropertyCount = 0;
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
QStringList labels;
|
|
|
|
labels << tr("Name") << tr("Value");
|
|
|
|
this->setHorizontalHeaderLabels(labels);
|
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
|
|
|
{
|
2010-12-18 05:04:57 +03:00
|
|
|
QSet<QCMakeProperty> newProps, newProps2;
|
|
|
|
|
|
|
|
if(this->ShowNewProperties)
|
|
|
|
{
|
|
|
|
newProps = props.toSet();
|
|
|
|
newProps2 = newProps;
|
|
|
|
QSet<QCMakeProperty> oldProps = this->properties().toSet();
|
|
|
|
oldProps.intersect(newProps);
|
|
|
|
newProps.subtract(oldProps);
|
|
|
|
newProps2.subtract(newProps);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newProps2 = props.toSet();
|
|
|
|
}
|
2007-11-04 02:48:59 +03:00
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
bool b = this->blockSignals(true);
|
|
|
|
|
|
|
|
this->clear();
|
|
|
|
this->NewPropertyCount = newProps.size();
|
2007-11-04 02:48:59 +03:00
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
if(View == FlatView)
|
|
|
|
{
|
|
|
|
QCMakePropertyList newP = newProps.toList();
|
|
|
|
QCMakePropertyList newP2 = newProps2.toList();
|
|
|
|
qSort(newP);
|
|
|
|
qSort(newP2);
|
2009-09-23 21:09:56 +04:00
|
|
|
int row_count = 0;
|
2008-06-13 19:19:53 +04:00
|
|
|
foreach(QCMakeProperty p, newP)
|
2008-06-10 08:17:00 +04:00
|
|
|
{
|
2009-09-23 21:09:56 +04:00
|
|
|
this->insertRow(row_count);
|
|
|
|
this->setPropertyData(this->index(row_count, 0), p, true);
|
|
|
|
row_count++;
|
2008-06-10 08:17:00 +04:00
|
|
|
}
|
2008-06-13 19:19:53 +04:00
|
|
|
foreach(QCMakeProperty p, newP2)
|
2008-06-10 08:17:00 +04:00
|
|
|
{
|
2009-09-23 21:09:56 +04:00
|
|
|
this->insertRow(row_count);
|
|
|
|
this->setPropertyData(this->index(row_count, 0), p, false);
|
|
|
|
row_count++;
|
2008-06-10 08:17:00 +04:00
|
|
|
}
|
2008-06-13 19:19:53 +04:00
|
|
|
}
|
|
|
|
else if(this->View == GroupView)
|
|
|
|
{
|
|
|
|
QMap<QString, QCMakePropertyList> newPropsTree;
|
|
|
|
this->breakProperties(newProps, newPropsTree);
|
|
|
|
QMap<QString, QCMakePropertyList> newPropsTree2;
|
|
|
|
this->breakProperties(newProps2, newPropsTree2);
|
|
|
|
|
|
|
|
QStandardItem* root = this->invisibleRootItem();
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
foreach(QString key, newPropsTree.keys())
|
|
|
|
{
|
2009-09-23 21:09:56 +04:00
|
|
|
QCMakePropertyList props2 = newPropsTree[key];
|
2008-06-13 19:19:53 +04:00
|
|
|
|
|
|
|
QList<QStandardItem*> parentItems;
|
|
|
|
parentItems.append(
|
|
|
|
new QStandardItem(key.isEmpty() ? tr("Ungrouped Entries") : key)
|
|
|
|
);
|
|
|
|
parentItems.append(new QStandardItem());
|
2008-06-14 00:57:07 +04:00
|
|
|
parentItems[0]->setData(QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
|
|
|
|
parentItems[1]->setData(QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
|
2011-01-28 18:50:56 +03:00
|
|
|
parentItems[0]->setData(1, GroupRole);
|
|
|
|
parentItems[1]->setData(1, GroupRole);
|
2008-06-13 19:19:53 +04:00
|
|
|
root->appendRow(parentItems);
|
|
|
|
|
2009-09-23 21:09:56 +04:00
|
|
|
int num = props2.size();
|
|
|
|
for(int i=0; i<num; i++)
|
2008-06-13 19:19:53 +04:00
|
|
|
{
|
2009-09-23 21:09:56 +04:00
|
|
|
QCMakeProperty prop = props2[i];
|
2008-06-13 19:19:53 +04:00
|
|
|
QList<QStandardItem*> items;
|
|
|
|
items.append(new QStandardItem());
|
|
|
|
items.append(new QStandardItem());
|
|
|
|
parentItems[0]->appendRow(items);
|
|
|
|
this->setPropertyData(this->indexFromItem(items[0]), prop, true);
|
|
|
|
}
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
foreach(QString key, newPropsTree2.keys())
|
|
|
|
{
|
2009-09-23 21:09:56 +04:00
|
|
|
QCMakePropertyList props2 = newPropsTree2[key];
|
2008-06-13 19:19:53 +04:00
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
QStandardItem* parentItem =
|
2008-06-13 19:19:53 +04:00
|
|
|
new QStandardItem(key.isEmpty() ? tr("Ungrouped Entries") : key);
|
|
|
|
root->appendRow(parentItem);
|
2011-01-28 18:50:56 +03:00
|
|
|
parentItem->setData(1, GroupRole);
|
2008-06-13 19:19:53 +04:00
|
|
|
|
2009-09-23 21:09:56 +04:00
|
|
|
int num = props2.size();
|
|
|
|
for(int i=0; i<num; i++)
|
2008-06-13 19:19:53 +04:00
|
|
|
{
|
2009-09-23 21:09:56 +04:00
|
|
|
QCMakeProperty prop = props2[i];
|
2008-06-13 19:19:53 +04:00
|
|
|
QList<QStandardItem*> items;
|
|
|
|
items.append(new QStandardItem());
|
|
|
|
items.append(new QStandardItem());
|
|
|
|
parentItem->appendRow(items);
|
|
|
|
this->setPropertyData(this->indexFromItem(items[0]), prop, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
this->blockSignals(b);
|
|
|
|
this->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
QCMakeCacheModel::ViewType QCMakeCacheModel::viewType() const
|
|
|
|
{
|
|
|
|
return this->View;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QCMakeCacheModel::setViewType(QCMakeCacheModel::ViewType t)
|
|
|
|
{
|
|
|
|
this->View = t;
|
|
|
|
|
|
|
|
QCMakePropertyList props = this->properties();
|
|
|
|
QCMakePropertyList oldProps;
|
|
|
|
int numNew = this->NewPropertyCount;
|
|
|
|
int numTotal = props.count();
|
|
|
|
for(int i=numNew; i<numTotal; i++)
|
|
|
|
{
|
|
|
|
oldProps.append(props[i]);
|
|
|
|
}
|
2008-06-10 08:17:00 +04:00
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
bool b = this->blockSignals(true);
|
|
|
|
this->clear();
|
|
|
|
this->setProperties(oldProps);
|
|
|
|
this->setProperties(props);
|
|
|
|
this->blockSignals(b);
|
2007-11-02 18:50:17 +03:00
|
|
|
this->reset();
|
|
|
|
}
|
2008-06-10 08:17:00 +04:00
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
void QCMakeCacheModel::setPropertyData(const QModelIndex& idx1,
|
2008-06-13 19:19:53 +04:00
|
|
|
const QCMakeProperty& prop, bool isNew)
|
|
|
|
{
|
|
|
|
QModelIndex idx2 = idx1.sibling(idx1.row(), 1);
|
|
|
|
|
|
|
|
this->setData(idx1, prop.Key, Qt::DisplayRole);
|
|
|
|
this->setData(idx1, prop.Help, QCMakeCacheModel::HelpRole);
|
|
|
|
this->setData(idx1, prop.Type, QCMakeCacheModel::TypeRole);
|
|
|
|
this->setData(idx1, prop.Advanced, QCMakeCacheModel::AdvancedRole);
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
if(prop.Type == QCMakeProperty::BOOL)
|
|
|
|
{
|
|
|
|
int check = prop.Value.toBool() ? Qt::Checked : Qt::Unchecked;
|
|
|
|
this->setData(idx2, check, Qt::CheckStateRole);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->setData(idx2, prop.Value, Qt::DisplayRole);
|
|
|
|
}
|
|
|
|
this->setData(idx2, prop.Help, QCMakeCacheModel::HelpRole);
|
|
|
|
|
2009-03-12 18:19:27 +03:00
|
|
|
if (!prop.Strings.isEmpty())
|
|
|
|
{
|
|
|
|
this->setData(idx1, prop.Strings, QCMakeCacheModel::StringsRole);
|
|
|
|
}
|
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
if(isNew)
|
|
|
|
{
|
2008-06-14 00:57:07 +04:00
|
|
|
this->setData(idx1, QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
|
|
|
|
this->setData(idx2, QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
|
2008-06-13 19:19:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
void QCMakeCacheModel::getPropertyData(const QModelIndex& idx1,
|
2008-06-13 19:19:53 +04:00
|
|
|
QCMakeProperty& prop) const
|
|
|
|
{
|
|
|
|
QModelIndex idx2 = idx1.sibling(idx1.row(), 1);
|
|
|
|
|
|
|
|
prop.Key = this->data(idx1, Qt::DisplayRole).toString();
|
|
|
|
prop.Help = this->data(idx1, HelpRole).toString();
|
|
|
|
prop.Type = static_cast<QCMakeProperty::PropertyType>(this->data(idx1, TypeRole).toInt());
|
|
|
|
prop.Advanced = this->data(idx1, AdvancedRole).toBool();
|
2009-03-12 18:19:27 +03:00
|
|
|
prop.Strings = this->data(idx1, QCMakeCacheModel::StringsRole).toStringList();
|
2008-06-13 19:19:53 +04:00
|
|
|
if(prop.Type == QCMakeProperty::BOOL)
|
|
|
|
{
|
|
|
|
int check = this->data(idx2, Qt::CheckStateRole).toInt();
|
|
|
|
prop.Value = check == Qt::Checked;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prop.Value = this->data(idx2, Qt::DisplayRole).toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-10 08:17:00 +04:00
|
|
|
QString QCMakeCacheModel::prefix(const QString& s)
|
|
|
|
{
|
|
|
|
QString prefix = s.section('_', 0, 0);
|
2008-06-11 02:53:22 +04:00
|
|
|
if(prefix == s)
|
|
|
|
{
|
|
|
|
prefix = QString();
|
|
|
|
}
|
2008-06-10 08:17:00 +04:00
|
|
|
return prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QCMakeCacheModel::breakProperties(const QSet<QCMakeProperty>& props,
|
|
|
|
QMap<QString, QCMakePropertyList>& result)
|
|
|
|
{
|
2008-06-11 02:53:22 +04:00
|
|
|
QMap<QString, QCMakePropertyList> tmp;
|
2008-06-10 08:17:00 +04:00
|
|
|
// return a map of properties grouped by prefixes, and sorted
|
|
|
|
foreach(QCMakeProperty p, props)
|
|
|
|
{
|
|
|
|
QString prefix = QCMakeCacheModel::prefix(p.Key);
|
2008-06-11 02:53:22 +04:00
|
|
|
tmp[prefix].append(p);
|
2008-06-10 08:17:00 +04:00
|
|
|
}
|
2008-06-11 02:53:22 +04:00
|
|
|
// sort it and re-org any properties with only one sub item
|
|
|
|
QCMakePropertyList reorgProps;
|
2008-06-10 08:17:00 +04:00
|
|
|
QMap<QString, QCMakePropertyList>::iterator iter;
|
2008-06-11 02:53:22 +04:00
|
|
|
for(iter = tmp.begin(); iter != tmp.end();)
|
|
|
|
{
|
|
|
|
if(iter->count() == 1)
|
|
|
|
{
|
|
|
|
reorgProps.append((*iter)[0]);
|
|
|
|
iter = tmp.erase(iter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qSort(*iter);
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(reorgProps.count())
|
2008-06-10 08:17:00 +04:00
|
|
|
{
|
2008-06-13 19:19:53 +04:00
|
|
|
tmp[QString()] += reorgProps;
|
2008-06-10 08:17:00 +04:00
|
|
|
}
|
2008-06-11 02:53:22 +04:00
|
|
|
result = tmp;
|
2008-06-10 08:17:00 +04:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-05-16 03:21:01 +04:00
|
|
|
QCMakePropertyList QCMakeCacheModel::properties() const
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2008-06-10 08:17:00 +04:00
|
|
|
QCMakePropertyList props;
|
2008-06-13 19:19:53 +04:00
|
|
|
|
2008-06-24 08:00:42 +04:00
|
|
|
if(!this->rowCount())
|
|
|
|
{
|
|
|
|
return props;
|
|
|
|
}
|
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
QList<QModelIndex> idxs;
|
|
|
|
idxs.append(this->index(0,0));
|
|
|
|
|
|
|
|
// walk the entire model for property entries
|
|
|
|
// this works regardless of a flat view or a tree view
|
|
|
|
while(!idxs.isEmpty())
|
|
|
|
{
|
|
|
|
QModelIndex idx = idxs.last();
|
|
|
|
if(this->hasChildren(idx) && this->rowCount(idx))
|
2008-06-10 08:17:00 +04:00
|
|
|
{
|
2008-06-13 19:19:53 +04:00
|
|
|
idxs.append(this->index(0,0, idx));
|
2008-06-10 08:17:00 +04:00
|
|
|
}
|
2008-06-13 19:19:53 +04:00
|
|
|
else
|
2008-06-10 08:17:00 +04:00
|
|
|
{
|
2011-01-28 18:50:56 +03:00
|
|
|
if(!data(idx, GroupRole).toInt())
|
|
|
|
{
|
|
|
|
// get data
|
|
|
|
QCMakeProperty prop;
|
|
|
|
this->getPropertyData(idx, prop);
|
|
|
|
props.append(prop);
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
// go to the next in the tree
|
|
|
|
while(!idxs.isEmpty() && !idxs.last().sibling(idxs.last().row()+1, 0).isValid())
|
|
|
|
{
|
|
|
|
idxs.removeLast();
|
|
|
|
}
|
|
|
|
if(!idxs.isEmpty())
|
|
|
|
{
|
|
|
|
idxs.last() = idxs.last().sibling(idxs.last().row()+1, 0);
|
|
|
|
}
|
2008-06-10 08:17:00 +04:00
|
|
|
}
|
2008-06-13 19:19:53 +04:00
|
|
|
}
|
|
|
|
|
2008-06-10 08:17:00 +04:00
|
|
|
return props;
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-06-10 08:17:00 +04:00
|
|
|
bool QCMakeCacheModel::insertProperty(QCMakeProperty::PropertyType t,
|
2008-05-16 03:21:01 +04:00
|
|
|
const QString& name, const QString& description,
|
|
|
|
const QVariant& value, bool advanced)
|
|
|
|
{
|
2008-06-10 08:17:00 +04:00
|
|
|
QCMakeProperty prop;
|
|
|
|
prop.Key = name;
|
|
|
|
prop.Value = value;
|
|
|
|
prop.Help = description;
|
|
|
|
prop.Type = t;
|
|
|
|
prop.Advanced = advanced;
|
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
//insert at beginning
|
|
|
|
this->insertRow(0);
|
|
|
|
this->setPropertyData(this->index(0,0), prop, true);
|
|
|
|
this->NewPropertyCount++;
|
2008-06-10 08:17:00 +04:00
|
|
|
return true;
|
2008-05-16 03:21:01 +04:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2008-06-13 19:19:53 +04:00
|
|
|
int QCMakeCacheModel::newPropertyCount() const
|
2007-11-09 23:18:49 +03:00
|
|
|
{
|
2008-06-13 19:19:53 +04:00
|
|
|
return this->NewPropertyCount;
|
2007-11-09 23:18:49 +03:00
|
|
|
}
|
|
|
|
|
2007-11-05 21:20:54 +03:00
|
|
|
Qt::ItemFlags QCMakeCacheModel::flags (const QModelIndex& idx) const
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2008-06-13 19:19:53 +04:00
|
|
|
Qt::ItemFlags f = QStandardItemModel::flags(idx);
|
|
|
|
if(!this->EditEnabled)
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2008-06-13 19:19:53 +04:00
|
|
|
f &= ~Qt::ItemIsEditable;
|
2009-03-26 18:42:37 +03:00
|
|
|
return f;
|
2007-11-03 17:30:52 +03:00
|
|
|
}
|
2008-06-13 19:19:53 +04:00
|
|
|
if(QCMakeProperty::BOOL == this->data(idx, TypeRole).toInt())
|
2007-11-03 17:30:52 +03:00
|
|
|
{
|
2008-06-13 19:19:53 +04:00
|
|
|
f |= Qt::ItemIsUserCheckable;
|
2007-11-13 07:54:49 +03:00
|
|
|
}
|
2008-06-13 19:19:53 +04:00
|
|
|
return f;
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
|
|
|
|
2007-11-13 08:17:10 +03:00
|
|
|
QModelIndex QCMakeCacheModel::buddy(const QModelIndex& idx) const
|
2007-11-08 18:17:37 +03:00
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
if(!this->hasChildren(idx) &&
|
2008-06-13 19:19:53 +04:00
|
|
|
this->data(idx, TypeRole).toInt() != QCMakeProperty::BOOL)
|
|
|
|
{
|
|
|
|
return this->index(idx.row(), 1, idx.parent());
|
|
|
|
}
|
2007-11-08 18:17:37 +03:00
|
|
|
return idx;
|
|
|
|
}
|
2007-11-13 07:54:49 +03:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p,
|
2007-11-05 21:20:54 +03:00
|
|
|
const QStyleOptionViewItem&, const QModelIndex& idx) const
|
2007-11-02 18:50:17 +03:00
|
|
|
{
|
2008-06-13 19:19:53 +04:00
|
|
|
QModelIndex var = idx.sibling(idx.row(), 0);
|
|
|
|
int type = var.data(QCMakeCacheModel::TypeRole).toInt();
|
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 =
|
2012-08-13 21:42:58 +04:00
|
|
|
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 =
|
2012-08-13 21:42:58 +04:00
|
|
|
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
|
|
|
}
|
2009-03-12 18:19:27 +03:00
|
|
|
else if(type == QCMakeProperty::STRING &&
|
|
|
|
var.data(QCMakeCacheModel::StringsRole).isValid())
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
QCMakeComboBox* editor =
|
2009-03-12 18:19:27 +03:00
|
|
|
new QCMakeComboBox(p, var.data(QCMakeCacheModel::StringsRole).toStringList());
|
|
|
|
editor->setFrame(false);
|
|
|
|
return editor;
|
|
|
|
}
|
2007-11-02 18:50:17 +03:00
|
|
|
|
2009-03-12 18:19:27 +03:00
|
|
|
QLineEdit* editor = new QLineEdit(p);
|
|
|
|
editor->setFrame(false);
|
|
|
|
return editor;
|
2007-11-02 18:50:17 +03:00
|
|
|
}
|
2009-03-12 18:19:27 +03:00
|
|
|
|
2012-08-13 21:42:58 +04: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;
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
}
|
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;
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
}
|
|
|
|
else
|
2007-11-13 08:17:10 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
|
|
|
|
? Qt::Unchecked : Qt::Checked);
|
2009-07-17 22:38:36 +04:00
|
|
|
bool success = model->setData(index, state, Qt::CheckStateRole);
|
|
|
|
if(success)
|
|
|
|
{
|
|
|
|
this->recordChange(model, index);
|
|
|
|
}
|
|
|
|
return success;
|
2007-11-13 08:17:10 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2009-07-17 22:38:36 +04:00
|
|
|
// Issue 205903 fixed in Qt 4.5.0.
|
|
|
|
// Can remove this function and FileDialogFlag when minimum Qt version is 4.5
|
2009-09-23 21:09:56 +04:00
|
|
|
bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* evt)
|
2008-04-02 23:28:17 +04:00
|
|
|
{
|
|
|
|
// workaround for what looks like a bug in Qt on Mac OS X
|
2008-06-10 08:17:00 +04:00
|
|
|
// 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
|
2009-07-17 22:38:36 +04:00
|
|
|
|
2009-09-23 21:09:56 +04:00
|
|
|
if(evt->type() == QEvent::FocusOut && this->FileDialogFlag)
|
2008-06-10 08:17:00 +04:00
|
|
|
{
|
2008-04-02 23:28:17 +04:00
|
|
|
return false;
|
2008-06-10 08:17:00 +04:00
|
|
|
}
|
2009-09-23 21:09:56 +04:00
|
|
|
return QItemDelegate::eventFilter(object, evt);
|
2008-04-02 23:28:17 +04:00
|
|
|
}
|
|
|
|
|
2009-07-17 22:38:36 +04:00
|
|
|
void QCMakeCacheModelDelegate::setModelData(QWidget* editor,
|
|
|
|
QAbstractItemModel* model, const QModelIndex& index ) const
|
|
|
|
{
|
|
|
|
QItemDelegate::setModelData(editor, model, index);
|
|
|
|
const_cast<QCMakeCacheModelDelegate*>(this)->recordChange(model, index);
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2009-08-10 21:25:22 +04:00
|
|
|
QSize QCMakeCacheModelDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
QSize sz = QItemDelegate::sizeHint(option, index);
|
|
|
|
QStyle *style = QApplication::style();
|
|
|
|
|
|
|
|
// increase to checkbox size
|
|
|
|
QStyleOptionButton opt;
|
|
|
|
opt.QStyleOption::operator=(option);
|
|
|
|
sz = sz.expandedTo(style->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, NULL).size());
|
|
|
|
|
|
|
|
return sz;
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2009-07-17 22:38:36 +04:00
|
|
|
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())
|
|
|
|
{
|
2009-09-23 21:09:56 +04:00
|
|
|
QCMakeProperty prop;
|
2009-07-17 22:38:36 +04:00
|
|
|
idx = idx.sibling(idx.row(), 0);
|
2009-09-23 21:09:56 +04:00
|
|
|
cache_model->getPropertyData(idx, prop);
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2009-07-17 22:38:36 +04:00
|
|
|
// clean out an old one
|
2009-09-23 21:09:56 +04:00
|
|
|
QSet<QCMakeProperty>::iterator iter = mChanges.find(prop);
|
2009-07-17 22:38:36 +04:00
|
|
|
if(iter != mChanges.end())
|
|
|
|
{
|
|
|
|
mChanges.erase(iter);
|
|
|
|
}
|
|
|
|
// now add the new item
|
2009-09-23 21:09:56 +04:00
|
|
|
mChanges.insert(prop);
|
2009-07-17 22:38:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|