diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2019-11-17 20:02:20 +0100 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2019-11-17 20:43:10 +0000 |
commit | a51c58fa1b1605a6088d82baf832f4fd7df49a75 (patch) | |
tree | d2f4bc0bddebd7ccfb4ad072a5114005d190b41c /ui/qt/models/interface_tree_cache_model.cpp | |
parent | 1ddd30856d59b138861def6bff407f035c8babee (diff) |
Qt: Cleanup space inside parentheses
Remove randomly used space inside parentheses to make the coding
style uniform. Add space after if, for and while.
Change-Id: I519f5994b6f73d8a57a5004d51ca460276c618fe
Reviewed-on: https://code.wireshark.org/review/35112
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt/models/interface_tree_cache_model.cpp')
-rw-r--r-- | ui/qt/models/interface_tree_cache_model.cpp | 146 |
1 files changed, 73 insertions, 73 deletions
diff --git a/ui/qt/models/interface_tree_cache_model.cpp b/ui/qt/models/interface_tree_cache_model.cpp index 96f0432ded..ff084a3013 100644 --- a/ui/qt/models/interface_tree_cache_model.cpp +++ b/ui/qt/models/interface_tree_cache_model.cpp @@ -67,14 +67,14 @@ QVariant InterfaceTreeCacheModel::getColumnContent(int idx, int col, int role) #ifdef HAVE_LIBPCAP void InterfaceTreeCacheModel::reset(int row) { - if ( row < 0 ) + if (row < 0) { delete storage; storage = new QMap<int, QMap<InterfaceTreeColumns, QVariant> *>(); } else { - if ( storage->count() > row ) + if (storage->count() > row) storage->remove(storage->keys().at(row)); } } @@ -95,17 +95,17 @@ void InterfaceTreeCacheModel::saveNewDevices() QMap<InterfaceTreeColumns, QVariant> * dataField = storage->value(idx, 0); /* When devices are being added, they are added using generic values. So only devices * whose data have been changed should be used from here on out. */ - if ( dataField != 0 ) + if (dataField != 0) { - if ( device->if_info.type != IF_PIPE ) + if (device->if_info.type != IF_PIPE) { continue; } - if ( device->if_info.type == IF_PIPE ) + if (device->if_info.type == IF_PIPE) { QVariant saveValue = dataField->value(IFTREE_COL_PIPE_PATH); - if ( saveValue.isValid() ) + if (saveValue.isValid()) { g_free(device->if_info.name); device->if_info.name = qstring_strdup(saveValue.toString()); @@ -119,7 +119,7 @@ void InterfaceTreeCacheModel::saveNewDevices() } } - if ( useDevice ) + if (useDevice) g_array_append_val(global_capture_opts.all_ifaces, *device); } @@ -134,7 +134,7 @@ void InterfaceTreeCacheModel::saveNewDevices() void InterfaceTreeCacheModel::save() { - if ( storage->count() == 0 ) + if (storage->count() == 0) return; QMap<char**, QStringList> prefStorage; @@ -146,21 +146,21 @@ void InterfaceTreeCacheModel::save() saveNewDevices(); - for(unsigned int idx = 0; idx < global_capture_opts.all_ifaces->len; idx++) + for (unsigned int idx = 0; idx < global_capture_opts.all_ifaces->len; idx++) { interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, idx); - if (! device->name ) + if (! device->name) continue; /* Try to load a saved value row for this index */ QMap<InterfaceTreeColumns, QVariant> * dataField = storage->value(idx, 0); /* Handle the storing of values for this device here */ - if ( dataField ) + if (dataField) { QMap<InterfaceTreeColumns, QVariant>::const_iterator it = dataField->constBegin(); - while ( it != dataField->constEnd() ) + while (it != dataField->constEnd()) { InterfaceTreeColumns col = it.key(); QVariant saveValue = it.value(); @@ -170,30 +170,30 @@ void InterfaceTreeCacheModel::save() * value has to be handled separately. Comments are stored only in the preference file * and applied to the data name during loading. Therefore comments are not handled here */ - if ( col == IFTREE_COL_HIDDEN ) + if (col == IFTREE_COL_HIDDEN) { device->hidden = saveValue.toBool(); } - else if ( device->if_info.type == IF_EXTCAP ) + else if (device->if_info.type == IF_EXTCAP) { /* extcap interfaces do not have the following columns. * ATTENTION: all generic columns must be added, BEFORE this * if-clause, or they will be ignored for extcap interfaces */ } - else if ( col == IFTREE_COL_PROMISCUOUSMODE ) + else if (col == IFTREE_COL_PROMISCUOUSMODE) { device->pmode = saveValue.toBool(); } #ifdef HAVE_PCAP_CREATE - else if ( col == IFTREE_COL_MONITOR_MODE ) + else if (col == IFTREE_COL_MONITOR_MODE) { device->monitor_mode_enabled = saveValue.toBool(); } #endif - else if ( col == IFTREE_COL_SNAPLEN ) + else if (col == IFTREE_COL_SNAPLEN) { int iVal = saveValue.toInt(); - if ( iVal != WTAP_MAX_PACKET_SIZE_STANDARD ) + if (iVal != WTAP_MAX_PACKET_SIZE_STANDARD) { device->has_snaplen = true; device->snaplen = iVal; @@ -205,7 +205,7 @@ void InterfaceTreeCacheModel::save() } } #ifdef CAN_SET_CAPTURE_BUFFER_SIZE - else if ( col == IFTREE_COL_BUFFERLEN ) + else if (col == IFTREE_COL_BUFFERLEN) { device->buffer = saveValue.toInt(); } @@ -215,22 +215,22 @@ void InterfaceTreeCacheModel::save() } QVariant content = getColumnContent(idx, IFTREE_COL_HIDDEN, Qt::CheckStateRole); - if ( content.isValid() && static_cast<Qt::CheckState>(content.toInt()) == Qt::Unchecked ) + if (content.isValid() && static_cast<Qt::CheckState>(content.toInt()) == Qt::Unchecked) prefStorage[&prefs.capture_devices_hide] << QString(device->name); content = getColumnContent(idx, IFTREE_COL_COMMENT); - if ( content.isValid() && content.toString().size() > 0 ) + if (content.isValid() && content.toString().size() > 0) prefStorage[&prefs.capture_devices_descr] << QString("%1(%2)").arg(device->name).arg(content.toString()); bool allowExtendedColumns = true; - if ( device->if_info.type == IF_EXTCAP ) + if (device->if_info.type == IF_EXTCAP) allowExtendedColumns = false; - if ( allowExtendedColumns ) + if (allowExtendedColumns) { content = getColumnContent(idx, IFTREE_COL_PROMISCUOUSMODE, Qt::CheckStateRole); - if ( content.isValid() ) + if (content.isValid()) { bool value = static_cast<Qt::CheckState>(content.toInt()) == Qt::Checked; prefStorage[&prefs.capture_devices_pmode] << QString("%1(%2)").arg(device->name).arg(value ? 1 : 0); @@ -238,12 +238,12 @@ void InterfaceTreeCacheModel::save() #ifdef HAVE_PCAP_CREATE content = getColumnContent(idx, IFTREE_COL_MONITOR_MODE, Qt::CheckStateRole); - if ( content.isValid() && static_cast<Qt::CheckState>(content.toInt()) == Qt::Checked ) + if (content.isValid() && static_cast<Qt::CheckState>(content.toInt()) == Qt::Checked) prefStorage[&prefs.capture_devices_monitor_mode] << QString(device->name); #endif content = getColumnContent(idx, IFTREE_COL_SNAPLEN); - if ( content.isValid() ) + if (content.isValid()) { int value = content.toInt(); prefStorage[&prefs.capture_devices_snaplen] << @@ -254,10 +254,10 @@ void InterfaceTreeCacheModel::save() #ifdef CAN_SET_CAPTURE_BUFFER_SIZE content = getColumnContent(idx, IFTREE_COL_BUFFERLEN); - if ( content.isValid() ) + if (content.isValid()) { int value = content.toInt(); - if ( value != -1 ) + if (value != -1) { prefStorage[&prefs.capture_devices_buffersize] << QString("%1(%2)").arg(device->name). @@ -269,7 +269,7 @@ void InterfaceTreeCacheModel::save() } QMap<char**, QStringList>::const_iterator it = prefStorage.constBegin(); - while ( it != prefStorage.constEnd() ) + while (it != prefStorage.constEnd()) { char ** key = it.key(); @@ -294,7 +294,7 @@ int InterfaceTreeCacheModel::rowCount(const QModelIndex & parent) const bool InterfaceTreeCacheModel::changeIsAllowed(InterfaceTreeColumns col) const { - if ( editableColumns.contains(col) || checkableColumns.contains(col) ) + if (editableColumns.contains(col) || checkableColumns.contains(col)) return true; return false; } @@ -304,15 +304,15 @@ const interface_t * InterfaceTreeCacheModel::lookup(const QModelIndex &index) co { const interface_t * result = 0; - if ( ! index.isValid() || ! global_capture_opts.all_ifaces ) + if (! index.isValid() || ! global_capture_opts.all_ifaces) return result; int idx = index.row(); - if ( (unsigned int) idx >= global_capture_opts.all_ifaces->len ) + if ((unsigned int) idx >= global_capture_opts.all_ifaces->len) { idx = idx - global_capture_opts.all_ifaces->len; - if ( idx < newDevices.size() ) + if (idx < newDevices.size()) result = &newDevices[idx]; } else @@ -333,17 +333,17 @@ bool InterfaceTreeCacheModel::isAllowedToBeEdited(const QModelIndex &index) cons Q_UNUSED(index); #else const interface_t * device = lookup(index); - if ( device == 0 ) + if (device == 0) return false; InterfaceTreeColumns col = (InterfaceTreeColumns) index.column(); - if ( device->if_info.type == IF_EXTCAP ) + if (device->if_info.type == IF_EXTCAP) { /* extcap interfaces do not have those settings */ - if ( col == IFTREE_COL_PROMISCUOUSMODE || col == IFTREE_COL_SNAPLEN ) + if (col == IFTREE_COL_PROMISCUOUSMODE || col == IFTREE_COL_SNAPLEN) return false; #ifdef CAN_SET_CAPTURE_BUFFER_SIZE - if ( col == IFTREE_COL_BUFFERLEN ) + if (col == IFTREE_COL_BUFFERLEN) return false; #endif } @@ -359,14 +359,14 @@ bool InterfaceTreeCacheModel::isAvailableField(const QModelIndex &index) const #else const interface_t * device = lookup(index); - if ( device == 0 ) + if (device == 0) return false; InterfaceTreeColumns col = (InterfaceTreeColumns) index.column(); - if ( col == IFTREE_COL_HIDDEN ) + if (col == IFTREE_COL_HIDDEN) { // Do not allow default capture interface to be hidden. - if ( ! g_strcmp0(prefs.capture_device, device->display_name) ) + if (! g_strcmp0(prefs.capture_device, device->display_name)) return false; } #endif @@ -376,16 +376,16 @@ bool InterfaceTreeCacheModel::isAvailableField(const QModelIndex &index) const Qt::ItemFlags InterfaceTreeCacheModel::flags(const QModelIndex &index) const { - if ( ! index.isValid() ) + if (! index.isValid()) return 0; Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable; InterfaceTreeColumns col = (InterfaceTreeColumns) index.column(); - if ( changeIsAllowed(col) && isAvailableField(index) && isAllowedToBeEdited(index) ) + if (changeIsAllowed(col) && isAvailableField(index) && isAllowedToBeEdited(index)) { - if ( checkableColumns.contains(col) ) + if (checkableColumns.contains(col)) { flags |= Qt::ItemIsUserCheckable; } @@ -400,25 +400,25 @@ Qt::ItemFlags InterfaceTreeCacheModel::flags(const QModelIndex &index) const bool InterfaceTreeCacheModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if ( ! index.isValid() ) + if (! index.isValid()) return false; - if ( ! isAvailableField(index) ) + if (! isAvailableField(index)) return false; int row = index.row(); InterfaceTreeColumns col = (InterfaceTreeColumns)index.column(); - if ( role == Qt::CheckStateRole || role == Qt::EditRole ) + if (role == Qt::CheckStateRole || role == Qt::EditRole) { - if ( changeIsAllowed( col ) ) + if (changeIsAllowed(col) ) { QVariant saveValue = value; QMap<InterfaceTreeColumns, QVariant> * dataField = 0; /* obtain the list of already stored changes for this row. If none exist * create a new storage row for this entry */ - if ( ( dataField = storage->value(row, 0) ) == 0 ) + if ((dataField = storage->value(row, 0)) == 0) { dataField = new QMap<InterfaceTreeColumns, QVariant>(); storage->insert(row, dataField); @@ -435,22 +435,22 @@ bool InterfaceTreeCacheModel::setData(const QModelIndex &index, const QVariant & QVariant InterfaceTreeCacheModel::data(const QModelIndex &index, int role) const { - if ( ! index.isValid() ) + if (! index.isValid()) return QVariant(); int row = index.row(); InterfaceTreeColumns col = (InterfaceTreeColumns)index.column(); - if ( isAvailableField(index) && isAllowedToBeEdited(index) ) + if (isAvailableField(index) && isAllowedToBeEdited(index)) { - if ( ( ( role == Qt::DisplayRole || role == Qt::EditRole ) && editableColumns.contains(col) ) || - ( role == Qt::CheckStateRole && checkableColumns.contains(col) ) ) + if (((role == Qt::DisplayRole || role == Qt::EditRole) && editableColumns.contains(col)) || + (role == Qt::CheckStateRole && checkableColumns.contains(col)) ) { QMap<InterfaceTreeColumns, QVariant> * dataField = 0; - if ( ( dataField = storage->value(row, 0) ) != 0 ) + if ((dataField = storage->value(row, 0)) != 0) { - if ( dataField->contains(col) ) + if (dataField->contains(col)) { return dataField->value(col, QVariant()); } @@ -459,13 +459,13 @@ QVariant InterfaceTreeCacheModel::data(const QModelIndex &index, int role) const } else { - if ( role == Qt::CheckStateRole ) + if (role == Qt::CheckStateRole) return QVariant(); - else if ( role == Qt::DisplayRole ) + else if (role == Qt::DisplayRole) return QString(UTF8_EM_DASH); } - if ( row < sourceModel->rowCount() ) + if (row < sourceModel->rowCount()) { return sourceModel->data(index, role); } @@ -478,35 +478,35 @@ QVariant InterfaceTreeCacheModel::data(const QModelIndex &index, int role) const * classify as new devices. */ const interface_t * device = lookup(index); - if ( device != 0 ) + if (device != 0) { - if ( role == Qt::DisplayRole || role == Qt::EditRole ) + if (role == Qt::DisplayRole || role == Qt::EditRole) { - if ( col == IFTREE_COL_PIPE_PATH || + if (col == IFTREE_COL_PIPE_PATH || col == IFTREE_COL_NAME || - col == IFTREE_COL_DESCRIPTION ) + col == IFTREE_COL_DESCRIPTION) { QMap<InterfaceTreeColumns, QVariant> * dataField = 0; - if ( ( dataField = storage->value(row, 0) ) != 0 && - dataField->contains(IFTREE_COL_PIPE_PATH) ) + if ((dataField = storage->value(row, 0)) != 0 && + dataField->contains(IFTREE_COL_PIPE_PATH)) { return dataField->value(IFTREE_COL_PIPE_PATH, QVariant()); } else return QString(device->name); } - else if ( col == IFTREE_COL_TYPE ) + else if (col == IFTREE_COL_TYPE) { return QVariant::fromValue((int)device->if_info.type); } } - else if ( role == Qt::CheckStateRole ) + else if (role == Qt::CheckStateRole) { - if ( col == IFTREE_COL_HIDDEN ) + if (col == IFTREE_COL_HIDDEN) { // Do not allow default capture interface to be hidden. - if ( ! g_strcmp0(prefs.capture_device, device->display_name) ) + if (! g_strcmp0(prefs.capture_device, device->display_name)) return QVariant(); /* Hidden is a de-selection, therefore inverted logic here */ @@ -523,7 +523,7 @@ QVariant InterfaceTreeCacheModel::data(const QModelIndex &index, int role) const #ifdef HAVE_LIBPCAP QModelIndex InterfaceTreeCacheModel::index(int row, int column, const QModelIndex &parent) const { - if ( row >= sourceModel->rowCount() && ( row - sourceModel->rowCount() ) < newDevices.count() ) + if (row >= sourceModel->rowCount() && (row - sourceModel->rowCount()) < newDevices.count()) { return createIndex(row, column, (void *)0); } @@ -540,7 +540,7 @@ void InterfaceTreeCacheModel::addDevice(const interface_t * newDevice) void InterfaceTreeCacheModel::deleteDevice(const QModelIndex &index) { - if ( ! index.isValid() ) + if (! index.isValid()) return; emit beginRemoveRows(QModelIndex(), index.row(), index.row()); @@ -548,12 +548,12 @@ void InterfaceTreeCacheModel::deleteDevice(const QModelIndex &index) int row = index.row(); /* device is in newDevices */ - if ( row >= sourceModel->rowCount() ) + if (row >= sourceModel->rowCount()) { int newDeviceIdx = row - sourceModel->rowCount(); newDevices.removeAt(newDeviceIdx); - if ( storage->contains(index.row()) ) + if (storage->contains(index.row())) storage->remove(index.row()); /* The storage array has to be resorted, if the index, that was removed @@ -562,10 +562,10 @@ void InterfaceTreeCacheModel::deleteDevice(const QModelIndex &index) * We must iterate using a list, not an iterator, otherwise the change * will fold on itself. */ QList<int> storageKeys = storage->keys(); - for ( int i = 0; i < storageKeys.size(); ++i ) + for (int i = 0; i < storageKeys.size(); ++i) { int key = storageKeys.at(i); - if ( key > index.row() ) + if (key > index.row()) { storage->insert(key - 1, storage->value(key)); storage->remove(key); |