1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 13:33:50 +03:00

settings:store views column widgets/criteria

This commit is contained in:
Michail Vourlakos 2021-03-31 11:44:32 +03:00
parent 9d68f6b32a
commit 634e68b857
3 changed files with 65 additions and 14 deletions

View File

@ -48,7 +48,7 @@ Views::Views(Settings::Handler::ViewsHandler *parent)
m_view(m_handler->ui()->viewsTable),
m_storage(KConfigGroup(KSharedConfig::openConfig(),"LatteSettingsDialog").group("ViewsDialog"))
{
// loadConfig();
loadConfig();
m_proxyModel->setSourceModel(m_model);
connect(m_model, &QAbstractItemModel::dataChanged, this, &Views::dataChanged);
@ -60,7 +60,7 @@ Views::Views(Settings::Handler::ViewsHandler *parent)
Views::~Views()
{
// saveConfig();
saveConfig();
}
QAbstractItemModel *Views::proxyModel() const
@ -95,6 +95,15 @@ void Views::init()
//m_view->setItemDelegateForColumn(Model::Layouts::MENUCOLUMN, new Settings::Layout::Delegate::CheckBox(this));
//m_view->setItemDelegateForColumn(Model::Layouts::BORDERSCOLUMN, new Settings::Layout::Delegate::CheckBox(this));
//m_view->setItemDelegateForColumn(Model::Layouts::ACTIVITYCOLUMN, new Settings::Layout::Delegate::Activities(this));
applyColumnWidths();
connect(m_view, &QObject::destroyed, this, &Views::storeColumnWidths);
connect(m_view->horizontalHeader(), &QObject::destroyed, this, [&]() {
m_viewSortColumn = m_view->horizontalHeader()->sortIndicatorSection();
m_viewSortOrder = m_view->horizontalHeader()->sortIndicatorOrder();
});
}
bool Views::hasChangedData() const
@ -114,6 +123,45 @@ void Views::selectRow(const QString &id)
// m_view->selectRow(rowForId(id));
}
void Views::applyColumnWidths()
{
m_view->horizontalHeader()->setSectionResizeMode(Model::Views::SCREENCOLUMN, QHeaderView::Stretch);
if (m_viewColumnWidths.count()<3) {
return;
}
m_view->setColumnWidth(Model::Views::EDGECOLUMN, m_viewColumnWidths[0].toInt());
m_view->setColumnWidth(Model::Views::ALIGNMENTCOLUMN, m_viewColumnWidths[1].toInt());
m_view->setColumnWidth(Model::Views::IDCOLUMN, m_viewColumnWidths[2].toInt());
}
void Views::storeColumnWidths()
{
if (m_viewColumnWidths.isEmpty()) {
//! storing three columns
m_viewColumnWidths << "" << "" << "";
}
m_viewColumnWidths[0] = QString::number(m_view->columnWidth(Model::Views::EDGECOLUMN));
m_viewColumnWidths[1] = QString::number(m_view->columnWidth(Model::Views::ALIGNMENTCOLUMN));
m_viewColumnWidths[2] = QString::number(m_view->columnWidth(Model::Views::IDCOLUMN));
}
void Views::loadConfig()
{
m_viewColumnWidths = m_storage.readEntry("columnWidths", QStringList());
m_viewSortColumn = m_storage.readEntry("sortColumn", (int)Model::Layouts::NAMECOLUMN);
m_viewSortOrder = static_cast<Qt::SortOrder>(m_storage.readEntry("sortOrder", (int)Qt::AscendingOrder));
}
void Views::saveConfig()
{
m_storage.writeEntry("columnWidths", m_viewColumnWidths);
m_storage.writeEntry("sortColumn", m_viewSortColumn);
m_storage.writeEntry("sortOrder", (int)m_viewSortOrder);
}
}
}
}

View File

@ -82,12 +82,12 @@ signals:
private:
void init();
private slots:
// void loadConfig();
// void saveConfig();
// void storeColumnWidths();
// void applyColumnWidths();
private slots:
void loadConfig();
void saveConfig();
void storeColumnWidths();
void applyColumnWidths();
private:
Settings::Handler::ViewsHandler *m_handler{nullptr};
@ -95,7 +95,7 @@ private:
QTableView *m_view{nullptr};
//! layoutsView ui settings
int m_viewSortColumn;
int m_viewSortColumn{Model::Views::SCREENCOLUMN};
Qt::SortOrder m_viewSortOrder;
QStringList m_viewColumnWidths;

View File

@ -107,23 +107,26 @@ QVariant Views::headerData(int section, Qt::Orientation orientation, int role) c
case SCREENCOLUMN:
if (role == Qt::DisplayRole) {
return QString(i18n("Screen"));
} else if (role == Qt::DecorationRole) {
return QIcon::fromTheme("desktop");
}
/* } else if (role == Qt::DecorationRole) {
return QIcon::fromTheme("desktop");
}*/
break;
case EDGECOLUMN:
if (role == Qt::DisplayRole) {
return QString(i18nc("screen edge", "Edge"));
} else if (role == Qt::DecorationRole) {
return QIcon::fromTheme("transform-move");
}
/* } else if (role == Qt::DecorationRole) {
return QIcon::fromTheme("transform-move");
}*/
break;
case ALIGNMENTCOLUMN:
if (role == Qt::DisplayRole) {
return QString(i18n("Alignment"));
} else if (role == Qt::DecorationRole) {
return QIcon::fromTheme("format-justify-center");
}
/*} else if (role == Qt::DecorationRole) {
return QIcon::fromTheme("format-justify-center");
}*/
break;
default:
break;