#include "CameraDataBaseModel.h"
#include <QtGui>
cameraDataBaseModel
::cameraDataBaseModel(QWidget *parent,CCameraDataBase
* cameraDataBase
){
this->camDataBase = cameraDataBase;
this->cameraModel->setDynamicSortFilter(true);
this->cameraView->setRootIsDecorated(false);
this->cameraView->setAlternatingRowColors(true);
this->cameraView->setModel(cameraModel);
this->cameraView->setSortingEnabled(true);
this->setSourceModel(setupModel());
this->cameraView->hideColumn(4);
this
->sortCaseSensitivityCheckBox
= new QCheckBox(tr
("Case sensitive sorting"));
this
->filterCaseSensitivityCheckBox
= new QCheckBox(tr
("Case sensitive filter"));
this
->filterPatternLabel
= new QLabel(tr
("&Filter pattern:"));
this->filterPatternLabel->setBuddy(filterPatternLineEdit);
this
->filterSyntaxComboBox
->addItem
(tr
("Regular expression"),
QRegExp::RegExp);
this
->filterSyntaxComboBox
->addItem
(tr
("Wildcard"),
QRegExp::Wildcard);
this
->filterSyntaxComboBox
->addItem
(tr
("Fixed string"),
QRegExp::FixedString);
this
->filterSyntaxLabel
= new QLabel(tr
("Filter &syntax:"));
this->filterSyntaxLabel->setBuddy(filterSyntaxComboBox);
this->filterColumnComboBox->addItem(tr("Camera Model"));
this->filterColumnComboBox->addItem(tr("Focal Length"));
this->filterColumnComboBox->addItem(tr("Image Width"));
this->filterColumnComboBox->addItem(tr("Image Height"));
this
->filterColumnLabel
= new QLabel(tr
("Filter &column:"));
this->filterColumnLabel->setBuddy(filterColumnComboBox);
connect(filterPatternLineEdit,
SIGNAL(textChanged
(const QString &)),
this, SLOT(filterRegExpChanged()));
connect(filterSyntaxComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(filterRegExpChanged()));
connect(filterColumnComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(filterColumnChanged()));
connect(filterCaseSensitivityCheckBox, SIGNAL(toggled(bool)),
this, SLOT(filterRegExpChanged()));
connect(sortCaseSensitivityCheckBox, SIGNAL(toggled(bool)),
this, SLOT(sortChanged()));
connect(this->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(this->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
cameraLayout->addWidget(cameraView, 0, 0, 1, 3);
cameraLayout->addWidget(filterPatternLabel, 1, 0);
cameraLayout->addWidget(filterPatternLineEdit, 1, 1, 1, 2);
cameraLayout->addWidget(filterSyntaxLabel, 2, 0);
cameraLayout->addWidget(filterSyntaxComboBox, 2, 1, 1, 2);
cameraLayout->addWidget(filterColumnLabel, 3, 0);
cameraLayout->addWidget(filterColumnComboBox, 3, 1, 1, 2);
cameraLayout->addWidget(filterCaseSensitivityCheckBox, 4, 0, 1, 2);
cameraLayout->addWidget(sortCaseSensitivityCheckBox, 4, 2);
cameraLayout->addWidget(buttonBox,5,2);
setLayout(cameraLayout);
setWindowTitle(tr("Select Camera"));
resize(450, 400);
this->cameraView->sortByColumn(2, Qt::AscendingOrder);
this->filterColumnComboBox->setCurrentIndex(0);
this->filterPatternLineEdit->setText("");
this->filterCaseSensitivityCheckBox->setChecked(false);
this->sortCaseSensitivityCheckBox->setChecked(false);
}
cameraDataBaseModel::~cameraDataBaseModel()
{
}
{
cameraModel->setSourceModel(model);
}
void cameraDataBaseModel::filterRegExpChanged()
{
QRegExp::PatternSyntax(filterSyntaxComboBox
->itemData
( filterSyntaxComboBox->currentIndex()).toInt());
Qt::CaseSensitivity caseSensitivity =
filterCaseSensitivityCheckBox->isChecked() ? Qt::CaseSensitive
: Qt::CaseInsensitive;
QRegExp regExp
(filterPatternLineEdit
->text
(), caseSensitivity, syntax
);
cameraModel->setFilterRegExp(regExp);
}
void cameraDataBaseModel::filterColumnChanged()
{
cameraModel->setFilterKeyColumn(filterColumnComboBox->currentIndex());
}
void cameraDataBaseModel::sortChanged()
{
cameraModel->setSortCaseSensitivity(
sortCaseSensitivityCheckBox->isChecked() ? Qt::CaseSensitive
: Qt::CaseInsensitive);
}
const double &FocalLength,const int &ImageWidth, const int &ImageHeight, const int &cameraID)
{
model->insertRow(0);
model->setData(model->index(0, 0), cameraModel);
model->setData(model->index(0, 1), FocalLength);
model->setData(model->index(0, 2), ImageWidth);
model->setData(model->index(0, 3), ImageHeight);
model->setData(model->index(0, 4), cameraID);
}
{
model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("Camera Model"));
model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Focal Length"));
model
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("Image Width"));
model
->setHeaderData
(3, Qt
::Horizontal,
QObject::tr("Image Height"));
model
->setHeaderData
(4, Qt
::Horizontal,
QObject::tr("Camera ID"));
for (int i =0; i < this->camDataBase->globalCameras.GetSize(); i++)
{
addCamera
( model,
QString::fromUtf8(this
->camDataBase
->globalCameras.
GetAt(i
)->getMakeAndModel
()),
this->camDataBase->globalCameras.GetAt(i)->getFocalLength(),
this->camDataBase->globalCameras.GetAt(i)->getImageWidth(),
this->camDataBase->globalCameras.GetAt(i)->getImageHeight(), i );
}
return model;
}
void cameraDataBaseModel::accept()
{
//this where i want to grab the selection of the user and find the Camera ID which is the 4th colum of the model
}
#include "CameraDataBaseModel.h"
#include <QtGui>
cameraDataBaseModel::cameraDataBaseModel(QWidget *parent,CCameraDataBase * cameraDataBase)
: QWidget(parent)
{
this->camDataBase = cameraDataBase;
this->cameraModel = new QSortFilterProxyModel;
this->cameraModel->setDynamicSortFilter(true);
this->cameraView = new QTreeView();
this->cameraView->setRootIsDecorated(false);
this->cameraView->setAlternatingRowColors(true);
this->cameraView->setModel(cameraModel);
this->cameraView->setSortingEnabled(true);
this->setSourceModel(setupModel());
this->cameraView->hideColumn(4);
this->sortCaseSensitivityCheckBox = new QCheckBox(tr("Case sensitive sorting"));
this->filterCaseSensitivityCheckBox = new QCheckBox(tr("Case sensitive filter"));
this->filterPatternLineEdit = new QLineEdit;
this->filterPatternLabel = new QLabel(tr("&Filter pattern:"));
this->filterPatternLabel->setBuddy(filterPatternLineEdit);
this->filterSyntaxComboBox = new QComboBox;
this->filterSyntaxComboBox->addItem(tr("Regular expression"), QRegExp::RegExp);
this->filterSyntaxComboBox->addItem(tr("Wildcard"), QRegExp::Wildcard);
this->filterSyntaxComboBox->addItem(tr("Fixed string"), QRegExp::FixedString);
this->filterSyntaxLabel = new QLabel(tr("Filter &syntax:"));
this->filterSyntaxLabel->setBuddy(filterSyntaxComboBox);
this->filterColumnComboBox = new QComboBox;
this->filterColumnComboBox->addItem(tr("Camera Model"));
this->filterColumnComboBox->addItem(tr("Focal Length"));
this->filterColumnComboBox->addItem(tr("Image Width"));
this->filterColumnComboBox->addItem(tr("Image Height"));
this->filterColumnLabel = new QLabel(tr("Filter &column:"));
this->filterColumnLabel->setBuddy(filterColumnComboBox);
this->buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
connect(filterPatternLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(filterRegExpChanged()));
connect(filterSyntaxComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(filterRegExpChanged()));
connect(filterColumnComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(filterColumnChanged()));
connect(filterCaseSensitivityCheckBox, SIGNAL(toggled(bool)),
this, SLOT(filterRegExpChanged()));
connect(sortCaseSensitivityCheckBox, SIGNAL(toggled(bool)),
this, SLOT(sortChanged()));
connect(this->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(this->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
QGridLayout *cameraLayout = new QGridLayout;
cameraLayout->addWidget(cameraView, 0, 0, 1, 3);
cameraLayout->addWidget(filterPatternLabel, 1, 0);
cameraLayout->addWidget(filterPatternLineEdit, 1, 1, 1, 2);
cameraLayout->addWidget(filterSyntaxLabel, 2, 0);
cameraLayout->addWidget(filterSyntaxComboBox, 2, 1, 1, 2);
cameraLayout->addWidget(filterColumnLabel, 3, 0);
cameraLayout->addWidget(filterColumnComboBox, 3, 1, 1, 2);
cameraLayout->addWidget(filterCaseSensitivityCheckBox, 4, 0, 1, 2);
cameraLayout->addWidget(sortCaseSensitivityCheckBox, 4, 2);
cameraLayout->addWidget(buttonBox,5,2);
setLayout(cameraLayout);
setWindowTitle(tr("Select Camera"));
resize(450, 400);
this->cameraView->sortByColumn(2, Qt::AscendingOrder);
this->filterColumnComboBox->setCurrentIndex(0);
this->filterPatternLineEdit->setText("");
this->filterCaseSensitivityCheckBox->setChecked(false);
this->sortCaseSensitivityCheckBox->setChecked(false);
}
cameraDataBaseModel::~cameraDataBaseModel()
{
}
void cameraDataBaseModel::setSourceModel(QAbstractItemModel *model)
{
cameraModel->setSourceModel(model);
}
void cameraDataBaseModel::filterRegExpChanged()
{
QRegExp::PatternSyntax syntax =
QRegExp::PatternSyntax(filterSyntaxComboBox->itemData(
filterSyntaxComboBox->currentIndex()).toInt());
Qt::CaseSensitivity caseSensitivity =
filterCaseSensitivityCheckBox->isChecked() ? Qt::CaseSensitive
: Qt::CaseInsensitive;
QRegExp regExp(filterPatternLineEdit->text(), caseSensitivity, syntax);
cameraModel->setFilterRegExp(regExp);
}
void cameraDataBaseModel::filterColumnChanged()
{
cameraModel->setFilterKeyColumn(filterColumnComboBox->currentIndex());
}
void cameraDataBaseModel::sortChanged()
{
cameraModel->setSortCaseSensitivity(
sortCaseSensitivityCheckBox->isChecked() ? Qt::CaseSensitive
: Qt::CaseInsensitive);
}
void cameraDataBaseModel::addCamera(QAbstractItemModel *model, const QString &cameraModel,
const double &FocalLength,const int &ImageWidth, const int &ImageHeight, const int &cameraID)
{
model->insertRow(0);
model->setData(model->index(0, 0), cameraModel);
model->setData(model->index(0, 1), FocalLength);
model->setData(model->index(0, 2), ImageWidth);
model->setData(model->index(0, 3), ImageHeight);
model->setData(model->index(0, 4), cameraID);
}
QAbstractItemModel * cameraDataBaseModel::setupModel()
{
model = new QStandardItemModel(0, 5);
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Camera Model"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Focal Length"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Image Width"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Image Height"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("Camera ID"));
for (int i =0; i < this->camDataBase->globalCameras.GetSize(); i++)
{
addCamera( model, QString::fromUtf8(this->camDataBase->globalCameras.GetAt(i)->getMakeAndModel()),
this->camDataBase->globalCameras.GetAt(i)->getFocalLength(),
this->camDataBase->globalCameras.GetAt(i)->getImageWidth(),
this->camDataBase->globalCameras.GetAt(i)->getImageHeight(), i );
}
return model;
}
void cameraDataBaseModel::accept()
{
//this where i want to grab the selection of the user and find the Camera ID which is the 4th colum of the model
}
To copy to clipboard, switch view to plain text mode
Bookmarks