Skip to content
Snippets Groups Projects
Commit 9e97d2c3 authored by Lars Bilke's avatar Lars Bilke
Browse files

Filecompares should be working again

git-svn-id: https://svn.ufz.de/svn/ogs/trunk/sources@7043 3895a583-e809-0410-9bb6-aa9463026377
parents
No related branches found
No related tags found
No related merge requests found
Showing
with 1831 additions and 0 deletions
# Source files
set( SOURCES
OGSError.cpp
QNonScalableGraphicsTextItem.cpp
RecentFiles.cpp
TreeItem.cpp
TreeModel.cpp
ColorPickerPushButton.cpp
TreeModelIterator.cpp
modeltest.cpp
CheckboxDelegate.cpp
)
# Moc headers
set( MOC_HEADERS
RecentFiles.h
TreeModel.h
ColorPickerPushButton.h
modeltest.h
CheckboxDelegate.h
)
# Header files
set( HEADERS
OGSError.h
QNonScalableGraphicsTextItem.h
TreeItem.h
TreeModelIterator.h
)
# UI files
set ( UIS
)
# Put moc files in a project folder
source_group("UI Files" REGULAR_EXPRESSION "\\w*\\.ui")
source_group("Moc Files" REGULAR_EXPRESSION "moc_.*")
# Run Qts user interface compiler uic on .ui files
qt4_wrap_ui( UI_HEADERS ${UIS} )
# Run Qts meta object compiler moc on header files
qt4_wrap_cpp( MOC_SOURCES ${MOC_HEADERS} )
# Create the library
add_library( QtBase STATIC
${SOURCES}
${HEADERS}
${MOC_HEADERS}
${MOC_SOURCES}
${UIS}
)
target_link_libraries( QtBase ${QT_LIBRARIES} )
/**
* \file CheckboxDelegate.cpp
* 19/08/2010 LB Initial implementation
*
* Implementation of CheckboxDelegate class
*/
// ** INCLUDES **
#include "CheckboxDelegate.h"
#include <QCheckBox>
#include <QPainter>
#include <QEvent>
#include <QApplication>
#include <QStyleOptionButton>
#include <QMouseEvent>
#include <iostream>
CheckboxDelegate::CheckboxDelegate(QObject* parent)
: QItemDelegate(parent)
{
}
void CheckboxDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
if(index.isValid())
{
bool checked = index.model()->data(index, Qt::DisplayRole).toBool();
QStyleOptionButton styleOptionButton;
styleOptionButton.state |= QStyle::State_Enabled;
if (checked)
styleOptionButton.state |= QStyle::State_On;
else
styleOptionButton.state |= QStyle::State_Off;
styleOptionButton.rect = this->checkboxRect(option);
QApplication::style()->drawControl(QStyle::CE_CheckBox,
&styleOptionButton, painter);
}
else
QItemDelegate::paint(painter, option, index);
}
bool CheckboxDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
const QStyleOptionViewItem &option, const QModelIndex &index)
{
Q_UNUSED(option);
if ((event->type() == QEvent::MouseButtonRelease) ||
(event->type() == QEvent::MouseButtonDblClick))
{
QMouseEvent *mouse_event = static_cast<QMouseEvent*>(event);
if (mouse_event->button() != Qt::LeftButton ||
!checkboxRect(option).contains(mouse_event->pos()))
return false;
if (event->type() == QEvent::MouseButtonDblClick)
return true;
}
else if (event->type() == QEvent::KeyPress)
{
if (static_cast<QKeyEvent*>(event)->key() != Qt::Key_Space &&
static_cast<QKeyEvent*>(event)->key() != Qt::Key_Select)
return false;
}
else
return false;
bool checked = index.model()->data(index, Qt::DisplayRole).toBool();
return model->setData(index, !checked, Qt::EditRole);
}
QSize CheckboxDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
{
Q_UNUSED(index);
QRect rect = checkboxRect(option);
return QSize(rect.width(), rect.height());
}
QRect CheckboxDelegate::checkboxRect(const QStyleOptionViewItem& viewItemStyleOptions) const
{
QStyleOptionButton styleOptionButton;
QRect rect = QApplication::style()->subElementRect(
QStyle::SE_CheckBoxIndicator, &styleOptionButton);
QPoint point(viewItemStyleOptions.rect.x() +
viewItemStyleOptions.rect.width() / 2 - rect.width() / 2,
viewItemStyleOptions.rect.y() + viewItemStyleOptions.rect.height() / 2 -
rect.height() / 2);
return QRect(point, rect.size());
}
/**
* \file CheckboxDelegate.h
* 19/08/2010 LB Initial implementation
*/
#ifndef CHECKBOXDELEGATE_H
#define CHECKBOXDELEGATE_H
#include <QItemDelegate>
class QWidget;
class QRect;
/**
* \brief CheckboxDelegate modifies a model view to display boolean values as checkboxes.
* Important: the column on which this delegate is set (
* QAbstractItemView::setItemDelegateForColumn()) must not have the flags
* Qt::ItemIsEditable or Qt::ItemIsUserCheckable set in the model.
**/
class CheckboxDelegate : public QItemDelegate
{
Q_OBJECT
public:
/// \brief Constructor
CheckboxDelegate (QObject* parent = 0);
/// \brief Paints a checkbox. This overrides the default painting of a combo box.
void paint(QPainter* painter, const QStyleOptionViewItem& option,
const QModelIndex& index) const;
/// \brief Handles the click events and sets the model data.
bool editorEvent(QEvent *event, QAbstractItemModel *model,
const QStyleOptionViewItem &option, const QModelIndex &index);
QSize sizeHint (const QStyleOptionViewItem & option, const QModelIndex & index) const;
private:
QRect checkboxRect(const QStyleOptionViewItem& viewItemStyleOptions) const;
};
#endif // CHECKBOXDELEGATE_H
/**
* \file ColorPickerPushButton.cpp
* 17/5/2010 LB Initial implementation
*
* Implementation of ColorPickerPushButton
*/
// ** INCLUDES **
#include "ColorPickerPushButton.h"
#include <QColorDialog>
ColorPickerPushButton::ColorPickerPushButton( QWidget* parent /*= 0*/ )
: QPushButton(parent)
{
setAutoFillBackground(true);
_color = QColor("white");
}
void ColorPickerPushButton::mouseReleaseEvent(QMouseEvent* e)
{
Q_UNUSED(e);
QColor newColor = QColorDialog::getColor(_color, NULL, "Choose a color");
if (!newColor.isValid())
return;
setColor(newColor);
emit colorPicked(_color);
}
QString ColorPickerPushButton::colorToCss( QColor color )
{
QString colorStr = "rgb";
colorStr.append(colorToString(color));
return colorStr;
}
QString ColorPickerPushButton::colorToString( QColor color )
{
QString colorStr = "(";
colorStr.append(QString::number(color.red()));
colorStr.append(", ");
colorStr.append(QString::number(color.green()));
colorStr.append(", ");
colorStr.append(QString::number(color.blue()));
colorStr.append(")");
return colorStr;
}
void ColorPickerPushButton::setColor( QColor color )
{
_color = color;
// Compute text color
QColor hsv = _color.toHsv();
QString textColorStr;
if (hsv.valueF() < 0.5f)
textColorStr = "color: rgb(255, 255, 255);";
else
textColorStr = "color: rgb(0, 0, 0);";
QString stylesheetStr = "background-color: ";
stylesheetStr.append(colorToCss(_color));
stylesheetStr.append(";");
stylesheetStr.append(textColorStr);
this->setStyleSheet(stylesheetStr);
this->setText(colorToString(_color));
}
void ColorPickerPushButton::setColor( double* color )
{
return setColor(QColor::fromRgbF(color[0], color[1], color[2]));
}
/**
* \file ColorPickerPushButton.h
* 17/5/2010 LB Initial implementation
*
*/
#ifndef COLORPICKERPUSHBUTTON_H
#define COLORPICKERPUSHBUTTON_H
// ** INCLUDES **
#include <QPushButton>
class QColor;
class QMouseEvent;
/**
* ColorPickerPushButton calls a QColorDialog on clicking and then sends a
* colorPicked(QColor) signal. It also saves the last color and sets its
* background color accordingly.
*/
class ColorPickerPushButton : public QPushButton
{
Q_OBJECT
public:
ColorPickerPushButton(QWidget* parent = 0);
public slots:
/// Calls the QColorDialog
void mouseReleaseEvent(QMouseEvent* e);
/// Sets the color.
void setColor(QColor color);
void setColor(double* color);
private:
QString colorToCss(QColor color);
QString colorToString(QColor color);
QColor _color;
signals:
/// Is emitted when a color was picked from the dialog.
void colorPicked(QColor);
};
#endif // COLORPICKERPUSHBUTTON_H
/**
* \file OGSError.cpp
* KR Initial implementation
*/
#include "OGSError.h"
#include <QMessageBox>
#include <QString>
OGSError::OGSError()
{}
OGSError::~OGSError()
{}
/**
* Displays an error in a QMessageBox
* \param e The error message.
*/
void OGSError::box(QString e)
{
box(e, "OpenGeoSys");
}
/**
* Displays an error in a QMessageBox
* \param e The error message.
* \param t The title of the message box
* \sa QMessageBox
*/
void OGSError::box(QString e, QString t)
{
QMessageBox msgBox;
msgBox.setWindowTitle(t);
msgBox.setText(e);
msgBox.exec();
}
/**
* \file OGSError.h
* KR Initial implementation
*/
#ifndef OGSERROR_H
#define OGSERROR_H
class QString;
/**
* \brief Manages error messages via message boxes
*/
class OGSError
{
public:
static void box(QString e);
static void box(QString e, QString t);
protected:
OGSError();
~OGSError();
};
#endif //OGSERROR_H
/**
* \file QNonScalableGraphicsTextItem.cpp
* KR Initial implementation
*/
#include <QPainter>
#include "QNonScalableGraphicsTextItem.h"
/// Constructor using a QGraphicsTextItem.
QNonScalableGraphicsTextItem::QNonScalableGraphicsTextItem(QGraphicsItem* parent) : QGraphicsTextItem(parent)
{
setAcceptDrops(true);
setAcceptHoverEvents(true);
setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
}
/// Constructor using a QString.
QNonScalableGraphicsTextItem::QNonScalableGraphicsTextItem(const QString & text, QGraphicsItem * parent) :
QGraphicsTextItem(parent)
{
if (!text.isEmpty())
setPlainText(text);
setAcceptDrops(true);
setAcceptHoverEvents(true);
setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
}
QNonScalableGraphicsTextItem::~QNonScalableGraphicsTextItem()
{
}
/// Paints the text item.
void QNonScalableGraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
//painter->drawRect(boundingRect());
QRectF rect = boundingRect();
painter->translate(-rect.width()/2, -rect.height()/2);
QGraphicsTextItem::paint(painter, option, widget);
}
/// Returns the bounding rectangle of the text item.
QRectF QNonScalableGraphicsTextItem::boundingRect()
{
QRectF rect = QGraphicsTextItem::boundingRect();
return QRectF(rect.x()-rect.width()/2, rect.y()-rect.height()/2,rect.width(), rect.height());
}
/**
* \file QNonScalableGraphicsTextItem.h
* KR Initial implementation
*/
#ifndef QNONSCALABLETEXTITEM_H
#define QNONSCALABLETEXTITEM_H
#include <QGraphicsTextItem>
/**
* \brief A QGraphicsTextItem that will ignore all geometric transformations.
*
* A QGraphicsTextItem that will ignore all geometric transformations to the underlying QGraphicsView/QGraphicsScene (in particular, it will not be scaled).
*/
class QNonScalableGraphicsTextItem : public QGraphicsTextItem
{
public:
QNonScalableGraphicsTextItem(QGraphicsItem* parent = 0);
QNonScalableGraphicsTextItem(const QString &text, QGraphicsItem * parent = 0);
~QNonScalableGraphicsTextItem();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QRectF boundingRect();
};
#endif //QNONSCALABLETEXTITEM_H
/**
* \file RecentFiles.cpp
* 5/11/2009 LB Initial implementation
*
* Implementation of RecentFiles
*/
// ** INCLUDES **
#include "RecentFiles.h"
#include <QSettings>
#include <QFileInfo>
RecentFiles::RecentFiles( QObject* parent, const char* slot,
QString settingsName, QString programName )
: QObject(parent), _settingsName(settingsName), _programName(programName)
{
_filesMenu = new QMenu(tr("Recent files"));
for (int i = 0; i < _maxFiles; i++)
{
_fileActions[i] = new QAction(this);
_fileActions[i]->setVisible(false);
connect(_fileActions[i], SIGNAL(triggered()), parent, slot);
_filesMenu->addAction(_fileActions[i]);
}
updateRecentFileActions();
}
QMenu* RecentFiles::menu()
{
return _filesMenu;
}
void RecentFiles::setCurrentFile( const QString& filename )
{
_currentFile = filename;
QSettings settings("UFZ", _programName);
QStringList files = settings.value(_settingsName).toStringList();
files.removeAll(filename);
files.prepend(filename);
while (files.size() > _maxFiles)
files.removeLast();
settings.setValue("recentFileList", files);
updateRecentFileActions();
}
void RecentFiles::updateRecentFileActions()
{
QSettings settings("UFZ", _programName);
QStringList files = settings.value(_settingsName).toStringList();
int numFiles = qMin(files.size(), (int)_maxFiles);
for (int i = 0; i < numFiles; ++i)
{
QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i]));
_fileActions[i]->setText(text);
_fileActions[i]->setData(files[i]);
_fileActions[i]->setVisible(true);
}
for (int i = numFiles; i < _maxFiles; ++i)
_fileActions[i]->setVisible(false);
}
QString RecentFiles::strippedName( const QString& fullFileName )
{
return QFileInfo(fullFileName).fileName();
}
/**
* \file RecentFiles.h
* 5/11/2009 LB Initial implementation
*
*/
#ifndef RECENTFILES_H
#define RECENTFILES_H
// ** INCLUDES **
#include <QObject>
#include <QMenu>
#include <QAction>
class QString;
/**
* The RecentFiles class provides functionality to store informations about
* recently used files (e.g. loaded or saved files).
* Example Usage:
* \code RecentFiles* recentFiles = new RecentFiles(this, SLOT(openRecentFile()), "recentFileList", "OpenGeoSys-5");
* connect(this, SIGNAL(fileUsed(QString)), recentFiles, SLOT(setCurrentFile(QString)));
* menu_File->addMenu( recentFiles->menu() ); \endcode
* with:
* \code void MainWindow::openRecentFile()
* {
* QAction* action = qobject_cast<QAction*>(sender());
* if (action)
* loadFile(action->data().toString());
* } \endcode
*/
class RecentFiles : public QObject
{
Q_OBJECT
public:
/**
* Constructor. Example Usage:
* \code RecentFiles recentFiles = new RecentFiles(this, SLOT(mySlot(QString)), "recentFileList"); \endcode
* \param parent The parent object. Normally the QMainWindow instance
* \param slot A slot on parent which is called when a recent file is clicked.
* Use this with Qts SLOT() macro!
* \param settingsName The setting key
* \param programName The name of the program. QSettings of one program
* should be stored with the same keys: QSettings("UFZ", programName)
*/
RecentFiles(QObject* parent, const char* slot, QString settingsName, QString programName);
/// Returns the created menu. Add this menu to your QMainWindow menu.
QMenu* menu();
public slots:
/// Should be called from the application when a file was used.
void setCurrentFile(const QString& filename);
private:
/// Updates the recent files list and writes it to the settings.
void updateRecentFileActions();
/// Returns the filename from a full file path.
QString strippedName(const QString& fullFileName);
QMenu* _filesMenu;
QString _currentFile;
QString _settingsName;
QString _programName;
enum { _maxFiles = 5 };
QAction* _fileActions[_maxFiles];
};
#endif // RECENTFILES_H
/**
* \file TreeItem.cpp
* KR Initial implementation
*/
#include "TreeItem.h"
/**
* The constructor is only used to record the item's parent
* and the data associated with each column.
*/
TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
{
_parentItem = parent;
_itemData = data;
}
/**
* A pointer to each of the child items belonging to this item
* will be stored in the _childItems private member variable. When
* the class's destructor is called, it must delete each of these
* to ensure that their memory is reused.
*/
TreeItem::~TreeItem()
{
qDeleteAll(_childItems);
}
/**
* Add a child to the tree item
*/
void TreeItem::appendChild(TreeItem *item)
{
_childItems.append(item);
}
/**
* Returns the child that corresponds to the specified row number
* in the item's list of child items
* Returns NULL if that child does not exist.
*/
TreeItem *TreeItem::child(int row) const
{
if (_childItems.count() > row)
return _childItems.value(row);
else
return NULL;
}
/**
* Returns the number of _childItems
*/
int TreeItem::childCount() const
{
return _childItems.count();
}
/**
* Returns the item's location within its parent's list of items.
*/
int TreeItem::row() const
{
if (_parentItem)
return _parentItem->_childItems.indexOf(const_cast<TreeItem*>(this));
return 0;
}
/**
* Returns the number of columns of data in the item.
*/
int TreeItem::columnCount() const
{
return _itemData.count();
}
/**
* Returns the data from all the columns.
*/
QVariant TreeItem::data(int column) const
{
return _itemData.value(column);
}
/**
* Sets the data at a given column.
*/
bool TreeItem::setData( int column, const QVariant &value )
{
if (column < 0 || column >= _itemData.size())
return false;
_itemData[column] = value;
return true;
}
/**
* Returns the parent object of the tree item.
*/
TreeItem *TreeItem::parentItem() const
{
return _parentItem;
}
/**
* Removes a number of children of the TreeItem starting from the given position.
*/
bool TreeItem::removeChildren(int position, int count)
{
if (position < 0 || position + count > _childItems.size())
return false;
for (int row = 0; row < count; ++row)
delete _childItems.takeAt(position);
return true;
}
/**
* \file TreeItem.h
* KR Initial implementation
*/
#ifndef QTREEITEM_H
#define QTREEITEM_H
#include <QList>
#include <QVariant>
/**
* \brief Objects nodes for the TreeModel.
*
* The TreeItem class provides simple items that contain several pieces of data,
* and which can provide information about their parent and child items
* \sa TreeModel
*/
class TreeItem
{
public:
TreeItem(const QList<QVariant> &data, TreeItem *parent);
virtual ~TreeItem();
void appendChild(TreeItem *child);
TreeItem* child(int row) const;
virtual int childCount() const;
virtual int columnCount() const;
virtual QVariant data(int column) const;
virtual bool setData(int column, const QVariant &value);
int row() const;
TreeItem* parentItem() const;
bool removeChildren(int position, int count);
private:
QList<TreeItem*> _childItems;
QList<QVariant> _itemData;
TreeItem* _parentItem;
};
#endif //QTREEITEM_H
/**
* \file TreeModel.cpp
* KR Initial implementation
*/
#include "TreeModel.h"
#include "TreeItem.h"
#include <QStringList>
#include <QVariant>
#include <QModelIndex>
/**
* A model for the QTreeView implementing the tree as a double-linked list.
*/
TreeModel::TreeModel( QObject *parent )
: QAbstractItemModel(parent)
{
//_modelType = TREE_MODEL;
QList<QVariant> rootData;
rootData << "1" << "2" << "3";
_rootItem = new TreeItem(rootData, NULL);
//setupModelData(data, _rootItem);
}
TreeModel::~TreeModel()
{
delete _rootItem;
}
/**
* Returns the index of a TreeItem given its parent and position.
* It is first checked if the model index is valid. If it is not, it is assumed that a
* top-level item is being referred to; otherwise, the data pointer from the model
* index is obtained with its internalPointer() function and is used to reference a
* TreeItem object
* \param row Row of the tree object
* \param column Column of the tree object
* \param parent Index of the parent object
*/
QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
TreeItem *parentItem;
if (!parent.isValid())
parentItem = _rootItem;
else
parentItem = static_cast<TreeItem*>(parent.internalPointer());
TreeItem *childItem = parentItem->child(row);
if (childItem)
return createIndex(row, column, childItem);
else
return QModelIndex();
}
/**
* Returns the model index of a TreeItem based on its index.
*/
QModelIndex TreeModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
TreeItem *parentItem = childItem->parentItem();
if (parentItem == _rootItem)
return QModelIndex();
return createIndex(parentItem->row(), 0, parentItem);
}
/**
* Returns the number of child items for the TreeItem that corresponds to a given
* model index, or the number of top-level items if an invalid index is specified.
*/
int TreeModel::rowCount(const QModelIndex &parent) const
{
TreeItem *parentItem;
if (parent.column() > 0)
return 0;
if (!parent.isValid())
parentItem = _rootItem;
else
parentItem = static_cast<TreeItem*>(parent.internalPointer());
return parentItem->childCount();
}
/**
* Determines how many columns are present for a given model index.
*/
int TreeModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
else
return _rootItem->columnCount();
}
void TreeModel::updateData()
{
}
/**
* Since each item manages its own columns, the column number is used to retrieve
* the data with the TreeItem::data() function
*/
QVariant TreeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::EditRole || role == Qt::DisplayRole)
{
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
return item->data(index.column());
}
return QVariant();
}
bool TreeModel::setData( const QModelIndex &index, const QVariant &value, int role /* = Qt::EditRole */ )
{
if (!index.isValid())
return false;
if (role == Qt::EditRole)
{
TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
item->setData(index.column(), value);
return true;
}
return false;
}
Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
/**
* Returns the Item characterized by the given index.
*/
TreeItem* TreeModel::getItem(const QModelIndex &index) const
{
if (index.isValid()) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if (item) return item;
}
return _rootItem;
}
QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return _rootItem->data(section);
return QVariant();
}
/**
* Removes item from the model.
*/
bool TreeModel::removeRows(int position, int count, const QModelIndex & parent)
{
TreeItem *parentItem = getItem(parent);
bool success = true;
beginRemoveRows(parent, position, position + count - 1);
success = parentItem->removeChildren(position, count);
endRemoveRows();
return success;
}
/**
* Test method for creating a tree model
*/
void TreeModel::setupModelData(const QStringList &lines, TreeItem *parent)
{
QList<TreeItem*> parents;
QList<int> indentations;
parents << parent;
indentations << 0;
int number = 0;
while (number < lines.count()) {
int position = 0;
while (position < lines[number].length()) {
if (lines[number].mid(position, 1) != " ")
break;
position++;
}
QString lineData = lines[number].mid(position).trimmed();
if (!lineData.isEmpty()) {
// Read the column data from the rest of the line.
QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts);
QList<QVariant> columnData;
for (int column = 0; column < columnStrings.count(); ++column)
columnData << columnStrings[column];
if (position > indentations.last()) {
// The last child of the current parent is now the new parent
// unless the current parent has no children.
if (parents.last()->childCount() > 0) {
parents << parents.last()->child(parents.last()->childCount()-1);
indentations << position;
}
} else {
while (position < indentations.last() && parents.count() > 0) {
parents.pop_back();
indentations.pop_back();
}
}
// Append a new item to the current parent's list of children.
parents.last()->appendChild(new TreeItem(columnData, parents.last()));
}
number++;
}
}
TreeItem* TreeModel::rootItem() const
{
return _rootItem;
}
/**
* \file TreeModel.cpp
* KR Initial implementation
*/
#ifndef QTREEMODEL_H
#define QTREEMODEL_H
#include <QAbstractItemModel>
class QVariant;
class QModelIndex;
class TreeItem;
/**
* \brief A hierarchical model for a tree implemented as a double-linked list
*
* A hierarchical model for the pre-defined QTreeView included in QT. The tree as implemented
* as a double-linked list.
*/
class TreeModel : public QAbstractItemModel
{
Q_OBJECT
public:
TreeModel(QObject* parent = 0);
virtual ~TreeModel();
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role /* = Qt::EditRole */);
Qt::ItemFlags flags(const QModelIndex &index) const;
TreeItem* getItem(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
bool removeRows(int row, int count, const QModelIndex & parent);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
TreeItem* rootItem() const;
public slots:
void updateData();
protected:
TreeItem* _rootItem;
private:
void setupModelData(const QStringList &lines, TreeItem *parent);
};
#endif //QTREEMODEL_H
/**
* \file TreeModelIterator.cpp
* 23/6/2010 LB Initial implementation
*
* Implementation of TreeModelIterator
*/
// ** INCLUDES **
#include "TreeModelIterator.h"
#include "TreeItem.h"
#include "TreeModel.h"
TreeModelIterator::TreeModelIterator( TreeModel* model )
: _current(NULL), _model(model)
{
if (_model->rootItem()->childCount() > 0)
{
_current = _model->rootItem();
next(_current);
//_parentIndex.push(0);
//_currentIndex = 0;
}
}
TreeItem* TreeModelIterator::operator*() const
{
return _current;
}
TreeModelIterator& TreeModelIterator::operator++()
{
if (_current)
{
_current = next(_current);
}
return *this;
}
TreeItem* TreeModelIterator::next( const TreeItem* current )
{
if (!current)
return NULL;
TreeItem* next = NULL;
if (current->childCount())
{
// walk the child
_parentIndex.push(_currentIndex);
_currentIndex = 0;
next = current->child(0);
}
else
{
// walk the sibling
TreeItem* parent = current->parentItem();
next = parent ? parent->child(_currentIndex + 1)
: _model->rootItem()->child(_currentIndex + 1);
while (!next && parent)
{
// if we had no sibling walk up the parent
// and try the sibling of that
parent = parent->parentItem();
_currentIndex = _parentIndex.pop();
next = parent ? parent->child(_currentIndex + 1)
: _model->rootItem()->child(_currentIndex + 1);
}
if (next)
++(_currentIndex);
}
return next;
}
/**
* \file TreeModelIterator.h
* 23/6/2010 LB Initial implementation
*
*/
#ifndef TREEMODELITERATOR_H
#define TREEMODELITERATOR_H
// ** INCLUDES **
#include <QStack>
class TreeModel;
class TreeItem;
/**
* \brief TreeModelIterator provides a way to iterate over TreeItems in a TreeModel.
* Usage: \code
* TreeModelIterator it(model);
* while(*it)
* {
* QVariant var = (*it)->data(0);
* std::cout << var.toString().toStdString() << std::endl;
* ++it;
* } \endcode
*/
class TreeModelIterator
{
public:
/// \brief Constructor. Provide a tree model to iterate over.
TreeModelIterator(TreeModel* model);
/// \brief Dereferencing the iterator to retrieve the current TreeItem.
/// Returns NULL if the iterator is at the end.
TreeItem* operator* () const;
/// \brief Advance the iterator to the next TreeItem.
TreeModelIterator& operator++ ();
private:
/// \brief The current TreeItem.
TreeItem* _current;
/// \brief The current child index.
int _currentIndex;
/// \brief Stack to save the child indices of the parent TreeItems.
QStack<int> _parentIndex;
/// \brief The model to iterate over.
TreeModel* _model;
/// \brief The traversal implementation.
TreeItem* next(const TreeItem* current);
};
#endif // TREEMODELITERATOR_H
/****************************************************************************
**
** Copyright (C) 2007 Trolltech ASA. All rights reserved.
**
** This file is part of the Qt Concurrent project on Trolltech Labs.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://www.trolltech.com/products/qt/licensing.html or contact the
** sales department at sales@trolltech.com.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include <QtGui/QtGui>
#include "modeltest.h"
Q_DECLARE_METATYPE(QModelIndex)
/*!
Connect to all of the models signals. Whenever anything happens recheck everything.
*/
ModelTest::ModelTest(QAbstractItemModel *_model, QObject *parent) : QObject(parent), model(_model), fetchingMore(false)
{
Q_ASSERT(model);
connect(model, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)),
this, SLOT(runAllTests()));
connect(model, SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)),
this, SLOT(runAllTests()));
connect(model, SIGNAL(columnsInserted(const QModelIndex &, int, int)),
this, SLOT(runAllTests()));
connect(model, SIGNAL(columnsRemoved(const QModelIndex &, int, int)),
this, SLOT(runAllTests()));
connect(model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
this, SLOT(runAllTests()));
connect(model, SIGNAL(headerDataChanged(Qt::Orientation, int, int)),
this, SLOT(runAllTests()));
connect(model, SIGNAL(layoutAboutToBeChanged ()), this, SLOT(runAllTests()));
connect(model, SIGNAL(layoutChanged ()), this, SLOT(runAllTests()));
connect(model, SIGNAL(modelReset ()), this, SLOT(runAllTests()));
connect(model, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
this, SLOT(runAllTests()));
connect(model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
this, SLOT(runAllTests()));
connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
this, SLOT(runAllTests()));
connect(model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
this, SLOT(runAllTests()));
// Special checks for inserting/removing
connect(model, SIGNAL(layoutAboutToBeChanged()),
this, SLOT(layoutAboutToBeChanged()));
connect(model, SIGNAL(layoutChanged()),
this, SLOT(layoutChanged()));
connect(model, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
this, SLOT(rowsAboutToBeInserted(const QModelIndex &, int, int)));
connect(model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
this, SLOT(rowsAboutToBeRemoved(const QModelIndex &, int, int)));
connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
this, SLOT(rowsInserted(const QModelIndex &, int, int)));
connect(model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
this, SLOT(rowsRemoved(const QModelIndex &, int, int)));
runAllTests();
}
void ModelTest::runAllTests()
{
if (fetchingMore)
return;
nonDestructiveBasicTest();
rowCount();
columnCount();
hasIndex();
index();
parent();
data();
}
/*!
nonDestructiveBasicTest tries to call a number of the basic functions (not all)
to make sure the model doesn't outright segfault, testing the functions that makes sense.
*/
void ModelTest::nonDestructiveBasicTest()
{
Q_ASSERT(model->buddy(QModelIndex()) == QModelIndex());
model->canFetchMore(QModelIndex());
Q_ASSERT(model->columnCount(QModelIndex()) >= 0);
Q_ASSERT(model->data(QModelIndex()) == QVariant());
fetchingMore = true;
model->fetchMore(QModelIndex());
fetchingMore = false;
Qt::ItemFlags flags = model->flags(QModelIndex());
Q_ASSERT(flags == Qt::ItemIsDropEnabled || flags == 0);
model->hasChildren(QModelIndex());
model->hasIndex(0, 0);
model->headerData(0, Qt::Horizontal);
model->index(0, 0);
Q_ASSERT(model->index(-1, -1) == QModelIndex());
model->itemData(QModelIndex());
QVariant cache;
model->match(QModelIndex(), -1, cache);
model->mimeTypes();
Q_ASSERT(model->parent(QModelIndex()) == QModelIndex());
Q_ASSERT(model->rowCount() >= 0);
QVariant variant;
model->setData(QModelIndex(), variant, -1);
model->setHeaderData(-1, Qt::Horizontal, QVariant());
model->setHeaderData(0, Qt::Horizontal, QVariant());
model->setHeaderData(999999, Qt::Horizontal, QVariant());
QMap<int, QVariant> roles;
model->sibling(0, 0, QModelIndex());
model->span(QModelIndex());
model->supportedDropActions();
}
/*!
Tests model's implementation of QAbstractItemModel::rowCount() and hasChildren()
Models that are dynamically populated are not as fully tested here.
*/
void ModelTest::rowCount()
{
// check top row
QModelIndex topIndex = model->index(0, 0, QModelIndex());
int rows = model->rowCount(topIndex);
Q_ASSERT(rows >= 0);
if (rows > 0)
Q_ASSERT(model->hasChildren(topIndex) == true);
QModelIndex secondLevelIndex = model->index(0, 0, topIndex);
if (secondLevelIndex.isValid()) { // not the top level
// check a row count where parent is valid
rows = model->rowCount(secondLevelIndex);
Q_ASSERT(rows >= 0);
if (rows > 0)
Q_ASSERT(model->hasChildren(secondLevelIndex) == true);
}
// The models rowCount() is tested more extensively in checkChildren(),
// but this catches the big mistakes
}
/*!
Tests model's implementation of QAbstractItemModel::columnCount() and hasChildren()
*/
void ModelTest::columnCount()
{
// check top row
QModelIndex topIndex = model->index(0, 0, QModelIndex());
Q_ASSERT(model->columnCount(topIndex) >= 0);
// check a column count where parent is valid
QModelIndex childIndex = model->index(0, 0, topIndex);
if (childIndex.isValid())
Q_ASSERT(model->columnCount(childIndex) >= 0);
// columnCount() is tested more extensively in checkChildren(),
// but this catches the big mistakes
}
/*!
Tests model's implementation of QAbstractItemModel::hasIndex()
*/
void ModelTest::hasIndex()
{
// Make sure that invalid values returns an invalid index
Q_ASSERT(model->hasIndex(-2, -2) == false);
Q_ASSERT(model->hasIndex(-2, 0) == false);
Q_ASSERT(model->hasIndex(0, -2) == false);
int rows = model->rowCount();
int columns = model->columnCount();
// check out of bounds
Q_ASSERT(model->hasIndex(rows, columns) == false);
Q_ASSERT(model->hasIndex(rows + 1, columns + 1) == false);
if (rows > 0)
Q_ASSERT(model->hasIndex(0, 0) == true);
// hasIndex() is tested more extensively in checkChildren(),
// but this catches the big mistakes
}
/*!
Tests model's implementation of QAbstractItemModel::index()
*/
void ModelTest::index()
{
// Make sure that invalid values returns an invalid index
Q_ASSERT(model->index(-2, -2) == QModelIndex());
Q_ASSERT(model->index(-2, 0) == QModelIndex());
Q_ASSERT(model->index(0, -2) == QModelIndex());
int rows = model->rowCount();
int columns = model->columnCount();
if (rows == 0)
return;
// Catch off by one errors
Q_ASSERT(model->index(rows, columns) == QModelIndex());
Q_ASSERT(model->index(0, 0).isValid() == true);
// Make sure that the same index is *always* returned
QModelIndex a = model->index(0, 0);
QModelIndex b = model->index(0, 0);
Q_ASSERT(a == b);
// index() is tested more extensively in checkChildren(),
// but this catches the big mistakes
}
/*!
Tests model's implementation of QAbstractItemModel::parent()
*/
void ModelTest::parent()
{
// Make sure the model wont crash and will return an invalid QModelIndex
// when asked for the parent of an invalid index.
Q_ASSERT(model->parent(QModelIndex()) == QModelIndex());
if (model->rowCount() == 0)
return;
// Column 0 | Column 1 |
// QModelIndex() | |
// \- topIndex | topIndex1 |
// \- childIndex | childIndex1 |
// Common error test #1, make sure that a top level index has a parent
// that is a invalid QModelIndex.
QModelIndex topIndex = model->index(0, 0, QModelIndex());
Q_ASSERT(model->parent(topIndex) == QModelIndex());
// Common error test #2, make sure that a second level index has a parent
// that is the first level index.
if (model->rowCount(topIndex) > 0) {
QModelIndex childIndex = model->index(0, 0, topIndex);
Q_ASSERT(model->parent(childIndex) == topIndex);
}
// Common error test #3, the second column should NOT have the same children
// as the first column in a row.
// Usually the second column shouldn't have children.
QModelIndex topIndex1 = model->index(0, 1, QModelIndex());
if (model->rowCount(topIndex1) > 0) {
QModelIndex childIndex = model->index(0, 0, topIndex);
QModelIndex childIndex1 = model->index(0, 0, topIndex1);
Q_ASSERT(childIndex != childIndex1);
}
// Full test, walk n levels deep through the model making sure that all
// parent's children correctly specify their parent.
checkChildren(QModelIndex());
}
/*!
Called from the parent() test.
A model that returns an index of parent X should also return X when asking
for the parent of the index.
This recursive function does pretty extensive testing on the whole model in an
effort to catch edge cases.
This function assumes that rowCount(), columnCount() and index() already work.
If they have a bug it will point it out, but the above tests should have already
found the basic bugs because it is easier to figure out the problem in
those tests then this one.
*/
void ModelTest::checkChildren(const QModelIndex &parent, int currentDepth)
{
// First just try walking back up the tree.
QModelIndex p = parent;
while (p.isValid())
p = p.parent();
// For models that are dynamically populated
if (model->canFetchMore(parent)) {
fetchingMore = true;
model->fetchMore(parent);
fetchingMore = false;
}
int rows = model->rowCount(parent);
int columns = model->columnCount(parent);
if (rows > 0)
Q_ASSERT(model->hasChildren(parent));
// Some further testing against rows(), columns(), and hasChildren()
Q_ASSERT(rows >= 0);
Q_ASSERT(columns >= 0);
if (rows > 0)
Q_ASSERT(model->hasChildren(parent) == true);
//qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows
// << "columns:" << columns << "parent column:" << parent.column();
Q_ASSERT(model->hasIndex(rows + 1, 0, parent) == false);
for (int r = 0; r < rows; ++r) {
if (model->canFetchMore(parent)) {
fetchingMore = true;
model->fetchMore(parent);
fetchingMore = false;
}
Q_ASSERT(model->hasIndex(r, columns + 1, parent) == false);
for (int c = 0; c < columns; ++c) {
Q_ASSERT(model->hasIndex(r, c, parent) == true);
QModelIndex index = model->index(r, c, parent);
// rowCount() and columnCount() said that it existed...
Q_ASSERT(index.isValid() == true);
// index() should always return the same index when called twice in a row
QModelIndex modifiedIndex = model->index(r, c, parent);
Q_ASSERT(index == modifiedIndex);
// Make sure we get the same index if we request it twice in a row
QModelIndex a = model->index(r, c, parent);
QModelIndex b = model->index(r, c, parent);
Q_ASSERT(a == b);
// Some basic checking on the index that is returned
Q_ASSERT(index.model() == model);
Q_ASSERT(index.row() == r);
Q_ASSERT(index.column() == c);
// While you can technically return a QVariant usually this is a sign
// of an bug in data() Disable if this really is ok in your model.
//Q_ASSERT(model->data(index, Qt::DisplayRole).isValid() == true);
// If the next test fails here is some somewhat useful debug you play with.
/*
if (model->parent(index) != parent) {
qDebug() << r << c << currentDepth << model->data(index).toString()
<< model->data(parent).toString();
qDebug() << index << parent << model->parent(index);
// And a view that you can even use to show the model.
//QTreeView view;
//view.setModel(model);
//view.show();
}*/
// Check that we can get back our real parent.
QModelIndex p = model->parent(index);
//qDebug() << "child:" << index;
//qDebug() << p;
//qDebug() << parent;
Q_ASSERT(model->parent(index) == parent);
// recursively go down the children
if (model->hasChildren(index) && currentDepth < 10 ) {
//qDebug() << r << c << "has children" << model->rowCount(index);
checkChildren(index, ++currentDepth);
}/* else { if (currentDepth >= 10) qDebug() << "checked 10 deep"; };*/
// make sure that after testing the children that the index doesn't change.
QModelIndex newerIndex = model->index(r, c, parent);
Q_ASSERT(index == newerIndex);
}
}
}
/*!
Tests model's implementation of QAbstractItemModel::data()
*/
void ModelTest::data()
{
// Invalid index should return an invalid qvariant
Q_ASSERT(!model->data(QModelIndex()).isValid());
if (model->rowCount() == 0)
return;
// A valid index should have a valid QVariant data
Q_ASSERT(model->index(0, 0).isValid());
// shouldn't be able to set data on an invalid index
Q_ASSERT(model->setData(QModelIndex(), QLatin1String("foo"), Qt::DisplayRole) == false);
// General Purpose roles that should return a QString
QVariant variant = model->data(model->index(0, 0), Qt::ToolTipRole);
if (variant.isValid()) {
Q_ASSERT(qVariantCanConvert<QString>(variant));
}
variant = model->data(model->index(0, 0), Qt::StatusTipRole);
if (variant.isValid()) {
Q_ASSERT(qVariantCanConvert<QString>(variant));
}
variant = model->data(model->index(0, 0), Qt::WhatsThisRole);
if (variant.isValid()) {
Q_ASSERT(qVariantCanConvert<QString>(variant));
}
// General Purpose roles that should return a QSize
variant = model->data(model->index(0, 0), Qt::SizeHintRole);
if (variant.isValid()) {
Q_ASSERT(qVariantCanConvert<QSize>(variant));
}
// General Purpose roles that should return a QFont
QVariant fontVariant = model->data(model->index(0, 0), Qt::FontRole);
if (fontVariant.isValid()) {
Q_ASSERT(qVariantCanConvert<QFont>(fontVariant));
}
// Check that the alignment is one we know about
QVariant textAlignmentVariant = model->data(model->index(0, 0), Qt::TextAlignmentRole);
if (textAlignmentVariant.isValid()) {
int alignment = textAlignmentVariant.toInt();
Q_ASSERT(alignment == Qt::AlignLeft ||
alignment == Qt::AlignRight ||
alignment == Qt::AlignHCenter ||
alignment == Qt::AlignJustify ||
alignment == Qt::AlignTop ||
alignment == Qt::AlignBottom ||
alignment == Qt::AlignVCenter ||
alignment == Qt::AlignCenter ||
alignment == Qt::AlignAbsolute ||
alignment == Qt::AlignLeading ||
alignment == Qt::AlignTrailing);
}
// General Purpose roles that should return a QColor
QVariant colorVariant = model->data(model->index(0, 0), Qt::BackgroundColorRole);
if (colorVariant.isValid()) {
Q_ASSERT(qVariantCanConvert<QColor>(colorVariant));
}
colorVariant = model->data(model->index(0, 0), Qt::TextColorRole);
if (colorVariant.isValid()) {
Q_ASSERT(qVariantCanConvert<QColor>(colorVariant));
}
// Check that the "check state" is one we know about.
QVariant checkStateVariant = model->data(model->index(0, 0), Qt::CheckStateRole);
if (checkStateVariant.isValid()) {
int state = checkStateVariant.toInt();
Q_ASSERT(state == Qt::Unchecked ||
state == Qt::PartiallyChecked ||
state == Qt::Checked);
}
}
/*!
Store what is about to be inserted to make sure it actually happens
\sa rowsInserted()
*/
void ModelTest::rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
{
Q_UNUSED(end);
Changing c;
c.parent = parent;
c.oldSize = model->rowCount(parent);
c.last = model->data(model->index(start - 1, 0, parent));
c.next = model->data(model->index(start, 0, parent));
insert.push(c);
}
/*!
Confirm that what was said was going to happen actually did
\sa rowsAboutToBeInserted()
*/
void ModelTest::rowsInserted(const QModelIndex & parent, int start, int end)
{
Changing c = insert.pop();
Q_ASSERT(c.parent == parent);
Q_ASSERT(c.oldSize + (end - start + 1) == model->rowCount(parent));
Q_ASSERT(c.last == model->data(model->index(start - 1, 0, c.parent)));
/*
if (c.next != model->data(model->index(end + 1, 0, c.parent))) {
qDebug() << start << end;
for (int i=0; i < model->rowCount(); ++i)
qDebug() << model->index(i, 0).data().toString();
qDebug() << c.next << model->data(model->index(end + 1, 0, c.parent));
}
*/
Q_ASSERT(c.next == model->data(model->index(end + 1, 0, c.parent)));
}
void ModelTest::layoutAboutToBeChanged()
{
for (int i = 0; i < qBound(0, model->rowCount(), 100); ++i)
changing.append(QPersistentModelIndex(model->index(i, 0)));
}
void ModelTest::layoutChanged()
{
for (int i = 0; i < changing.count(); ++i) {
QPersistentModelIndex p = changing[i];
Q_ASSERT(p == model->index(p.row(), p.column(), p.parent()));
}
changing.clear();
}
/*!
Store what is about to be inserted to make sure it actually happens
\sa rowsRemoved()
*/
void ModelTest::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
{
Changing c;
c.parent = parent;
c.oldSize = model->rowCount(parent);
c.last = model->data(model->index(start - 1, 0, parent));
c.next = model->data(model->index(end + 1, 0, parent));
remove.push(c);
}
/*!
Confirm that what was said was going to happen actually did
\sa rowsAboutToBeRemoved()
*/
void ModelTest::rowsRemoved(const QModelIndex & parent, int start, int end)
{
Changing c = remove.pop();
Q_ASSERT(c.parent == parent);
Q_ASSERT(c.oldSize - (end - start + 1) == model->rowCount(parent));
Q_ASSERT(c.last == model->data(model->index(start - 1, 0, c.parent)));
Q_ASSERT(c.next == model->data(model->index(start, 0, c.parent)));
}
/****************************************************************************
**
** Copyright (C) 2007 Trolltech ASA. All rights reserved.
**
** This file is part of the Qt Concurrent project on Trolltech Labs.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://www.trolltech.com/products/qt/licensing.html or contact the
** sales department at sales@trolltech.com.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#ifndef MODELTEST_H
#define MODELTEST_H
#include <QtCore/QObject>
#include <QtCore/QAbstractItemModel>
#include <QtCore/QStack>
class ModelTest : public QObject
{
Q_OBJECT
public:
ModelTest(QAbstractItemModel *model, QObject *parent = 0);
private Q_SLOTS:
void nonDestructiveBasicTest();
void rowCount();
void columnCount();
void hasIndex();
void index();
void parent();
void data();
protected Q_SLOTS:
void runAllTests();
void layoutAboutToBeChanged();
void layoutChanged();
void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
void rowsInserted(const QModelIndex & parent, int start, int end);
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
void rowsRemoved(const QModelIndex & parent, int start, int end);
private:
void checkChildren(const QModelIndex &parent, int currentDepth = 0);
QAbstractItemModel *model;
struct Changing
{
QModelIndex parent;
int oldSize;
QVariant last;
QVariant next;
};
QStack<Changing> insert;
QStack<Changing> remove;
bool fetchingMore;
QList<QPersistentModelIndex> changing;
};
#endif
# Visual Studio settings
IF (MSVC)
ADD_DEFINITIONS(
-D/MP # For multicore compiling
)
ENDIF (MSVC)
# Find VTK
FIND_PACKAGE( VTK REQUIRED )
INCLUDE( ${VTK_USE_FILE} )
# Find libgeotiff
FIND_PACKAGE( LibTiff REQUIRED )
FIND_PACKAGE( LibGeoTiff REQUIRED )
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /ZI /Od /Ob0")
# Add subprojects
ADD_SUBDIRECTORY( Base )
ADD_SUBDIRECTORY( DataView )
ADD_SUBDIRECTORY( StationView )
ADD_SUBDIRECTORY( StationView/DiagramView )
ADD_SUBDIRECTORY( StationView/StratView )
ADD_SUBDIRECTORY( VtkVis )
ADD_SUBDIRECTORY( VtkAct )
IF (OGS_USE_OPENSG)
ADD_SUBDIRECTORY( OpenSG )
ENDIF (OGS_USE_OPENSG)
IF(VRPN_FOUND)
ADD_SUBDIRECTORY( Vrpn )
ENDIF()
ADD_SUBDIRECTORY( Gui )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment