mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-01 06:35:41 +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 NotSet:
|
||||||
case StationsOnline:
|
case StationsOnline:
|
||||||
this->m_columns.addColumn(CColumn("callsign", CAtcStation::IndexCallsignAsStringAsSet));
|
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("distance", CAtcStation::IndexDistance, Qt::AlignRight | Qt::AlignVCenter));
|
||||||
this->m_columns.addColumn(CColumn("frequency", CAtcStation::IndexFrequency, Qt::AlignRight | Qt::AlignVCenter));
|
this->m_columns.addColumn(CColumn("frequency", CAtcStation::IndexFrequency, Qt::AlignRight | Qt::AlignVCenter));
|
||||||
this->m_columns.addColumn(CColumn("controllername", CAtcStation::IndexControllerRealName));
|
this->m_columns.addColumn(CColumn("controllername", CAtcStation::IndexControllerRealName));
|
||||||
@@ -52,6 +53,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
case StationsBooked:
|
case StationsBooked:
|
||||||
this->m_columns.addColumn(CColumn("callsign", CAtcStation::IndexCallsignAsStringAsSet));
|
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("controllername", CAtcStation::IndexControllerRealName));
|
||||||
this->m_columns.addColumn(CColumn("bookedfrom", CAtcStation::IndexBookedFrom));
|
this->m_columns.addColumn(CColumn("bookedfrom", CAtcStation::IndexBookedFrom));
|
||||||
this->m_columns.addColumn(CColumn("bookeduntil", CAtcStation::IndexBookedUntil));
|
this->m_columns.addColumn(CColumn("bookeduntil", CAtcStation::IndexBookedUntil));
|
||||||
|
|||||||
@@ -10,11 +10,18 @@
|
|||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
CColumn::CColumn(const QString &headerName, int propertyIndex, int alignment, bool editable) :
|
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) :
|
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
|
const char *CColumn::getTranslationContextChar() const
|
||||||
@@ -137,6 +144,15 @@ namespace BlackGui
|
|||||||
return this->m_columns.at(index.column()).isEditable();
|
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
|
* Aligment as QVariant
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -33,22 +33,27 @@ namespace BlackGui
|
|||||||
/*!
|
/*!
|
||||||
* \brief Constructor
|
* \brief Constructor
|
||||||
* \param headerName
|
* \param headerName
|
||||||
* \param propertyIndex
|
* \param propertyIndex as in CValueObject::propertyByIndex
|
||||||
* \param editable
|
* \param editable
|
||||||
*/
|
*/
|
||||||
CColumn(const QString &headerName, int propertyIndex, bool 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?
|
//! Alignment for this column?
|
||||||
bool hasAlignment() const
|
bool hasAlignment() const { return this->m_alignment >= 0; }
|
||||||
{
|
|
||||||
return this->m_alignment >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Editable?
|
//! Editable?
|
||||||
bool isEditable() const
|
bool isEditable() const { return this->m_editable; }
|
||||||
{
|
|
||||||
return this->m_editable;
|
//! Icon?
|
||||||
}
|
bool isIcon() const { return this->m_icon; }
|
||||||
|
|
||||||
//! Aligment as QVariant
|
//! Aligment as QVariant
|
||||||
QVariant aligmentAsQVariant() const;
|
QVariant aligmentAsQVariant() const;
|
||||||
@@ -71,6 +76,7 @@ namespace BlackGui
|
|||||||
int m_alignment;
|
int m_alignment;
|
||||||
int m_propertyIndex; // property index
|
int m_propertyIndex; // property index
|
||||||
bool m_editable;
|
bool m_editable;
|
||||||
|
bool m_icon;
|
||||||
const char *getTranslationContextChar() const;
|
const char *getTranslationContextChar() const;
|
||||||
const char *getColumnNameChar() const;
|
const char *getColumnNameChar() const;
|
||||||
};
|
};
|
||||||
@@ -118,6 +124,9 @@ namespace BlackGui
|
|||||||
//! Is this column editable?
|
//! Is this column editable?
|
||||||
bool isEditable(const QModelIndex &index) const;
|
bool isEditable(const QModelIndex &index) const;
|
||||||
|
|
||||||
|
//! Is icon?
|
||||||
|
bool isIcon(const QModelIndex &index) const;
|
||||||
|
|
||||||
//! Aligment as QVariant
|
//! Aligment as QVariant
|
||||||
QVariant aligmentAsQVariant(const QModelIndex &index) const;
|
QVariant aligmentAsQVariant(const QModelIndex &index) const;
|
||||||
|
|
||||||
|
|||||||
@@ -74,11 +74,19 @@ namespace BlackGui
|
|||||||
|
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
{
|
{
|
||||||
|
if (this->m_columns.isIcon(index)) return QVariant();
|
||||||
ObjectType obj = this->m_container[index.row()];
|
ObjectType obj = this->m_container[index.row()];
|
||||||
int propertyIndex = this->columnToPropertyIndex(index.column());
|
int propertyIndex = this->columnToPropertyIndex(index.column());
|
||||||
QString propertyString = obj.propertyByIndexAsString(propertyIndex, true);
|
QString propertyString = obj.propertyByIndexAsString(propertyIndex, true);
|
||||||
return QVariant::fromValue(propertyString);
|
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)
|
else if (role == Qt::TextAlignmentRole)
|
||||||
{
|
{
|
||||||
return this->m_columns.aligmentAsQVariant(index);
|
return this->m_columns.aligmentAsQVariant(index);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
case NotSet:
|
case NotSet:
|
||||||
case UserDetailed:
|
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("realname", CUser::IndexRealName));
|
||||||
this->m_columns.addColumn(CColumn("callsign", CUser::IndexCallsign));
|
this->m_columns.addColumn(CColumn("callsign", CUser::IndexCallsign));
|
||||||
this->m_columns.addColumn(CColumn("userid", CUser::IndexId));
|
this->m_columns.addColumn(CColumn("userid", CUser::IndexId));
|
||||||
@@ -51,22 +51,4 @@ namespace BlackGui
|
|||||||
break;
|
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
|
//! \brief Destructor
|
||||||
virtual ~CUserListModel() {}
|
virtual ~CUserListModel() {}
|
||||||
|
|
||||||
//! \copydoc CListModelBase::data
|
|
||||||
QVariant data(const QModelIndex &modelIndex, int role = Qt::DisplayRole) const;
|
|
||||||
|
|
||||||
//! Set station mode
|
//! Set station mode
|
||||||
void setUserMode(UserMode userMode);
|
void setUserMode(UserMode userMode);
|
||||||
|
|
||||||
|
|||||||
@@ -236,7 +236,8 @@ namespace BlackMisc
|
|||||||
/*
|
/*
|
||||||
* Frequency
|
* Frequency
|
||||||
*/
|
*/
|
||||||
void CAtcStation::setFrequency(const CFrequency &frequency) {
|
void CAtcStation::setFrequency(const CFrequency &frequency)
|
||||||
|
{
|
||||||
this->m_frequency = frequency;
|
this->m_frequency = frequency;
|
||||||
this->m_frequency.setUnit(CFrequencyUnit::MHz());
|
this->m_frequency.setUnit(CFrequencyUnit::MHz());
|
||||||
}
|
}
|
||||||
@@ -318,6 +319,8 @@ namespace BlackMisc
|
|||||||
return QVariant(this->m_callsign.asString());
|
return QVariant(this->m_callsign.asString());
|
||||||
case IndexCallsignAsStringAsSet:
|
case IndexCallsignAsStringAsSet:
|
||||||
return QVariant(this->m_callsign.getStringAsSet());
|
return QVariant(this->m_callsign.getStringAsSet());
|
||||||
|
case IndexCallsignIcon:
|
||||||
|
return QVariant(this->m_callsign.toIcon());
|
||||||
case IndexController:
|
case IndexController:
|
||||||
return this->m_controller.toQVariant();
|
return this->m_controller.toQVariant();
|
||||||
case IndexControllerRealName:
|
case IndexControllerRealName:
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ namespace BlackMisc
|
|||||||
IndexCallsign = 0,
|
IndexCallsign = 0,
|
||||||
IndexCallsignAsString,
|
IndexCallsignAsString,
|
||||||
IndexCallsignAsStringAsSet,
|
IndexCallsignAsStringAsSet,
|
||||||
|
IndexCallsignIcon,
|
||||||
IndexController,
|
IndexController,
|
||||||
IndexControllerRealName,
|
IndexControllerRealName,
|
||||||
IndexControllerId,
|
IndexControllerId,
|
||||||
|
|||||||
@@ -222,6 +222,13 @@ int BlackMisc:: compareQVariants(const QVariant &v1, const QVariant &v2)
|
|||||||
if (t1 == t2) return 0;
|
if (t1 == t2) return 0;
|
||||||
return t1 < t2 ? -1 : 1;
|
return t1 < t2 ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
case QMetaType::QPixmap:
|
||||||
|
{
|
||||||
|
QPixmap p1 = v1.value<QPixmap>();
|
||||||
|
QPixmap p2 = v2.value<QPixmap>();
|
||||||
|
if (p1.width() == p2.width()) return 0;
|
||||||
|
return p1.width() < p2.width() ? -1 : 1;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user