mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #300, moved views in subdirectory and namespace
This commit is contained in:
94
src/blackgui/views/viewbase.h
Normal file
94
src/blackgui/views/viewbase.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef BLACKGUI_VIEWBASE_H
|
||||
#define BLACKGUI_VIEWBASE_H
|
||||
|
||||
//! \file
|
||||
|
||||
#include <QTableView>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
{
|
||||
//! List model
|
||||
template <class ModelClass> class CViewBase : public QTableView
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
//! Constructor
|
||||
CViewBase(QWidget *parent, ModelClass *model = nullptr) : QTableView(parent), m_model(model)
|
||||
{
|
||||
this->setSortingEnabled(true);
|
||||
this->horizontalHeader()->setStretchLastSection(true);
|
||||
}
|
||||
|
||||
//! Destructor
|
||||
virtual ~CViewBase() {}
|
||||
|
||||
ModelClass *m_model; //!< corresponding model
|
||||
|
||||
public:
|
||||
|
||||
//! Model
|
||||
ModelClass *derivedModel() { return this->m_model; }
|
||||
|
||||
//! Model
|
||||
const ModelClass *derivedModel() const { return this->m_model; }
|
||||
|
||||
//! Clear
|
||||
void clear() { Q_ASSERT(this->m_model); this->m_model->clear(); }
|
||||
|
||||
//! Update
|
||||
template<class ContainerType> int update(const ContainerType &container, bool resize = true)
|
||||
{
|
||||
Q_ASSERT(this->m_model);
|
||||
int c = this->m_model->update(container);
|
||||
if (!resize) return c;
|
||||
this->resizeColumnsToContents();
|
||||
this->resizeRowsToContents();
|
||||
return c;
|
||||
}
|
||||
|
||||
//! Insert
|
||||
template<class ObjectType> void insert(const ObjectType &value, bool resize = true)
|
||||
{
|
||||
Q_ASSERT(this->m_model);
|
||||
this->m_model->insert(value);
|
||||
if (!resize) return;
|
||||
this->resizeColumnsToContents();
|
||||
this->resizeRowsToContents();
|
||||
}
|
||||
|
||||
//! Value object at
|
||||
template<class ObjectType> const ObjectType &at(const QModelIndex &index) const
|
||||
{
|
||||
Q_ASSERT(this->m_model);
|
||||
return this->m_model->at(index);
|
||||
}
|
||||
|
||||
//! Row count
|
||||
int rowCount() const
|
||||
{
|
||||
Q_ASSERT(this->m_model);
|
||||
return this->m_model->rowCount();
|
||||
}
|
||||
|
||||
//! Any data?
|
||||
bool isEmpty() const
|
||||
{
|
||||
Q_ASSERT(this->m_model);
|
||||
return this->m_model->rowCount() < 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user