From 6335a6fdd49f08b1316a20dd7080bf9997c0ffee Mon Sep 17 00:00:00 2001 From: Dmitry Degtyarev Date: Mon, 18 May 2020 11:44:09 +0400 Subject: [PATCH] remove excessive auto's --- src/ad_filter.cpp | 6 ++--- src/ad_model.cpp | 50 ++++++++++++++++++++-------------------- src/attributes_model.cpp | 10 ++++---- src/attributes_view.cpp | 10 ++++---- src/contents_view.cpp | 14 +++++------ src/create_entry.cpp | 16 ++++++------- src/main.cpp | 4 ++-- 7 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/ad_filter.cpp b/src/ad_filter.cpp index 6a14f151..3802f8be 100644 --- a/src/ad_filter.cpp +++ b/src/ad_filter.cpp @@ -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; } diff --git a/src/ad_model.cpp b/src/ad_model.cpp index a39f81d3..ca0e7b52 100644 --- a/src/ad_model.cpp +++ b/src/ad_model.cpp @@ -6,25 +6,25 @@ #include void load_row(QList row, QString &dn) { - auto attributes = load_attributes(dn); + QMap> 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 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 row, QString &dn) { // is container bool is_container = false; if (attributes.contains("objectClass")) { - auto objectClasses = attributes["objectClass"]; + QList objectClasses = attributes["objectClass"]; QList container_objectClasses = {"container", "organizationalUnit", "builtinDomain", "domain"}; for (auto e : container_objectClasses) { @@ -60,10 +60,10 @@ void load_row(QList 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 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 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(); 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(); 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); } diff --git a/src/attributes_model.cpp b/src/attributes_model.cpp index ad33398a..8d079f57 100644 --- a/src/attributes_model.cpp +++ b/src/attributes_model.cpp @@ -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 diff --git a/src/attributes_view.cpp b/src/attributes_view.cpp index 41766528..4208a486 100644 --- a/src/attributes_view.cpp +++ b/src/attributes_view.cpp @@ -9,25 +9,25 @@ void AttributesView::set_target_from_selection(const QItemSelection &selected, const QItemSelection &) { // Convert selection to dn - auto indexes = selected.indexes(); + QList 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(this->model()); + AttributesModel *model = qobject_cast(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> attributes = load_attributes(this->target_dn); for (auto attribute : attributes.keys()) { - auto values = attributes[attribute]; + QList values = attributes[attribute]; for (auto value : values) { auto name_item = new QStandardItem(attribute); diff --git a/src/contents_view.cpp b/src/contents_view.cpp index 019818ab..40b5e944 100644 --- a/src/contents_view.cpp +++ b/src/contents_view.cpp @@ -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 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(model); + const QAbstractItemModel *model = source_index.model(); + const QSortFilterProxyModel *proxy_model = qobject_cast(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(model); + const QAbstractItemModel *model = this->model(); + const QSortFilterProxyModel *proxy_model = qobject_cast(model); if (proxy_model != nullptr) { contents_index = proxy_model->mapFromSource(contents_index); } diff --git a/src/create_entry.cpp b/src/create_entry.cpp index 6b264ddd..6aa8e5fc 100644 --- a/src/create_entry.cpp +++ b/src/create_entry.cpp @@ -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 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); } diff --git a/src/main.cpp b/src/main.cpp index 1c6fc2bb..1873a207 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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);