mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-28 11:45:40 +08:00
Support for an empty column
This commit is contained in:
@@ -421,5 +421,13 @@ namespace BlackGui
|
|||||||
if (ok) { return QString::number(i); }
|
if (ok) { return QString::number(i); }
|
||||||
return CVariant();
|
return CVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CVariant CEmptyFormatter::displayRole(const CVariant &dataCVariant) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(dataCVariant);
|
||||||
|
static const CVariant empty("");
|
||||||
|
return empty;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -154,6 +154,17 @@ namespace BlackGui
|
|||||||
virtual BlackMisc::CVariant displayRole(const BlackMisc::CVariant &dataCVariant) const override;
|
virtual BlackMisc::CVariant displayRole(const BlackMisc::CVariant &dataCVariant) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! Just returns a empty "" value
|
||||||
|
class CEmptyFormatter : public CDefaultFormatter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Constructor
|
||||||
|
CEmptyFormatter(int alignment = alignDefault()) : CDefaultFormatter(alignment, false, roleDisplay()) {}
|
||||||
|
|
||||||
|
//! \copydoc CDefaultFormatter::displayRole
|
||||||
|
virtual BlackMisc::CVariant displayRole(const BlackMisc::CVariant &dataCVariant) const override;
|
||||||
|
};
|
||||||
|
|
||||||
//! Layout will be defined by a delegate
|
//! Layout will be defined by a delegate
|
||||||
class CDelegateFormatter : public CDefaultFormatter
|
class CDelegateFormatter : public CDefaultFormatter
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,6 +73,13 @@ namespace BlackGui
|
|||||||
return CColumn(headerName, toolTip, propertyIndex, new CIntegerFormatter(alignment));
|
return CColumn(headerName, toolTip, propertyIndex, new CIntegerFormatter(alignment));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CColumn CColumn::emptyColumn()
|
||||||
|
{
|
||||||
|
CColumn col = CColumn("", "", CPropertyIndex::GlobalIndexEmpty, new CEmptyFormatter());
|
||||||
|
col.setWidthPercentage(1);
|
||||||
|
return col;
|
||||||
|
}
|
||||||
|
|
||||||
// --------------- columns ----------------------------------------------
|
// --------------- columns ----------------------------------------------
|
||||||
|
|
||||||
CColumns::CColumns(const QString &translationContext, QObject *parent) :
|
CColumns::CColumns(const QString &translationContext, QObject *parent) :
|
||||||
@@ -236,6 +243,19 @@ namespace BlackGui
|
|||||||
return widths;
|
return widths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CColumns::insertEmptyColumn()
|
||||||
|
{
|
||||||
|
if (this->endsWithEmptyColumn()) { return; }
|
||||||
|
this->addColumn(CColumn::emptyColumn());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CColumns::endsWithEmptyColumn() const
|
||||||
|
{
|
||||||
|
if (m_columns.isEmpty()) { return false; }
|
||||||
|
const CColumn c = m_columns.last();
|
||||||
|
return c.getPropertyIndex() == CPropertyIndex::GlobalIndexEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
const CDefaultFormatter *CColumns::getFormatter(const QModelIndex &index) const
|
const CDefaultFormatter *CColumns::getFormatter(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!isValidColumn(index)) { return nullptr; }
|
if (!isValidColumn(index)) { return nullptr; }
|
||||||
|
|||||||
@@ -118,6 +118,9 @@ namespace BlackGui
|
|||||||
//! Get a standard integer value formatted column
|
//! Get a standard integer value formatted column
|
||||||
static CColumn standardInteger(const QString &headerName, const QString &toolTip, const BlackMisc::CPropertyIndex &propertyIndex, int alignment = CDefaultFormatter::alignRightVCenter());
|
static CColumn standardInteger(const QString &headerName, const QString &toolTip, const BlackMisc::CPropertyIndex &propertyIndex, int alignment = CDefaultFormatter::alignRightVCenter());
|
||||||
|
|
||||||
|
//! An empty column
|
||||||
|
static CColumn emptyColumn();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_translationContext;
|
QString m_translationContext;
|
||||||
QString m_columnName;
|
QString m_columnName;
|
||||||
@@ -220,6 +223,12 @@ namespace BlackGui
|
|||||||
//! Calculate the absolute width
|
//! Calculate the absolute width
|
||||||
QList<int> calculateWidths(int totalWidth) const;
|
QList<int> calculateWidths(int totalWidth) const;
|
||||||
|
|
||||||
|
//! Insert an empty column
|
||||||
|
void insertEmptyColumn();
|
||||||
|
|
||||||
|
//! Ending with an empty column
|
||||||
|
bool endsWithEmptyColumn() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<CColumn> m_columns;
|
QList<CColumn> m_columns;
|
||||||
QString m_translationContext; //!< for future usage
|
QString m_translationContext; //!< for future usage
|
||||||
|
|||||||
@@ -102,9 +102,14 @@ namespace BlackGui
|
|||||||
const int row = index.row();
|
const int row = index.row();
|
||||||
const int col = index.column();
|
const int col = index.column();
|
||||||
const CPropertyIndex propertyIndex = this->columnToPropertyIndex(col);
|
const CPropertyIndex propertyIndex = this->columnToPropertyIndex(col);
|
||||||
if (static_cast<int>(CPropertyIndex::GlobalIndexLineNumber) == propertyIndex.frontCasted<int>())
|
const int propertyIndexFront = propertyIndex.frontCasted<int>();
|
||||||
|
|
||||||
|
// special cases
|
||||||
|
switch (propertyIndexFront)
|
||||||
{
|
{
|
||||||
return QVariant::fromValue(row + 1);
|
case CPropertyIndex::GlobalIndexLineNumber: return QVariant::fromValue(row + 1);
|
||||||
|
case CPropertyIndex::GlobalIndexEmpty: return {};
|
||||||
|
default: break; // continue here
|
||||||
}
|
}
|
||||||
|
|
||||||
// Formatted data
|
// Formatted data
|
||||||
|
|||||||
@@ -129,6 +129,9 @@ namespace BlackGui
|
|||||||
//! The columns
|
//! The columns
|
||||||
const CColumns &getColumns() const { return m_columns; }
|
const CColumns &getColumns() const { return m_columns; }
|
||||||
|
|
||||||
|
//! Using void column at the end?
|
||||||
|
bool endsWithEmptyColumn() const { return m_columns.endsWithEmptyColumn(); }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Asynchronous update finished
|
//! Asynchronous update finished
|
||||||
void asyncUpdateFinished();
|
void asyncUpdateFinished();
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// m_columns.insertEmptyColumn();
|
||||||
|
|
||||||
// sorting
|
// sorting
|
||||||
if (CStatusMessageListModel::sortedByTimestampOrOrder(oldIndex))
|
if (CStatusMessageListModel::sortedByTimestampOrOrder(oldIndex))
|
||||||
|
|||||||
@@ -186,6 +186,9 @@ namespace BlackGui
|
|||||||
//! \copydoc BlackGui::Models::CListModelBaseNonTemplate::hasValidSortColumn
|
//! \copydoc BlackGui::Models::CListModelBaseNonTemplate::hasValidSortColumn
|
||||||
virtual bool hasValidSortColumn() const = 0;
|
virtual bool hasValidSortColumn() const = 0;
|
||||||
|
|
||||||
|
//! \copydoc BlackGui::Models::CListModelBaseNonTemplate::endsWithEmptyColumn
|
||||||
|
virtual bool endsWithEmptyColumn() const = 0;
|
||||||
|
|
||||||
//! \copydoc BlackGui::Models::CListModelBaseNonTemplate::getSortOrder
|
//! \copydoc BlackGui::Models::CListModelBaseNonTemplate::getSortOrder
|
||||||
virtual Qt::SortOrder getSortOrder() const = 0;
|
virtual Qt::SortOrder getSortOrder() const = 0;
|
||||||
|
|
||||||
@@ -736,6 +739,7 @@ namespace BlackGui
|
|||||||
virtual BlackMisc::CPropertyIndex getSortProperty() const override { return m_model->getSortProperty(); }
|
virtual BlackMisc::CPropertyIndex getSortProperty() const override { return m_model->getSortProperty(); }
|
||||||
virtual int getSortColumn() const override { return m_model->getSortColumn(); }
|
virtual int getSortColumn() const override { return m_model->getSortColumn(); }
|
||||||
virtual bool hasValidSortColumn() const override { return m_model->hasValidSortColumn(); }
|
virtual bool hasValidSortColumn() const override { return m_model->hasValidSortColumn(); }
|
||||||
|
virtual bool endsWithEmptyColumn() const override { return m_model->endsWithEmptyColumn(); }
|
||||||
virtual Qt::SortOrder getSortOrder() const override { return m_model->getSortOrder(); }
|
virtual Qt::SortOrder getSortOrder() const override { return m_model->getSortOrder(); }
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ namespace BlackMisc
|
|||||||
GlobalIndexSwiftCore = 17100,
|
GlobalIndexSwiftCore = 17100,
|
||||||
GlobalIndexSwiftLauncher = 17200,
|
GlobalIndexSwiftLauncher = 17200,
|
||||||
GlobalIndexLineNumber = 20000, //!< pseudo index for line numbers
|
GlobalIndexLineNumber = 20000, //!< pseudo index for line numbers
|
||||||
|
GlobalIndexEmpty = 20001
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Default constructor.
|
//! Default constructor.
|
||||||
|
|||||||
Reference in New Issue
Block a user