mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
Views style
This commit is contained in:
committed by
Roland Winklmeier
parent
9f5e265c5e
commit
ece54729ef
@@ -98,7 +98,7 @@ namespace BlackGui
|
||||
virtual void customMenu(CMenuActions &menuActions) override;
|
||||
|
||||
//! Change target
|
||||
void setModelsTarget(QObject *target) { this->m_modelsTarget = target; }
|
||||
void setModelsTarget(QObject *target) { m_modelsTarget = target; }
|
||||
|
||||
private:
|
||||
void consolidateData();
|
||||
@@ -130,7 +130,7 @@ namespace BlackGui
|
||||
virtual void customMenu(CMenuActions &menuActions) override;
|
||||
|
||||
//! Change target
|
||||
void setModelsTarget(QObject *target) { this->m_modelsTarget = target; }
|
||||
void setModelsTarget(QObject *target) { m_modelsTarget = target; }
|
||||
|
||||
private:
|
||||
void consolidateData();
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
|
||||
CColumn::CColumn(const QString &headerName, const QString &toolTip, const CPropertyIndex &propertyIndex, CDefaultFormatter *formatter, bool editable) :
|
||||
m_columnName(headerName), m_columnToolTip(toolTip), m_formatter(formatter ? formatter : new CDefaultFormatter()), m_propertyIndex(propertyIndex),
|
||||
m_editable(editable)
|
||||
@@ -32,13 +31,13 @@ namespace BlackGui
|
||||
|
||||
bool CColumn::hasSortPropertyIndex() const
|
||||
{
|
||||
return !this->m_sortPropertyIndex.isEmpty();
|
||||
return !m_sortPropertyIndex.isEmpty();
|
||||
}
|
||||
|
||||
void CColumn::setSortPropertyIndex(const CPropertyIndex &propertyIndex)
|
||||
{
|
||||
Q_ASSERT(!propertyIndex.isEmpty());
|
||||
this->m_sortPropertyIndex = propertyIndex;
|
||||
m_sortPropertyIndex = propertyIndex;
|
||||
}
|
||||
|
||||
CColumn::CColumn(const QString &toolTip, const CPropertyIndex &propertyIndex) :
|
||||
@@ -47,28 +46,28 @@ namespace BlackGui
|
||||
|
||||
const char *CColumn::getTranslationContextChar() const
|
||||
{
|
||||
return this->m_translationContext.toUtf8().constData();
|
||||
return m_translationContext.toUtf8().constData();
|
||||
}
|
||||
|
||||
const char *CColumn::getColumnNameChar() const
|
||||
{
|
||||
return this->m_columnName.toUtf8().constData();
|
||||
return m_columnName.toUtf8().constData();
|
||||
}
|
||||
|
||||
const char *CColumn::getColumnToolTipChar() const
|
||||
{
|
||||
return this->m_columnToolTip.toUtf8().constData();
|
||||
return m_columnToolTip.toUtf8().constData();
|
||||
}
|
||||
|
||||
QString CColumn::getColumnName(bool i18n) const
|
||||
{
|
||||
if (!i18n || this->m_translationContext.isEmpty()) return this->m_columnName;
|
||||
if (!i18n || m_translationContext.isEmpty()) return m_columnName;
|
||||
return QCoreApplication::translate(this->getTranslationContextChar(), this->getColumnNameChar());
|
||||
}
|
||||
|
||||
QString CColumn::getColumnToolTip(bool i18n) const
|
||||
{
|
||||
if (!i18n || this->m_columnToolTip.isEmpty()) return this->m_columnToolTip;
|
||||
if (!i18n || m_columnToolTip.isEmpty()) return m_columnToolTip;
|
||||
return QCoreApplication::translate(this->getTranslationContextChar(), this->getColumnToolTipChar());
|
||||
}
|
||||
|
||||
@@ -112,33 +111,33 @@ namespace BlackGui
|
||||
|
||||
void CColumns::addColumn(CColumn column)
|
||||
{
|
||||
Q_ASSERT(!this->m_translationContext.isEmpty());
|
||||
column.setTranslationContext(this->m_translationContext);
|
||||
this->m_columns.push_back(column);
|
||||
Q_ASSERT(!m_translationContext.isEmpty());
|
||||
column.setTranslationContext(m_translationContext);
|
||||
m_columns.push_back(column);
|
||||
}
|
||||
|
||||
QString CColumns::propertyIndexToColumnName(const CPropertyIndex &propertyIndex, bool i18n) const
|
||||
{
|
||||
int column = this->propertyIndexToColumn(propertyIndex);
|
||||
return this->m_columns.at(column).getColumnName(i18n);
|
||||
return m_columns.at(column).getColumnName(i18n);
|
||||
}
|
||||
|
||||
QString CColumns::columnToName(int column, bool i18n) const
|
||||
{
|
||||
Q_ASSERT(isValidColumn(column));
|
||||
return this->m_columns.at(column).getColumnName(i18n);
|
||||
return m_columns.at(column).getColumnName(i18n);
|
||||
}
|
||||
|
||||
CPropertyIndex CColumns::columnToPropertyIndex(int column) const
|
||||
{
|
||||
Q_ASSERT(isValidColumn(column));
|
||||
return this->m_columns.at(column).getPropertyIndex();
|
||||
return m_columns.at(column).getPropertyIndex();
|
||||
}
|
||||
|
||||
CPropertyIndex CColumns::columnToSortPropertyIndex(int column) const
|
||||
{
|
||||
Q_ASSERT(isValidColumn(column));
|
||||
const CColumn col = this->m_columns[column];
|
||||
const CColumn col = m_columns[column];
|
||||
Q_ASSERT(col.isSortable());
|
||||
if (!col.isSortable()) { return CPropertyIndex(); }
|
||||
if (col.hasSortPropertyIndex()) { return col.getSortPropertyIndex(); }
|
||||
@@ -147,9 +146,9 @@ namespace BlackGui
|
||||
|
||||
int CColumns::propertyIndexToColumn(const CPropertyIndex &propertyIndex) const
|
||||
{
|
||||
for (int i = 0; i < this->m_columns.size(); i++)
|
||||
for (int i = 0; i < m_columns.size(); i++)
|
||||
{
|
||||
if (this->m_columns.at(i).getPropertyIndex() == propertyIndex)
|
||||
if (m_columns.at(i).getPropertyIndex() == propertyIndex)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
@@ -159,9 +158,9 @@ namespace BlackGui
|
||||
|
||||
int CColumns::nameToPropertyIndex(const QString &name) const
|
||||
{
|
||||
for (int i = 0; i < this->m_columns.size(); i++)
|
||||
for (int i = 0; i < m_columns.size(); i++)
|
||||
{
|
||||
if (this->m_columns.at(i).getColumnName(false) == name)
|
||||
if (m_columns.at(i).getColumnName(false) == name)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
@@ -169,58 +168,58 @@ namespace BlackGui
|
||||
|
||||
int CColumns::size() const
|
||||
{
|
||||
return this->m_columns.size();
|
||||
return m_columns.size();
|
||||
}
|
||||
|
||||
bool CColumns::hasAlignment(const QModelIndex &index) const
|
||||
{
|
||||
if (!isValidColumn(index)) return false;
|
||||
return this->m_columns.at(index.column()).hasAlignment();
|
||||
return m_columns.at(index.column()).hasAlignment();
|
||||
}
|
||||
|
||||
bool CColumns::isEditable(const QModelIndex &index) const
|
||||
{
|
||||
if (!isValidColumn(index)) return false;
|
||||
return this->m_columns.at(index.column()).isEditable();
|
||||
return m_columns.at(index.column()).isEditable();
|
||||
}
|
||||
|
||||
bool CColumns::isEditable(int column) const
|
||||
{
|
||||
if (!isValidColumn(column)) return false;
|
||||
return this->m_columns.at(column).isEditable();
|
||||
return m_columns.at(column).isEditable();
|
||||
}
|
||||
|
||||
bool CColumns::isSortable(const QModelIndex &index) const
|
||||
{
|
||||
if (!isValidColumn(index)) return false;
|
||||
return this->m_columns.at(index.column()).isSortable();
|
||||
return m_columns.at(index.column()).isSortable();
|
||||
}
|
||||
|
||||
bool CColumns::isSortable(int column) const
|
||||
{
|
||||
if (!isValidColumn(column)) return false;
|
||||
return this->m_columns.at(column).isSortable();
|
||||
return m_columns.at(column).isSortable();
|
||||
}
|
||||
|
||||
bool CColumns::isValidColumn(const QModelIndex &index) const
|
||||
{
|
||||
return (index.column() >= 0 && index.column() < this->m_columns.size());
|
||||
return (index.column() >= 0 && index.column() < m_columns.size());
|
||||
}
|
||||
|
||||
bool CColumns::isValidColumn(int column) const
|
||||
{
|
||||
return column >= 0 && column < this->m_columns.size();
|
||||
return column >= 0 && column < m_columns.size();
|
||||
}
|
||||
|
||||
const CDefaultFormatter *CColumns::getFormatter(const QModelIndex &index) const
|
||||
{
|
||||
if (!isValidColumn(index)) { return nullptr; }
|
||||
return this->m_columns.at(index.column()).getFormatter();
|
||||
return m_columns.at(index.column()).getFormatter();
|
||||
}
|
||||
|
||||
const char *CColumns::getTranslationContextChar() const
|
||||
{
|
||||
return this->m_translationContext.toUtf8().constData();
|
||||
return m_translationContext.toUtf8().constData();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -48,22 +48,22 @@ namespace BlackGui
|
||||
CColumn(const BlackMisc::CPropertyIndex &propertyIndex);
|
||||
|
||||
//! Alignment for this column?
|
||||
bool hasAlignment() const { return (!this->m_formatter.isNull() && this->m_formatter->hasAlignment()); }
|
||||
bool hasAlignment() const { return (!m_formatter.isNull() && m_formatter->hasAlignment()); }
|
||||
|
||||
//! Editable?
|
||||
bool isEditable() const { return this->m_editable; }
|
||||
bool isEditable() const { return m_editable; }
|
||||
|
||||
//! Set editable
|
||||
void setEditable(bool editable) { this->m_editable = editable; }
|
||||
void setEditable(bool editable) { m_editable = editable; }
|
||||
|
||||
//! Sortable?
|
||||
bool isSortable() const { return this->m_sortable; }
|
||||
bool isSortable() const { return m_sortable; }
|
||||
|
||||
//! Set sortable
|
||||
void setSortable(bool sortable) { this->m_sortable = sortable; }
|
||||
void setSortable(bool sortable) { m_sortable = sortable; }
|
||||
|
||||
//! Property index used when sorting, option alternative
|
||||
BlackMisc::CPropertyIndex getSortPropertyIndex() const { return this->m_sortPropertyIndex; }
|
||||
BlackMisc::CPropertyIndex getSortPropertyIndex() const { return m_sortPropertyIndex; }
|
||||
|
||||
//! Sort index available
|
||||
bool hasSortPropertyIndex() const;
|
||||
@@ -75,7 +75,7 @@ namespace BlackGui
|
||||
void setFormatter(CDefaultFormatter *formatter) { Q_ASSERT(formatter); m_formatter.reset(formatter); }
|
||||
|
||||
//! Formatter
|
||||
const CDefaultFormatter *getFormatter() const { return this->m_formatter.data(); }
|
||||
const CDefaultFormatter *getFormatter() const { return m_formatter.data(); }
|
||||
|
||||
//! Aligment as CVariant
|
||||
BlackMisc::CVariant getAlignment() const;
|
||||
@@ -87,10 +87,10 @@ namespace BlackGui
|
||||
QString getColumnToolTip(bool i18n = false) const;
|
||||
|
||||
//! Property index
|
||||
const BlackMisc::CPropertyIndex &getPropertyIndex() const { return this->m_propertyIndex;}
|
||||
const BlackMisc::CPropertyIndex &getPropertyIndex() const { return m_propertyIndex;}
|
||||
|
||||
//! Translation context
|
||||
void setTranslationContext(const QString &translationContext) { this->m_translationContext = translationContext; }
|
||||
void setTranslationContext(const QString &translationContext) { m_translationContext = translationContext; }
|
||||
|
||||
//! Get a standard value object formatted column
|
||||
static CColumn standardValueObject(const QString &headerName, const BlackMisc::CPropertyIndex &propertyIndex, int alignment = CDefaultFormatter::alignDefault());
|
||||
@@ -193,10 +193,10 @@ namespace BlackGui
|
||||
const CDefaultFormatter *getFormatter(const QModelIndex &index) const;
|
||||
|
||||
//! Column at position
|
||||
const CColumn &at(int columnNumber) const { return this->m_columns.at(columnNumber); }
|
||||
const CColumn &at(int columnNumber) const { return m_columns.at(columnNumber); }
|
||||
|
||||
//! Clear
|
||||
void clear() { this->m_columns.clear(); }
|
||||
void clear() { m_columns.clear(); }
|
||||
|
||||
private:
|
||||
QList<CColumn> m_columns;
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace BlackGui
|
||||
|
||||
//! \name View base class overrides
|
||||
//! @{
|
||||
virtual void customMenu(BlackGui::Menus::CMenuActions &menuActions) override;
|
||||
virtual void customMenu(Menus::CMenuActions &menuActions) override;
|
||||
virtual BlackMisc::CStatusMessage modifyLoadedJsonData(BlackMisc::Simulation::CAircraftModelList &models) const override;
|
||||
virtual BlackMisc::CStatusMessage validateLoadedJsonData(const BlackMisc::Simulation::CAircraftModelList &models) const override;
|
||||
virtual void jsonLoadedAndModelUpdated(const BlackMisc::Simulation::CAircraftModelList &models) override;
|
||||
|
||||
@@ -135,45 +135,45 @@ namespace BlackGui
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::customMenu(CMenuActions &menuActions)
|
||||
{
|
||||
if (this->m_menus.testFlag(CViewBaseNonTemplate::MenuOrderable) && this->hasSelection())
|
||||
if (m_menus.testFlag(CViewBaseNonTemplate::MenuOrderable) && this->hasSelection())
|
||||
{
|
||||
const int maxOrder = this->rowCount() - 1;
|
||||
CMenuAction menu = menuActions.addMenuViewOrder();
|
||||
if (this->m_menuActions.isEmpty())
|
||||
if (m_menuActions.isEmpty())
|
||||
{
|
||||
// predefine menus
|
||||
this->m_menuActions = QList<QAction *>({ nullptr, nullptr, nullptr, nullptr});
|
||||
m_menuActions = QList<QAction *>({ nullptr, nullptr, nullptr, nullptr});
|
||||
|
||||
if (!this->m_menuActions[0])
|
||||
if (!m_menuActions[0])
|
||||
{
|
||||
this->m_frame = new QFrame(this);
|
||||
QHBoxLayout *layout = new QHBoxLayout(this->m_frame);
|
||||
m_frame = new QFrame(this);
|
||||
QHBoxLayout *layout = new QHBoxLayout(m_frame);
|
||||
layout->setMargin(2);
|
||||
this->m_frame->setLayout(layout);
|
||||
this->m_leOrder = new QLineEdit(this->m_frame);
|
||||
QLabel *icon = new QLabel(this->m_frame);
|
||||
m_frame->setLayout(layout);
|
||||
m_leOrder = new QLineEdit(m_frame);
|
||||
QLabel *icon = new QLabel(m_frame);
|
||||
icon->setPixmap(menu.getPixmap());
|
||||
layout->addWidget(icon);
|
||||
QLabel *label = new QLabel(this->m_frame);
|
||||
QLabel *label = new QLabel(m_frame);
|
||||
label->setText("Order:");
|
||||
layout->addWidget(label);
|
||||
layout->addWidget(this->m_leOrder);
|
||||
this->m_validator = new QIntValidator(0, maxOrder, this);
|
||||
this->m_leOrder->setValidator(this->m_validator);
|
||||
layout->addWidget(m_leOrder);
|
||||
m_validator = new QIntValidator(0, maxOrder, this);
|
||||
m_leOrder->setValidator(m_validator);
|
||||
QWidgetAction *orderAction = new QWidgetAction(this);
|
||||
orderAction->setDefaultWidget(this->m_frame);
|
||||
QObject::connect(this->m_leOrder, &QLineEdit::returnPressed, this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::orderToLineEdit);
|
||||
this->m_menuActions[0] = orderAction;
|
||||
orderAction->setDefaultWidget(m_frame);
|
||||
QObject::connect(m_leOrder, &QLineEdit::returnPressed, this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::orderToLineEdit);
|
||||
m_menuActions[0] = orderAction;
|
||||
}
|
||||
}
|
||||
|
||||
this->m_validator->setRange(0, maxOrder);
|
||||
this->m_leOrder->setPlaceholderText("New order 0-" + QString::number(maxOrder));
|
||||
m_validator->setRange(0, maxOrder);
|
||||
m_leOrder->setPlaceholderText("New order 0-" + QString::number(maxOrder));
|
||||
|
||||
menuActions.addAction(this->m_menuActions[0], CMenuAction::pathViewOrder());
|
||||
this->m_menuActions[1] = menuActions.addAction(CIcons::arrowMediumNorth16(), "To top", CMenuAction::pathViewOrder(), { this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::orderToTop });
|
||||
this->m_menuActions[2] = menuActions.addAction(CIcons::arrowMediumSouth16(), "To bottom", CMenuAction::pathViewOrder(), { this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::orderToBottom });
|
||||
this->m_menuActions[3] = menuActions.addAction(CIcons::arrowMediumWest16(), "Freeze current order", CMenuAction::pathViewOrder(), { this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::freezeCurrentOrder });
|
||||
menuActions.addAction(m_menuActions[0], CMenuAction::pathViewOrder());
|
||||
m_menuActions[1] = menuActions.addAction(CIcons::arrowMediumNorth16(), "To top", CMenuAction::pathViewOrder(), { this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::orderToTop });
|
||||
m_menuActions[2] = menuActions.addAction(CIcons::arrowMediumSouth16(), "To bottom", CMenuAction::pathViewOrder(), { this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::orderToBottom });
|
||||
m_menuActions[3] = menuActions.addAction(CIcons::arrowMediumWest16(), "Freeze current order", CMenuAction::pathViewOrder(), { this, &COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::freezeCurrentOrder });
|
||||
}
|
||||
CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::customMenu(menuActions);
|
||||
}
|
||||
@@ -193,7 +193,7 @@ namespace BlackGui
|
||||
if (this->isEmpty()) { return; }
|
||||
const ContainerType objs(this->selectedObjects());
|
||||
if (objs.isEmpty()) { return; }
|
||||
this->m_model->moveItems(objs, order);
|
||||
m_model->moveItems(objs, order);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
|
||||
Reference in New Issue
Block a user