mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 05:28:09 +08:00
refs #264, QPixmap enable list model base to simplify columns with icons
* new constructor in column class * removed overridden data method, no longer needed * added icons for ATC station views * QPixmap comparison for such columns (free functions)
This commit is contained in:
@@ -38,6 +38,7 @@ namespace BlackGui
|
||||
case NotSet:
|
||||
case StationsOnline:
|
||||
this->m_columns.addColumn(CColumn("callsign", CAtcStation::IndexCallsignAsStringAsSet));
|
||||
this->m_columns.addColumn(CColumn(CAtcStation::IndexCallsignIcon, true));
|
||||
this->m_columns.addColumn(CColumn("distance", CAtcStation::IndexDistance, Qt::AlignRight | Qt::AlignVCenter));
|
||||
this->m_columns.addColumn(CColumn("frequency", CAtcStation::IndexFrequency, Qt::AlignRight | Qt::AlignVCenter));
|
||||
this->m_columns.addColumn(CColumn("controllername", CAtcStation::IndexControllerRealName));
|
||||
@@ -52,6 +53,7 @@ namespace BlackGui
|
||||
|
||||
case StationsBooked:
|
||||
this->m_columns.addColumn(CColumn("callsign", CAtcStation::IndexCallsignAsStringAsSet));
|
||||
this->m_columns.addColumn(CColumn(CAtcStation::IndexCallsignIcon, true));
|
||||
this->m_columns.addColumn(CColumn("controllername", CAtcStation::IndexControllerRealName));
|
||||
this->m_columns.addColumn(CColumn("bookedfrom", CAtcStation::IndexBookedFrom));
|
||||
this->m_columns.addColumn(CColumn("bookeduntil", CAtcStation::IndexBookedUntil));
|
||||
|
||||
@@ -10,11 +10,18 @@
|
||||
namespace BlackGui
|
||||
{
|
||||
CColumn::CColumn(const QString &headerName, int propertyIndex, int alignment, bool editable) :
|
||||
m_columnName(headerName), m_alignment(alignment), m_propertyIndex(propertyIndex), m_editable(editable)
|
||||
m_columnName(headerName), m_alignment(alignment), m_propertyIndex(propertyIndex),
|
||||
m_editable(editable), m_icon(false)
|
||||
{}
|
||||
|
||||
CColumn::CColumn(const QString &headerName, int propertyIndex, bool editable) :
|
||||
m_columnName(headerName), m_alignment(-1), m_propertyIndex(propertyIndex), m_editable(editable)
|
||||
m_columnName(headerName), m_alignment(-1), m_propertyIndex(propertyIndex),
|
||||
m_editable(editable), m_icon(false)
|
||||
{}
|
||||
|
||||
CColumn::CColumn(int propertyIndex, bool isIcon) :
|
||||
m_alignment(-1), m_propertyIndex(propertyIndex),
|
||||
m_editable(false), m_icon(isIcon)
|
||||
{}
|
||||
|
||||
const char *CColumn::getTranslationContextChar() const
|
||||
@@ -137,6 +144,15 @@ namespace BlackGui
|
||||
return this->m_columns.at(index.column()).isEditable();
|
||||
}
|
||||
|
||||
/*
|
||||
* Is icon?
|
||||
*/
|
||||
bool CColumns::isIcon(const QModelIndex &index) const
|
||||
{
|
||||
if (index.column() < 0 || index.column() >= this->m_columns.size()) return false;
|
||||
return this->m_columns.at(index.column()).isIcon();
|
||||
}
|
||||
|
||||
/*
|
||||
* Aligment as QVariant
|
||||
*/
|
||||
|
||||
@@ -33,22 +33,27 @@ namespace BlackGui
|
||||
/*!
|
||||
* \brief Constructor
|
||||
* \param headerName
|
||||
* \param propertyIndex
|
||||
* \param propertyIndex as in CValueObject::propertyByIndex
|
||||
* \param editable
|
||||
*/
|
||||
CColumn(const QString &headerName, int propertyIndex, bool editable);
|
||||
|
||||
/*!
|
||||
* \brief Constructor column is icon
|
||||
* \remarks only make sense with isIcon as true
|
||||
* \param propertyIndex as in CValueObject::propertyByIndex
|
||||
* \param isIcon icon, should be used with true only
|
||||
*/
|
||||
CColumn(int propertyIndex, bool isIcon);
|
||||
|
||||
//! Alignment for this column?
|
||||
bool hasAlignment() const
|
||||
{
|
||||
return this->m_alignment >= 0;
|
||||
}
|
||||
bool hasAlignment() const { return this->m_alignment >= 0; }
|
||||
|
||||
//! Editable?
|
||||
bool isEditable() const
|
||||
{
|
||||
return this->m_editable;
|
||||
}
|
||||
bool isEditable() const { return this->m_editable; }
|
||||
|
||||
//! Icon?
|
||||
bool isIcon() const { return this->m_icon; }
|
||||
|
||||
//! Aligment as QVariant
|
||||
QVariant aligmentAsQVariant() const;
|
||||
@@ -71,6 +76,7 @@ namespace BlackGui
|
||||
int m_alignment;
|
||||
int m_propertyIndex; // property index
|
||||
bool m_editable;
|
||||
bool m_icon;
|
||||
const char *getTranslationContextChar() const;
|
||||
const char *getColumnNameChar() const;
|
||||
};
|
||||
@@ -118,6 +124,9 @@ namespace BlackGui
|
||||
//! Is this column editable?
|
||||
bool isEditable(const QModelIndex &index) const;
|
||||
|
||||
//! Is icon?
|
||||
bool isIcon(const QModelIndex &index) const;
|
||||
|
||||
//! Aligment as QVariant
|
||||
QVariant aligmentAsQVariant(const QModelIndex &index) const;
|
||||
|
||||
|
||||
@@ -74,11 +74,19 @@ namespace BlackGui
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
if (this->m_columns.isIcon(index)) return QVariant();
|
||||
ObjectType obj = this->m_container[index.row()];
|
||||
int propertyIndex = this->columnToPropertyIndex(index.column());
|
||||
QString propertyString = obj.propertyByIndexAsString(propertyIndex, true);
|
||||
return QVariant::fromValue(propertyString);
|
||||
}
|
||||
else if (role == Qt::DecorationRole)
|
||||
{
|
||||
if (!this->m_columns.isIcon(index)) return QVariant();
|
||||
ObjectType obj = this->m_container[index.row()];
|
||||
int propertyIndex = this->columnToPropertyIndex(index.column());
|
||||
return obj.propertyByIndex(propertyIndex);
|
||||
}
|
||||
else if (role == Qt::TextAlignmentRole)
|
||||
{
|
||||
return this->m_columns.aligmentAsQVariant(index);
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace BlackGui
|
||||
{
|
||||
case NotSet:
|
||||
case UserDetailed:
|
||||
this->m_columns.addColumn(CColumn("", CUser::IndexCallsignIcon));
|
||||
this->m_columns.addColumn(CColumn(CUser::IndexCallsignIcon, true));
|
||||
this->m_columns.addColumn(CColumn("realname", CUser::IndexRealName));
|
||||
this->m_columns.addColumn(CColumn("callsign", CUser::IndexCallsign));
|
||||
this->m_columns.addColumn(CColumn("userid", CUser::IndexId));
|
||||
@@ -51,22 +51,4 @@ namespace BlackGui
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Display icons
|
||||
*/
|
||||
QVariant CUserListModel::data(const QModelIndex &modelIndex, int role) const
|
||||
{
|
||||
// shortcut, fast check
|
||||
if (role != Qt::DecorationRole) return CListModelBase::data(modelIndex, role);
|
||||
if (this->columnToPropertyIndex(modelIndex.column()) == CUser::IndexCallsignIcon)
|
||||
{
|
||||
if (role == Qt::DecorationRole)
|
||||
{
|
||||
CUser u = this->at(modelIndex);
|
||||
return u.toIcon();
|
||||
}
|
||||
}
|
||||
return CListModelBase::data(modelIndex, role);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,6 @@ namespace BlackGui
|
||||
//! \brief Destructor
|
||||
virtual ~CUserListModel() {}
|
||||
|
||||
//! \copydoc CListModelBase::data
|
||||
QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const;
|
||||
|
||||
//! Set station mode
|
||||
void setUserMode(UserMode userMode);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user