mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 13:36:48 +08:00
refs #535, updated viewbase and formatters
* Fixed wrong masking * changed signal for model * update selected models * directly set object in model
This commit is contained in:
@@ -22,10 +22,9 @@ namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
|
||||
Qt::ItemFlags CDefaultFormatter::flags(Qt::ItemFlags flags, bool editable) const
|
||||
{
|
||||
return editable ? (flags | Qt::ItemIsEditable) : (flags ^ Qt::ItemIsEditable);
|
||||
return editable ? (flags | Qt::ItemIsEditable) : (flags & ~Qt::ItemIsEditable);
|
||||
}
|
||||
|
||||
CVariant CDefaultFormatter::displayRole(const CVariant &dataCVariant) const
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "listmodelbase.h"
|
||||
#include "allmodelcontainers.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackmisc/verify.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/json.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
@@ -108,13 +109,13 @@ namespace BlackGui
|
||||
Qt::ItemFlags f = QStandardItemModel::flags(index);
|
||||
if (!index.isValid()) { return f; }
|
||||
bool editable = this->m_columns.isEditable(index);
|
||||
f = editable ? (f | Qt::ItemIsEditable) : (f ^ Qt::ItemIsEditable);
|
||||
f = editable ? (f | Qt::ItemIsEditable) : (f & ~Qt::ItemIsEditable);
|
||||
|
||||
// flags from formatter
|
||||
const CDefaultFormatter *formatter = this->m_columns.getFormatter(index);
|
||||
if (formatter) { f = formatter->flags(f, editable); }
|
||||
|
||||
// drag and rop
|
||||
// drag and drop
|
||||
f = f | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
||||
|
||||
return f;
|
||||
@@ -137,7 +138,7 @@ namespace BlackGui
|
||||
|
||||
QStringList CListModelBaseNonTemplate::mimeTypes() const
|
||||
{
|
||||
static const QStringList mimes( { "application/swift.container.json" });
|
||||
static const QStringList mimes({ "application/swift.container.json" });
|
||||
return mimes;
|
||||
}
|
||||
|
||||
@@ -151,6 +152,21 @@ namespace BlackGui
|
||||
return m_modelDestroyed;
|
||||
}
|
||||
|
||||
void CListModelBaseNonTemplate::sendDataChanged(int startRowIndex, int endRowIndex)
|
||||
{
|
||||
BLACK_VERIFY_X(startRowIndex <= endRowIndex, Q_FUNC_INFO, "check rows");
|
||||
BLACK_VERIFY_X(startRowIndex >= 0 && endRowIndex >= 0, Q_FUNC_INFO, "check rows");
|
||||
|
||||
int columns = columnCount();
|
||||
int rows = rowCount();
|
||||
if (columns < 1) { return; }
|
||||
if (startRowIndex < 0) { startRowIndex = 0; }
|
||||
if (endRowIndex >= rows) { endRowIndex = rows - 1; }
|
||||
QModelIndex topLeft(createIndex(startRowIndex, 0));
|
||||
QModelIndex bottomRight(createIndex(endRowIndex, columns - 1));
|
||||
emit dataChanged(topLeft, bottomRight);
|
||||
}
|
||||
|
||||
int CListModelBaseNonTemplate::ps_updateContainer(const CVariant &variant, bool sort)
|
||||
{
|
||||
return this->performUpdateContainer(variant, sort);
|
||||
@@ -242,6 +258,16 @@ namespace BlackGui
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
bool CListModelBase<ObjectType, ContainerType, UseCompare>::setInContainer(const QModelIndex &index, const ObjectType &obj)
|
||||
{
|
||||
if (!index.isValid()) { return false; }
|
||||
int row = index.row();
|
||||
if (row < 0 || row >= this->container().size()) { return false; }
|
||||
m_container[row] = obj;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
int CListModelBase<ObjectType, ContainerType, UseCompare>::update(const ContainerType &container, bool sort)
|
||||
{
|
||||
@@ -479,6 +505,7 @@ namespace BlackGui
|
||||
{
|
||||
int n = this->getContainerOrFilteredContainer().size();
|
||||
emit this->rowCountChanged(n, this->hasFilter());
|
||||
emit this->changed();
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
|
||||
@@ -96,6 +96,10 @@ namespace BlackGui
|
||||
//! Model about to be destroyed?
|
||||
bool isModelDestroyed();
|
||||
|
||||
//! Send signal that data have been changed.
|
||||
//! \note Meant for scenarios where the container is directly updated and a subsequent signal is required
|
||||
void sendDataChanged(int startRowIndex, int endRowIndex);
|
||||
|
||||
signals:
|
||||
//! Asynchronous update finished
|
||||
void asyncUpdateFinished();
|
||||
@@ -103,6 +107,9 @@ namespace BlackGui
|
||||
//! Number of elements changed
|
||||
void rowCountChanged(int count, bool withFilter);
|
||||
|
||||
//! Model has been changed
|
||||
void changed();
|
||||
|
||||
//! Template free information, that object changed
|
||||
void objectChanged(const BlackMisc::CVariant &object, const BlackMisc::CPropertyIndex &changedIndex);
|
||||
|
||||
@@ -147,6 +154,10 @@ namespace BlackGui
|
||||
//! \sa CListModelBaseNonTemplate::flags
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
|
||||
//! Simple set of data in container, using class is responsible for firing signals etc.
|
||||
//! \sa sendDataChanged
|
||||
bool setInContainer(const QModelIndex &index, const ObjectType &obj);
|
||||
|
||||
//! \copydoc QStandardItemModel::rowCount()
|
||||
virtual int rowCount(const QModelIndex &parentIndex = QModelIndex()) const override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user