1
0
mirror of https://github.com/altlinux/admc.git synced 2025-01-18 02:04:36 +03:00

remove excessive auto's

This commit is contained in:
Dmitry Degtyarev 2020-05-18 11:44:09 +04:00
parent b2576f5116
commit 6335a6fdd4
7 changed files with 55 additions and 55 deletions

View File

@ -17,17 +17,17 @@ AdFilter::AdFilter(const QAction * const advanced_view_action, bool only_show_co
}
bool AdFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
auto index = sourceModel()->index(source_row, 0, source_parent);
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
// Hide advanced view only entries if advanced view is OFF
auto advanced_view_only = index.data(AdModel::Roles::AdvancedViewOnly).toBool();
bool advanced_view_only = index.data(AdModel::Roles::AdvancedViewOnly).toBool();
if (advanced_view_only && !this->advanced_view) {
return false;
}
if (only_show_containers) {
// Hide non-containers
auto is_container = index.data(AdModel::Roles::IsContainer).toBool();
bool is_container = index.data(AdModel::Roles::IsContainer).toBool();
if (!is_container) {
return false;
}

View File

@ -6,25 +6,25 @@
#include <QMap>
void load_row(QList<QStandardItem*> row, QString &dn) {
auto attributes = load_attributes(dn);
QMap<QString, QList<QString>> attributes = load_attributes(dn);
// TODO: get rid of "if (x.contains(y))"
// Name
auto name = dn;
QString name = dn;
if (attributes.contains("name")) {
name = attributes["name"][0];
}
// Category
auto category = dn;
QString category = dn;
if (attributes.contains("objectCategory")) {
// NOTE: raw category is given as DN
// TODO: convert it completely (turn '-' into ' ')
auto category_as_dn = attributes["objectCategory"][0];
auto equals_index = category_as_dn.indexOf('=') + 1;
auto comma_index = category_as_dn.indexOf(',');
auto segment_length = comma_index - equals_index;
QString category_as_dn = attributes["objectCategory"][0];
int equals_index = category_as_dn.indexOf('=') + 1;
int comma_index = category_as_dn.indexOf(',');
int segment_length = comma_index - equals_index;
// TODO: check what happens if equals is negative
category = category_as_dn.mid(equals_index, segment_length);
}
@ -38,7 +38,7 @@ void load_row(QList<QStandardItem*> row, QString &dn) {
// showInAdvancedViewOnly
bool advanced_view = false;
if (attributes.contains("showInAdvancedViewOnly")) {
auto advanced_view_str = attributes["showInAdvancedViewOnly"][0];
QString advanced_view_str = attributes["showInAdvancedViewOnly"][0];
if (advanced_view_str == "TRUE") {
advanced_view = true;
@ -49,7 +49,7 @@ void load_row(QList<QStandardItem*> row, QString &dn) {
// is container
bool is_container = false;
if (attributes.contains("objectClass")) {
auto objectClasses = attributes["objectClass"];
QList<QString> objectClasses = attributes["objectClass"];
QList<QString> container_objectClasses = {"container", "organizationalUnit", "builtinDomain", "domain"};
for (auto e : container_objectClasses) {
@ -60,10 +60,10 @@ void load_row(QList<QStandardItem*> row, QString &dn) {
}
}
auto name_item = row[AdModel::Column::Name];
auto category_item = row[AdModel::Column::Category];
auto description_item = row[AdModel::Column::Description];
auto dn_item = row[AdModel::Column::DN];
QStandardItem *name_item = row[AdModel::Column::Name];
QStandardItem *category_item = row[AdModel::Column::Category];
QStandardItem *description_item = row[AdModel::Column::Description];
QStandardItem *dn_item = row[AdModel::Column::DN];
name_item->setText(name);
category_item->setText(category);
@ -94,7 +94,7 @@ AdModel::AdModel(): QStandardItemModel(0, Column::COUNT) {
this->setHorizontalHeaderItem(Column::Description, new QStandardItem("Description"));
// Load head
auto invis_root = this->invisibleRootItem();
QStandardItem *invis_root = this->invisibleRootItem();
auto head_dn = QString(HEAD_DN);
load_and_add_row(invis_root, head_dn);
@ -105,7 +105,7 @@ bool AdModel::canFetchMore(const QModelIndex &parent) const {
return false;
}
auto can_fetch = parent.data(AdModel::Roles::CanFetch).toBool();
bool can_fetch = parent.data(AdModel::Roles::CanFetch).toBool();
return can_fetch;
}
@ -115,13 +115,13 @@ void AdModel::fetchMore(const QModelIndex &parent) {
return;
}
auto dn_index = parent.siblingAtColumn(Column::DN);
auto dn = dn_index.data().toString();
QModelIndex dn_index = parent.siblingAtColumn(Column::DN);
QString dn = dn_index.data().toString();
auto parent_item = this->itemFromIndex(parent);
QStandardItem *parent_item = this->itemFromIndex(parent);
// Add children
auto children = load_children(dn);
QList<QString> children = load_children(dn);
for (auto child : children) {
load_and_add_row(parent_item, child);
@ -143,25 +143,25 @@ bool AdModel::hasChildren(const QModelIndex &parent = QModelIndex()) const {
void AdModel::on_entry_changed(QString &dn) {
// TODO: confirm what kind of search is this, linear?
auto items = this->findItems(dn, Qt::MatchExactly | Qt::MatchRecursive, AdModel::Column::DN);
QList<QStandardItem *> items = this->findItems(dn, Qt::MatchExactly | Qt::MatchRecursive, AdModel::Column::DN);
// TODO: not sure if any bad matches can happen, maybe?
if (items.size() > 0) {
auto dn_item = items[0];
auto dn_index = dn_item->index();
QStandardItem *dn_item = items[0];
QModelIndex dn_index = dn_item->index();
// Compose indexes for all columns
auto indexes = QList<QModelIndex>();
for (int i = 0; i < AdModel::Column::COUNT; i++) {
auto index = dn_index.siblingAtColumn(i);
QModelIndex index = dn_index.siblingAtColumn(i);
indexes.push_back(index);
}
// Compose the row of items from indexes
auto row = QList<QStandardItem *>();
for (int i = 0; i < AdModel::Column::COUNT; i++) {
auto index = indexes[i];
auto item = this->itemFromIndex(index);
QModelIndex index = indexes[i];
QStandardItem *item = this->itemFromIndex(index);
row.push_back(item);
}

View File

@ -10,12 +10,12 @@ AttributesModel::AttributesModel(): QStandardItemModel(0, Column::COUNT) {
// This will be called when an attribute value is edited
bool AttributesModel::setData(const QModelIndex &index, const QVariant &value, int role) {
auto value_index = index;
auto name_index = value_index.siblingAtColumn(AttributesModel::Column::Name);
QModelIndex value_index = index;
QModelIndex name_index = value_index.siblingAtColumn(AttributesModel::Column::Name);
auto dn = this->target_dn;
auto attribute = name_index.data().toString();
auto value_str = value.toString();
QString dn = this->target_dn;
QString attribute = name_index.data().toString();
QString value_str = value.toString();
// printf("setData: %s, %s, %s\n", qPrintable(dn), qPrintable(attribute), qPrintable(value_str));
// TODO: attribute edit can fail for many reasons, handle it

View File

@ -9,25 +9,25 @@
void AttributesView::set_target_from_selection(const QItemSelection &selected, const QItemSelection &) {
// Convert selection to dn
auto indexes = selected.indexes();
QList<QModelIndex> indexes = selected.indexes();
if (indexes.size() == 0) {
return;
}
auto index = indexes[0];
QModelIndex index = indexes[0];
this->target_dn = index.siblingAtColumn(AdModel::Column::DN).data().toString();
// Clear model of previous root
// TODO: get rid of cast
auto model = qobject_cast<AttributesModel *>(this->model());
AttributesModel *model = qobject_cast<AttributesModel *>(this->model());
if (model != nullptr) {
model->change_target(this->target_dn);
}
// Populate model with attributes of new root
auto attributes = load_attributes(this->target_dn);
QMap<QString, QList<QString>> attributes = load_attributes(this->target_dn);
for (auto attribute : attributes.keys()) {
auto values = attributes[attribute];
QList<QString> values = attributes[attribute];
for (auto value : values) {
auto name_item = new QStandardItem(attribute);

View File

@ -9,27 +9,27 @@
// Both contents and containers share the same source model, but have different proxy's to it
// So need to map from containers proxy to source then back to proxy of contents
void ContentsView::set_root_index_from_selection(const QItemSelection &selected, const QItemSelection &) {
auto indexes = selected.indexes();
QList<QModelIndex> indexes = selected.indexes();
if (indexes.size() == 0) {
return;
}
// Map from proxy model of given index to source model of this view (if needed)
auto source_index = indexes[0];
QModelIndex source_index = indexes[0];
{
auto model = source_index.model();
auto proxy_model = qobject_cast<const QSortFilterProxyModel *>(model);
const QAbstractItemModel *model = source_index.model();
const QSortFilterProxyModel *proxy_model = qobject_cast<const QSortFilterProxyModel *>(model);
if (proxy_model != nullptr) {
source_index = proxy_model->mapToSource(source_index);
}
}
// Map from source model of this view to proxy model of this view (if needed)
auto contents_index = source_index;
QModelIndex contents_index = source_index;
{
auto model = this->model();
auto proxy_model = qobject_cast<const QSortFilterProxyModel *>(model);
const QAbstractItemModel *model = this->model();
const QSortFilterProxyModel *proxy_model = qobject_cast<const QSortFilterProxyModel *>(model);
if (proxy_model != nullptr) {
contents_index = proxy_model->mapFromSource(contents_index);
}

View File

@ -53,7 +53,7 @@ void create_entry_dialog(NewEntryType type) {
}
bool ok;
auto name = QInputDialog::getText(nullptr, dialog_title, input_label, QLineEdit::Normal, "", &ok);
QString name = QInputDialog::getText(nullptr, dialog_title, input_label, QLineEdit::Normal, "", &ok);
// TODO: maybe expand tree to newly created entry?
@ -103,7 +103,7 @@ void create_entry_dialog(NewEntryType type) {
}
}
auto dn = suffix + "=" + name + "," + parent_dn;
QString dn = suffix + "=" + name + "," + parent_dn;
bool success = create_entry(name, dn, parent_dn, type);
@ -114,15 +114,15 @@ void create_entry_dialog(NewEntryType type) {
// TODO: for some reason doesnt work with expanded parent
auto items = admodel->findItems(parent_dn, Qt::MatchExactly | Qt::MatchRecursive, AdModel::Column::DN);
QList<QStandardItem *> items = admodel->findItems(parent_dn, Qt::MatchExactly | Qt::MatchRecursive, AdModel::Column::DN);
if (items.size() > 0) {
auto dn_item = items[0];
auto dn_index = dn_item->index();
auto parent_index = dn_index.siblingAtColumn(0);
auto parent = admodel->itemFromIndex(parent_index);
QStandardItem *dn_item = items[0];
QModelIndex dn_index = dn_item->index();
QModelIndex parent_index = dn_index.siblingAtColumn(0);
QStandardItem *parent = admodel->itemFromIndex(parent_index);
auto fetched_already = !admodel->canFetchMore(parent_index);
bool fetched_already = !admodel->canFetchMore(parent_index);
if (fetched_already) {
load_and_add_row(parent, dn);
}

View File

@ -42,7 +42,7 @@ int main(int argc, char **argv) {
// Contents
{
auto view = ui.contents_view;
ContentsView *view = ui.contents_view;
auto proxy = new AdFilter(ui.menubar_view_advancedView);
proxy->setSourceModel(&ad_model);
@ -53,7 +53,7 @@ int main(int argc, char **argv) {
// Containers
{
auto view = ui.containers_view;
ContainersView *view = ui.containers_view;
auto proxy = new AdFilter(ui.menubar_view_advancedView, true);
proxy->setSourceModel(&ad_model);