Whitespace and coding style updates

Another futile attempt to cleanup the code and make coding style and
whitespace consistent. I tried to add a file that describes the key points
of our coding style. I have no illusions that this will help the least
bit...

This commit should ONLY change whitespace

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-01-16 11:50:56 +07:00
parent 3387ccc6f6
commit a27f67c026
28 changed files with 387 additions and 323 deletions

63
CodingStyle Normal file
View file

@ -0,0 +1,63 @@
- all indentation is tabs (set to 8 char) with the exception of
continuation lines that are alligned with tabs and then spaces
- all keywords followed by a '(' have a space in between
if (condition)
for (i = 0; i < 5; i++)
- function calls do NOT have a space between their name and argument
i = some_function(argument);
- usually there is no space on the inside of parenthesis (see examples
above)
- function / method implementations have their opening curly braces in
column 1
- all other opening curly braces follow at the end of the line, with a
space separating them:
if (condition) {
dosomething();
}
- both sides of an if / else clause either use or do not use curly braces:
if (condition)
i = 4;
else
j = 6;
if (condition) {
i = 6;
} else {
i = 4;
j = 6;
}
- use space to make visual separation easier
a = b + 3 + e / 4;
- continuation lines have the operator / comma at the end
if (very_long_conditiont_1 ||
condition_2)
b = a + (c + d +
f + z);
- unfortunate inconsistency:
-- C code usually uses underscores to structure names
variable_in_C
-- C++ code usually uses camelCase
variableInCPlusPlus
where the two meet, use your best judgment and go for best consistency
(i.e., where does the variable "originate")

View file

@ -132,7 +132,7 @@ struct divecomputer* fake_dc(struct divecomputer* dc)
/* we try for a sane slope, but bow to the insanity of /* we try for a sane slope, but bow to the insanity of
* the user supplied data */ * the user supplied data */
fill_samples_no_avg(fake, max_d, max_t, MAX(2.0 * max_d / max_t, 5000.0 / 60)); fill_samples_no_avg(fake, max_d, max_t, MAX(2.0 * max_d / max_t, 5000.0 / 60));
if(fake[3].time.seconds == 0) { // just a 4 point profile if (fake[3].time.seconds == 0) { // just a 4 point profile
fakedc.samples = 4; fakedc.samples = 4;
fake[3].time.seconds = max_t; fake[3].time.seconds = max_t;
} }

View file

@ -1628,10 +1628,10 @@ void parse_xml_buffer(const char *url, const char *buffer, int size,
extern int dm4_events(void *handle, int columns, char **data, char **column) extern int dm4_events(void *handle, int columns, char **data, char **column)
{ {
event_start(); event_start();
if(data[1]) if (data[1])
cur_event.time.seconds = atoi(data[1]); cur_event.time.seconds = atoi(data[1]);
if(data[2]) { if (data[2]) {
switch (atoi(data[2])) { switch (atoi(data[2])) {
case 1: case 1:
/* 1 Mandatory Safety Stop */ /* 1 Mandatory Safety Stop */
@ -1728,7 +1728,7 @@ extern int dm4_events(void *handle, int columns, char **data, char **column)
extern int dm4_tags(void *handle, int columns, char **data, char **column) extern int dm4_tags(void *handle, int columns, char **data, char **column)
{ {
if(data[0]) if (data[0])
taglist_add_tag(cur_dive->tag_list, data[0]); taglist_add_tag(cur_dive->tag_list, data[0]);
return 0; return 0;
@ -1874,7 +1874,7 @@ int parse_dm4_buffer(const char *url, const char *buffer, int size,
retval = sqlite3_open(url, &handle); retval = sqlite3_open(url, &handle);
if(retval) { if (retval) {
fprintf(stderr, translate("gettextFromC","Database connection failed '%s'.\n"), url); fprintf(stderr, translate("gettextFromC","Database connection failed '%s'.\n"), url);
return 1; return 1;
} }

View file

@ -1097,7 +1097,7 @@ static void calculate_ndl_tts(double tissue_tolerance, struct plot_data *entry,
/* If we don't have a ceiling yet, calculate ndl. Don't try to calculate /* If we don't have a ceiling yet, calculate ndl. Don't try to calculate
* a ndl for lower values than 3m it would take forever */ * a ndl for lower values than 3m it would take forever */
if (next_stop == 0) { if (next_stop == 0) {
if(entry->depth < 3000) { if (entry->depth < 3000) {
entry->ndl = max_ndl; entry->ndl = max_ndl;
return; return;
} }
@ -1440,10 +1440,10 @@ static void plot_string(struct plot_data *entry, char *buf, int bufsize,
depthvalue = get_depth_units(entry->ceiling, NULL, &depth_unit); depthvalue = get_depth_units(entry->ceiling, NULL, &depth_unit);
memcpy(buf2, buf, bufsize); memcpy(buf2, buf, bufsize);
snprintf(buf, bufsize, translate("gettextFromC","%s\nCalculated ceiling %.0f %s"), buf2, depthvalue, depth_unit); snprintf(buf, bufsize, translate("gettextFromC","%s\nCalculated ceiling %.0f %s"), buf2, depthvalue, depth_unit);
if (prefs.calc_all_tissues){ if (prefs.calc_all_tissues) {
int k; int k;
for (k=0; k<16; k++){ for (k=0; k<16; k++) {
if (entry->ceilings[k]){ if (entry->ceilings[k]) {
depthvalue = get_depth_units(entry->ceilings[k], NULL, &depth_unit); depthvalue = get_depth_units(entry->ceilings[k], NULL, &depth_unit);
memcpy(buf2, buf, bufsize); memcpy(buf2, buf, bufsize);
snprintf(buf, bufsize, translate("gettextFromC","%s\nTissue %.0fmin: %.0f %s"), buf2, buehlmann_N2_t_halflife[k], depthvalue, depth_unit); snprintf(buf, bufsize, translate("gettextFromC","%s\nTissue %.0fmin: %.0f %s"), buf2, buehlmann_N2_t_halflife[k], depthvalue, depth_unit);

View file

@ -23,9 +23,9 @@ void Class::updateModel() \
QStringList list; \ QStringList list; \
struct dive* dive; \ struct dive* dive; \
int i = 0; \ int i = 0; \
for_each_dive(i, dive){ \ for_each_dive(i, dive) { \
QString buddy(dive->diveStructMember); \ QString buddy(dive->diveStructMember); \
if (!list.contains(buddy)){ \ if (!list.contains(buddy)) { \
list.append(buddy); \ list.append(buddy); \
} \ } \
} \ } \
@ -37,7 +37,7 @@ void BuddyCompletionModel::updateModel()
QSet<QString> set; QSet<QString> set;
struct dive* dive; struct dive* dive;
int i = 0; int i = 0;
for_each_dive(i, dive){ for_each_dive(i, dive) {
QString buddy(dive->buddy); QString buddy(dive->buddy);
foreach (const QString &value, buddy.split(",", QString::SkipEmptyParts)) { foreach (const QString &value, buddy.split(",", QString::SkipEmptyParts)) {
set.insert(value.trimmed()); set.insert(value.trimmed());
@ -52,7 +52,7 @@ CREATE_UPDATE_METHOD(SuitCompletionModel, suit);
void TagCompletionModel::updateModel() void TagCompletionModel::updateModel()
{ {
if(g_tag_list == NULL) if (g_tag_list == NULL)
return; return;
QStringList list; QStringList list;
struct tag_entry *current_tag_entry = g_tag_list->next; struct tag_entry *current_tag_entry = g_tag_list->next;

View file

@ -57,7 +57,7 @@ DiveListView::~DiveListView()
{ {
QSettings settings; QSettings settings;
settings.beginGroup("ListWidget"); settings.beginGroup("ListWidget");
for (int i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++){ for (int i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++) {
if (isColumnHidden(i)) if (isColumnHidden(i))
continue; continue;
settings.setValue(QString("colwidth%1").arg(i), columnWidth(i)); settings.setValue(QString("colwidth%1").arg(i), columnWidth(i));
@ -65,17 +65,18 @@ DiveListView::~DiveListView()
settings.endGroup(); settings.endGroup();
} }
void DiveListView::setupUi(){ void DiveListView::setupUi()
{
QSettings settings; QSettings settings;
static bool firstRun = true; static bool firstRun = true;
if(firstRun) if (firstRun)
backupExpandedRows(); backupExpandedRows();
settings.beginGroup("ListWidget"); settings.beginGroup("ListWidget");
/* if no width are set, use the calculated width for each column; /* if no width are set, use the calculated width for each column;
* for that to work we need to temporarily expand all rows */ * for that to work we need to temporarily expand all rows */
expandAll(); expandAll();
for (int i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++) { for (int i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++) {
if(isColumnHidden(i)) if (isColumnHidden(i))
continue; continue;
QVariant width = settings.value(QString("colwidth%1").arg(i)); QVariant width = settings.value(QString("colwidth%1").arg(i));
if (width.isValid()) if (width.isValid())
@ -84,7 +85,7 @@ void DiveListView::setupUi(){
setColumnWidth(i, 100); setColumnWidth(i, 100);
} }
settings.endGroup(); settings.endGroup();
if(firstRun) if (firstRun)
restoreExpandedRows(); restoreExpandedRows();
else else
collapseAll(); collapseAll();
@ -96,21 +97,23 @@ int DiveListView::lastVisibleColumn()
{ {
int lastColumn = -1; int lastColumn = -1;
for (int i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++) { for (int i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++) {
if(isColumnHidden(i)) if (isColumnHidden(i))
continue; continue;
lastColumn = i; lastColumn = i;
} }
return lastColumn; return lastColumn;
} }
void DiveListView::backupExpandedRows(){ void DiveListView::backupExpandedRows()
{
expandedRows.clear(); expandedRows.clear();
for(int i = 0; i < model()->rowCount(); i++) for(int i = 0; i < model()->rowCount(); i++)
if(isExpanded( model()->index(i, 0) )) if (isExpanded( model()->index(i, 0) ))
expandedRows.push_back(i); expandedRows.push_back(i);
} }
void DiveListView::restoreExpandedRows(){ void DiveListView::restoreExpandedRows()
{
setAnimated(false); setAnimated(false);
Q_FOREACH(const int &i, expandedRows) Q_FOREACH(const int &i, expandedRows)
setExpanded( model()->index(i, 0), true ); setExpanded( model()->index(i, 0), true );
@ -141,18 +144,18 @@ void DiveListView::rememberSelection()
void DiveListView::restoreSelection() void DiveListView::restoreSelection()
{ {
unselectDives(); unselectDives();
Q_FOREACH(dive_trip_t *trip, selectedDives.keys()){ Q_FOREACH(dive_trip_t *trip, selectedDives.keys()) {
QList<int> divesOnTrip = getDivesInTrip(trip); QList<int> divesOnTrip = getDivesInTrip(trip);
QList<int> selectedDivesOnTrip = selectedDives.values(trip); QList<int> selectedDivesOnTrip = selectedDives.values(trip);
// Trip was not selected, let's select single-dives. // Trip was not selected, let's select single-dives.
if (trip == NULL || divesOnTrip.count() != selectedDivesOnTrip.count()){ if (trip == NULL || divesOnTrip.count() != selectedDivesOnTrip.count()) {
Q_FOREACH(int i, selectedDivesOnTrip){ Q_FOREACH(int i, selectedDivesOnTrip) {
selectDive(i); selectDive(i);
} }
}else{ } else {
selectTrip(trip); selectTrip(trip);
Q_FOREACH(int i, selectedDivesOnTrip){ Q_FOREACH(int i, selectedDivesOnTrip) {
selectDive(i); selectDive(i);
} }
} }
@ -185,9 +188,9 @@ QList< dive_trip_t* > DiveListView::selectedTrips()
{ {
QModelIndexList indexes = selectionModel()->selectedRows(); QModelIndexList indexes = selectionModel()->selectedRows();
QList<dive_trip_t*> ret; QList<dive_trip_t*> ret;
Q_FOREACH(const QModelIndex& index, indexes){ Q_FOREACH(const QModelIndex& index, indexes) {
dive_trip_t *trip = static_cast<dive_trip_t*>(index.data(DiveTripModel::TRIP_ROLE).value<void*>()); dive_trip_t *trip = static_cast<dive_trip_t*>(index.data(DiveTripModel::TRIP_ROLE).value<void*>());
if(!trip) if (!trip)
continue; continue;
ret.push_back(trip); ret.push_back(trip);
} }
@ -196,7 +199,7 @@ QList< dive_trip_t* > DiveListView::selectedTrips()
void DiveListView::selectDive(int i, bool scrollto, bool toggle) void DiveListView::selectDive(int i, bool scrollto, bool toggle)
{ {
if( i == -1) if ( i == -1)
return; return;
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model()); QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
QModelIndexList match = m->match(m->index(0,0), DiveTripModel::DIVE_IDX, i, 2, Qt::MatchRecursive); QModelIndexList match = m->match(m->index(0,0), DiveTripModel::DIVE_IDX, i, 2, Qt::MatchRecursive);
@ -205,7 +208,7 @@ void DiveListView::selectDive(int i, bool scrollto, bool toggle)
flags = toggle ? QItemSelectionModel::Toggle : QItemSelectionModel::Select; flags = toggle ? QItemSelectionModel::Toggle : QItemSelectionModel::Select;
flags |= QItemSelectionModel::Rows; flags |= QItemSelectionModel::Rows;
selectionModel()->setCurrentIndex(idx, flags); selectionModel()->setCurrentIndex(idx, flags);
if(idx.parent().isValid()){ if (idx.parent().isValid()) {
setAnimated(false); setAnimated(false);
expand(idx.parent()); expand(idx.parent());
setAnimated(true); setAnimated(true);
@ -216,7 +219,7 @@ void DiveListView::selectDive(int i, bool scrollto, bool toggle)
void DiveListView::selectDives(const QList< int >& newDiveSelection) void DiveListView::selectDives(const QList< int >& newDiveSelection)
{ {
if(!newDiveSelection.count()) if (!newDiveSelection.count())
return; return;
disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
@ -233,24 +236,24 @@ void DiveListView::selectDives(const QList< int >& newDiveSelection)
QModelIndexList diveList; QModelIndexList diveList;
int firstSelectedDive = -1; int firstSelectedDive = -1;
/* context for temp. variables. */{ /* context for temp. variables. */ {
int i = 0; int i = 0;
struct dive *dive; struct dive *dive;
for_each_dive(i, dive){ for_each_dive(i, dive) {
dive->selected = newDiveSelection.contains(i) == true; dive->selected = newDiveSelection.contains(i) == true;
if(firstSelectedDive == -1 && dive->selected ){ if (firstSelectedDive == -1 && dive->selected ) {
firstSelectedDive = i; firstSelectedDive = i;
} }
} }
} }
select_dive(firstSelectedDive); select_dive(firstSelectedDive);
Q_FOREACH(int i, newDiveSelection){ Q_FOREACH(int i, newDiveSelection) {
diveList.append(m->match(m->index(0,0), DiveTripModel::DIVE_IDX, diveList.append(m->match(m->index(0,0), DiveTripModel::DIVE_IDX,
i, 2, Qt::MatchRecursive).first()); i, 2, Qt::MatchRecursive).first());
} }
Q_FOREACH(const QModelIndex& idx, diveList){ Q_FOREACH(const QModelIndex& idx, diveList) {
selectionModel()->select(idx, flags); selectionModel()->select(idx, flags);
if(idx.parent().isValid() && !isExpanded(idx.parent())){ if (idx.parent().isValid() && !isExpanded(idx.parent())) {
expand(idx.parent()); expand(idx.parent());
} }
} }
@ -273,7 +276,7 @@ void DiveListView::showSearchEdit()
bool DiveListView::eventFilter(QObject* , QEvent* event) bool DiveListView::eventFilter(QObject* , QEvent* event)
{ {
if(event->type() != QEvent::KeyPress) if (event->type() != QEvent::KeyPress)
return false; return false;
QKeyEvent *keyEv = static_cast<QKeyEvent*>(event); QKeyEvent *keyEv = static_cast<QKeyEvent*>(event);
if (keyEv->key() != Qt::Key_Escape) if (keyEv->key() != Qt::Key_Escape)
@ -301,13 +304,13 @@ void DiveListView::headerClicked(int i)
sortByColumn(i, currentOrder); sortByColumn(i, currentOrder);
} else { } else {
// clear the model, repopulate with new indexes. // clear the model, repopulate with new indexes.
if(currentLayout == DiveTripModel::TREE){ if (currentLayout == DiveTripModel::TREE) {
backupExpandedRows(); backupExpandedRows();
} }
reload(newLayout, false); reload(newLayout, false);
currentOrder = Qt::DescendingOrder; currentOrder = Qt::DescendingOrder;
sortByColumn(i, currentOrder); sortByColumn(i, currentOrder);
if (newLayout == DiveTripModel::TREE){ if (newLayout == DiveTripModel::TREE) {
restoreExpandedRows(); restoreExpandedRows();
} }
} }
@ -329,7 +332,7 @@ void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model()); QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
QAbstractItemModel *oldModel = m->sourceModel(); QAbstractItemModel *oldModel = m->sourceModel();
if (oldModel){ if (oldModel) {
oldModel->deleteLater(); oldModel->deleteLater();
} }
DiveTripModel *tripModel = new DiveTripModel(this); DiveTripModel *tripModel = new DiveTripModel(this);
@ -337,7 +340,7 @@ void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
m->setSourceModel(tripModel); m->setSourceModel(tripModel);
if(!forceSort) if (!forceSort)
return; return;
sortByColumn(sortColumn, currentOrder); sortByColumn(sortColumn, currentOrder);
@ -353,16 +356,16 @@ void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
} }
} }
setupUi(); setupUi();
if(selectedIndexes().count()){ if (selectedIndexes().count()) {
QModelIndex curr = selectedIndexes().first(); QModelIndex curr = selectedIndexes().first();
curr = curr.parent().isValid() ? curr.parent() : curr; curr = curr.parent().isValid() ? curr.parent() : curr;
if(!isExpanded(curr)){ if (!isExpanded(curr)) {
setAnimated(false); setAnimated(false);
expand(curr); expand(curr);
setAnimated(true); setAnimated(true);
} }
} }
if(currentLayout == DiveTripModel::TREE){ if (currentLayout == DiveTripModel::TREE) {
fixMessyQtModelBehaviour(); fixMessyQtModelBehaviour();
} }
} }
@ -644,7 +647,7 @@ void DiveListView::markDiveInvalid()
} }
mark_divelist_changed(true); mark_divelist_changed(true);
mainWindow()->refreshDisplay(); mainWindow()->refreshDisplay();
if(prefs.display_invalid_dives == false) { if (prefs.display_invalid_dives == false) {
clearSelection(); clearSelection();
// select top dive that isn't marked invalid // select top dive that isn't marked invalid
rememberSelection(); rememberSelection();
@ -675,7 +678,7 @@ void DiveListView::deleteDive()
} }
mark_divelist_changed(true); mark_divelist_changed(true);
mainWindow()->refreshDisplay(); mainWindow()->refreshDisplay();
if(lastDiveNr != -1){ if (lastDiveNr != -1) {
clearSelection(); clearSelection();
selectDive(lastDiveNr); selectDive(lastDiveNr);
rememberSelection(); rememberSelection();
@ -754,7 +757,7 @@ void DiveListView::saveSelectedDivesAs()
settings.beginGroup("FileDialog"); settings.beginGroup("FileDialog");
if (settings.contains("LastDir")) { if (settings.contains("LastDir")) {
if(QDir::setCurrent(settings.value("LastDir").toString())) { if (QDir::setCurrent(settings.value("LastDir").toString())) {
lastDir = settings.value("LastDir").toString(); lastDir = settings.value("LastDir").toString();
} }
} }

View file

@ -259,7 +259,7 @@ void DivePlannerGraphics::keyLeftAction()
break; break;
} }
} }
if(nextStep) if (nextStep)
continue; continue;
dp.time -= 60; dp.time -= 60;
@ -287,7 +287,7 @@ void DivePlannerGraphics::keyRightAction()
break; break;
} }
} }
if(nextStep) if (nextStep)
continue; continue;
dp.time += 60; dp.time += 60;
@ -299,7 +299,7 @@ void DivePlannerGraphics::keyRightAction()
void DivePlannerGraphics::keyDeleteAction() void DivePlannerGraphics::keyDeleteAction()
{ {
int selCount = scene()->selectedItems().count(); int selCount = scene()->selectedItems().count();
if(selCount) { if (selCount) {
QVector<int> selectedIndexes; QVector<int> selectedIndexes;
Q_FOREACH(QGraphicsItem *i, scene()->selectedItems()) { Q_FOREACH(QGraphicsItem *i, scene()->selectedItems()) {
if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler*>(i)) { if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler*>(i)) {
@ -599,7 +599,7 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event)
depthString->setPos(fromPercent(1, Qt::Horizontal), ypos); depthString->setPos(fromPercent(1, Qt::Horizontal), ypos);
timeString->setPos(xpos+1, fromPercent(95, Qt::Vertical)); timeString->setPos(xpos+1, fromPercent(95, Qt::Vertical));
if(isPointOutOfBoundaries(mappedPos)) if (isPointOutOfBoundaries(mappedPos))
return; return;
depthString->setText(get_depth_string(depthLine->valueAt(mappedPos), true, false)); depthString->setText(get_depth_string(depthLine->valueAt(mappedPos), true, false));
@ -665,8 +665,7 @@ bool DivePlannerGraphics::isPointOutOfBoundaries(const QPointF& point)
if (xpos > timeLine->maximum() || if (xpos > timeLine->maximum() ||
xpos < timeLine->minimum() || xpos < timeLine->minimum() ||
ypos > depthLine->maximum() || ypos > depthLine->maximum() ||
ypos < depthLine->minimum()) ypos < depthLine->minimum()) {
{
return true; return true;
} }
return false; return false;
@ -680,7 +679,7 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event)
} }
QPointF mappedPos = mapToScene(event->pos()); QPointF mappedPos = mapToScene(event->pos());
if (event->button() == Qt::LeftButton){ if (event->button() == Qt::LeftButton) {
Q_FOREACH(QGraphicsItem *item, scene()->items(mappedPos, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, transform())) { Q_FOREACH(QGraphicsItem *item, scene()->items(mappedPos, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, transform())) {
if (DiveHandler *h = qgraphicsitem_cast<DiveHandler*>(item)) { if (DiveHandler *h = qgraphicsitem_cast<DiveHandler*>(item)) {
activeDraggedHandler = h; activeDraggedHandler = h;
@ -724,7 +723,7 @@ void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
GasSelectionModel *model = GasSelectionModel::instance(); GasSelectionModel *model = GasSelectionModel::instance();
model->repopulate(); model->repopulate();
int rowCount = model->rowCount(); int rowCount = model->rowCount();
for(int i = 0; i < rowCount; i++){ for(int i = 0; i < rowCount; i++) {
QAction *action = new QAction(&m); QAction *action = new QAction(&m);
action->setText( model->data(model->index(i, 0),Qt::DisplayRole).toString()); action->setText( model->data(model->index(i, 0),Qt::DisplayRole).toString());
connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas())); connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas()));
@ -922,7 +921,7 @@ Button::Button(QObject* parent, QGraphicsItem *itemParent): QObject(parent), QGr
void Button::setPixmap(const QPixmap& pixmap) void Button::setPixmap(const QPixmap& pixmap)
{ {
icon->setPixmap(pixmap); icon->setPixmap(pixmap);
if(pixmap.isNull()) if (pixmap.isNull())
icon->hide(); icon->hide();
else else
icon->show(); icon->show();
@ -933,7 +932,7 @@ void Button::setPixmap(const QPixmap& pixmap)
void Button::setText(const QString& t) void Button::setText(const QString& t)
{ {
text->setText(t); text->setText(t);
if(icon->pixmap().isNull()) { if (icon->pixmap().isNull()) {
icon->hide(); icon->hide();
text->setPos(0,0); text->setPos(0,0);
} else { } else {
@ -1043,16 +1042,16 @@ int DivePlannerPointsModel::columnCount(const QModelIndex& parent) const
QVariant DivePlannerPointsModel::data(const QModelIndex& index, int role) const QVariant DivePlannerPointsModel::data(const QModelIndex& index, int role) const
{ {
if(role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
divedatapoint p = divepoints.at(index.row()); divedatapoint p = divepoints.at(index.row());
switch(index.column()) { switch (index.column()) {
case CCSETPOINT: return (double) p.po2 / 1000; case CCSETPOINT: return (double) p.po2 / 1000;
case DEPTH: return rint(get_depth_units(p.depth, NULL, NULL)); case DEPTH: return rint(get_depth_units(p.depth, NULL, NULL));
case DURATION: return p.time / 60; case DURATION: return p.time / 60;
case GAS: return dpGasToStr(p); case GAS: return dpGasToStr(p);
} }
} else if (role == Qt::DecorationRole) { } else if (role == Qt::DecorationRole) {
switch(index.column()) { switch (index.column()) {
case REMOVE : return QIcon(":trash"); case REMOVE : return QIcon(":trash");
} }
} else if (role == Qt::FontRole) { } else if (role == Qt::FontRole) {
@ -1065,9 +1064,9 @@ bool DivePlannerPointsModel::setData(const QModelIndex& index, const QVariant& v
{ {
int o2 = 0; int o2 = 0;
int he = 0; int he = 0;
if(role == Qt::EditRole) { if (role == Qt::EditRole) {
divedatapoint& p = divepoints[index.row()]; divedatapoint& p = divepoints[index.row()];
switch(index.column()) { switch (index.column()) {
case DEPTH: p.depth = units_to_depth(value.toInt()); break; case DEPTH: p.depth = units_to_depth(value.toInt()); break;
case DURATION: p.time = value.toInt() * 60; break; case DURATION: p.time = value.toInt() * 60; break;
case CCSETPOINT: { case CCSETPOINT: {
@ -1093,7 +1092,7 @@ bool DivePlannerPointsModel::setData(const QModelIndex& index, const QVariant& v
QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orientation, int role) const
{ {
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
switch(section) { switch (section) {
case DEPTH: return tr("Final Depth"); case DEPTH: return tr("Final Depth");
case DURATION: return tr("Duration"); case DURATION: return tr("Duration");
case GAS: return tr("Used Gas"); case GAS: return tr("Used Gas");
@ -1197,7 +1196,7 @@ bool DivePlannerPointsModel::addGas(int o2, int he)
int DivePlannerPointsModel::addStop(int milimeters, int seconds, int o2, int he, int ccpoint) int DivePlannerPointsModel::addStop(int milimeters, int seconds, int o2, int he, int ccpoint)
{ {
int row = divepoints.count(); int row = divepoints.count();
if (seconds == 0 && milimeters == 0 && row != 0){ if (seconds == 0 && milimeters == 0 && row != 0) {
/* this is only possible if the user clicked on the 'plus' sign on the DivePoints Table */ /* this is only possible if the user clicked on the 'plus' sign on the DivePoints Table */
struct divedatapoint& t = divepoints.last(); struct divedatapoint& t = divepoints.last();
milimeters = t.depth; milimeters = t.depth;
@ -1542,7 +1541,7 @@ ExpanderGraphics::ExpanderGraphics(QGraphicsItem* parent): QGraphicsRectItem(par
//I need to bottom align the items, I need to make the 0,0 ( orgin ) to be //I need to bottom align the items, I need to make the 0,0 ( orgin ) to be
// the bottom of this item, so shift everything up. // the bottom of this item, so shift everything up.
QRectF r = childrenBoundingRect(); QRectF r = childrenBoundingRect();
Q_FOREACH(QGraphicsItem *i, childItems()){ Q_FOREACH(QGraphicsItem *i, childItems()) {
i->setPos(i->pos().x(), i->pos().y() - r.height()); i->setPos(i->pos().x(), i->pos().y() - r.height());
} }
setScale(0.7); setScale(0.7);

View file

@ -32,7 +32,7 @@ struct mydescriptor {
unsigned int model; unsigned int model;
}; };
namespace DownloadFromDcGlobal{ namespace DownloadFromDcGlobal {
const char *err_string; const char *err_string;
}; };

View file

@ -51,7 +51,7 @@ GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0), edit
setProjection(Marble::Spherical); setProjection(Marble::Spherical);
setAnimationsEnabled(true); setAnimationsEnabled(true);
Q_FOREACH(AbstractFloatItem *i, floatItems()){ Q_FOREACH(AbstractFloatItem *i, floatItems()) {
i->setVisible(false); i->setVisible(false);
} }
@ -82,13 +82,13 @@ bool GlobeGPS::eventFilter(QObject *obj, QEvent *ev)
// This disables the Marble's Context Menu // This disables the Marble's Context Menu
// we need to move this to our 'contextMenuEvent' // we need to move this to our 'contextMenuEvent'
// if we plan to do a different one in the future. // if we plan to do a different one in the future.
if (ev->type() == QEvent::ContextMenu){ if (ev->type() == QEvent::ContextMenu) {
contextMenuEvent(static_cast<QContextMenuEvent*>(ev)); contextMenuEvent(static_cast<QContextMenuEvent*>(ev));
return true; return true;
} }
if (ev->type() == QEvent::MouseButtonPress){ if (ev->type() == QEvent::MouseButtonPress) {
QMouseEvent *e = static_cast<QMouseEvent*>(ev); QMouseEvent *e = static_cast<QMouseEvent*>(ev);
if(e->button() == Qt::RightButton) if (e->button() == Qt::RightButton)
return true; return true;
} }
return QObject::eventFilter(obj,ev ); return QObject::eventFilter(obj,ev );
@ -145,7 +145,7 @@ void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
selectedDiveIds.push_back(idx); selectedDiveIds.push_back(idx);
} }
if(selectedDiveIds.empty()) if (selectedDiveIds.empty())
return; return;
if (clear) { if (clear) {
mainWindow()->dive_list()->unselectDives(); mainWindow()->dive_list()->unselectDives();
@ -258,8 +258,8 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U
/* change everything on the selection. */ /* change everything on the selection. */
int i; int i;
struct dive* dive; struct dive* dive;
for_each_dive(i, dive){ for_each_dive(i, dive) {
if(!dive->selected) if (!dive->selected)
continue; continue;
dive->latitude.udeg = lrint(lat * 1000000.0); dive->latitude.udeg = lrint(lat * 1000000.0);
dive->longitude.udeg = lrint(lon * 1000000.0); dive->longitude.udeg = lrint(lon * 1000000.0);

View file

@ -132,7 +132,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
" background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," " background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
" stop: 0 #E0E0E0, stop: 1 #FFFFFF);" " stop: 0 #E0E0E0, stop: 1 #FFFFFF);"
"}"); "}");
Q_FOREACH(QGroupBox *box, findChildren<QGroupBox*>()){ Q_FOREACH(QGroupBox *box, findChildren<QGroupBox*>()) {
box->setStyleSheet(gnomeCss); box->setStyleSheet(gnomeCss);
} }
@ -141,7 +141,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
QSettings s; QSettings s;
s.beginGroup("cylinders_dialog"); s.beginGroup("cylinders_dialog");
for(int i = 0; i < CylindersModel::COLUMNS; i++){ for(int i = 0; i < CylindersModel::COLUMNS; i++) {
if ((i == CylindersModel::REMOVE) || (i == CylindersModel::TYPE)) if ((i == CylindersModel::REMOVE) || (i == CylindersModel::TYPE))
continue; continue;
bool checked = s.value(QString("column%1_hidden").arg(i)).toBool(); bool checked = s.value(QString("column%1_hidden").arg(i)).toBool();
@ -159,7 +159,7 @@ MainTab::~MainTab()
{ {
QSettings s; QSettings s;
s.beginGroup("cylinders_dialog"); s.beginGroup("cylinders_dialog");
for(int i = 0; i < CylindersModel::COLUMNS; i++){ for(int i = 0; i < CylindersModel::COLUMNS; i++) {
if ((i == CylindersModel::REMOVE) || (i == CylindersModel::TYPE)) if ((i == CylindersModel::REMOVE) || (i == CylindersModel::TYPE))
continue; continue;
s.setValue(QString("column%1_hidden").arg(i), ui.cylinders->view()->isColumnHidden(i)); s.setValue(QString("column%1_hidden").arg(i), ui.cylinders->view()->isColumnHidden(i));
@ -172,9 +172,9 @@ void MainTab::toggleTriggeredColumn()
int col = action->data().toInt(); int col = action->data().toInt();
QTableView *view = ui.cylinders->view(); QTableView *view = ui.cylinders->view();
if(action->isChecked()){ if (action->isChecked()) {
view->showColumn(col); view->showColumn(col);
if(view->columnWidth(col) <= 15) if (view->columnWidth(col) <= 15)
view->setColumnWidth(col, 80); view->setColumnWidth(col, 80);
} }
else else
@ -548,14 +548,14 @@ void MainTab::updateDiveInfo(int dive)
void MainTab::addCylinder_clicked() void MainTab::addCylinder_clicked()
{ {
if(editMode == NONE) if (editMode == NONE)
enableEdition(); enableEdition();
cylindersModel->add(); cylindersModel->add();
} }
void MainTab::addWeight_clicked() void MainTab::addWeight_clicked()
{ {
if(editMode == NONE) if (editMode == NONE)
enableEdition(); enableEdition();
weightModel->add(); weightModel->add();
} }
@ -655,7 +655,7 @@ void MainTab::acceptChanges()
} }
int scrolledBy = mainWindow()->dive_list()->verticalScrollBar()->sliderPosition(); int scrolledBy = mainWindow()->dive_list()->verticalScrollBar()->sliderPosition();
resetPallete(); resetPallete();
if(editMode == ADD || editMode == MANUALLY_ADDED_DIVE){ if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
mainWindow()->dive_list()->unselectDives(); mainWindow()->dive_list()->unselectDives();
struct dive *d = get_dive(dive_table.nr -1 ); struct dive *d = get_dive(dive_table.nr -1 );
// mark the dive as remembered (abusing the selected flag) // mark the dive as remembered (abusing the selected flag)
@ -663,7 +663,7 @@ void MainTab::acceptChanges()
d->selected = true; d->selected = true;
sort_table(&dive_table); sort_table(&dive_table);
int i = 0; int i = 0;
for_each_dive(i,d){ for_each_dive(i,d) {
if (d->selected) { if (d->selected) {
d->selected = false; d->selected = false;
break; break;
@ -715,7 +715,7 @@ void MainTab::rejectChanges()
tabBar()->setTabIcon(1, QIcon()); // Equipment tabBar()->setTabIcon(1, QIcon()); // Equipment
mainWindow()->dive_list()->setEnabled(true); mainWindow()->dive_list()->setEnabled(true);
if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1){ if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) {
ui.notes->setText(notesBackup[NULL].notes ); ui.notes->setText(notesBackup[NULL].notes );
ui.location->setText(notesBackup[NULL].location); ui.location->setText(notesBackup[NULL].location);
} else { } else {
@ -823,7 +823,7 @@ void MainTab::rejectChanges()
} \ } \
} while(0) } while(0)
void markChangedWidget(QWidget *w){ void markChangedWidget(QWidget *w) {
QPalette p; QPalette p;
qreal h, s, l, a; qreal h, s, l, a;
qApp->palette().color(QPalette::Text).getHslF(&h, &s, &l, &a); qApp->palette().color(QPalette::Text).getHslF(&h, &s, &l, &a);
@ -890,12 +890,12 @@ void MainTab::on_location_textChanged(const QString& text)
// we are editing a trip // we are editing a trip
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips().begin(); dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips().begin();
EDIT_TEXT(currentTrip->location, text); EDIT_TEXT(currentTrip->location, text);
} else if (editMode == DIVE || editMode == ADD){ } else if (editMode == DIVE || editMode == ADD) {
if (!ui.coordinates->isModified() || if (!ui.coordinates->isModified() ||
ui.coordinates->text().trimmed().isEmpty()) { ui.coordinates->text().trimmed().isEmpty()) {
struct dive* dive; struct dive* dive;
int i = 0; int i = 0;
for_each_dive(i, dive){ for_each_dive(i, dive) {
QString location(dive->location); QString location(dive->location);
if (location == text && if (location == text &&
(dive->latitude.udeg || dive->longitude.udeg)) { (dive->latitude.udeg || dive->longitude.udeg)) {

View file

@ -112,7 +112,7 @@ void MainWindow::on_actionNew_triggered()
void MainWindow::on_actionOpen_triggered() void MainWindow::on_actionOpen_triggered()
{ {
if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING ||
ui.InfoWidget->isEditing()) { ui.InfoWidget->isEditing()) {
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before opening a new file.")); QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before opening a new file."));
return; return;
@ -125,7 +125,8 @@ void MainWindow::on_actionOpen_triggered()
loadFiles( QStringList() << filename ); loadFiles( QStringList() << filename );
} }
QTabWidget *MainWindow::tabWidget(){ QTabWidget *MainWindow::tabWidget()
{
return ui.tabWidget; return ui.tabWidget;
} }
void MainWindow::on_actionSave_triggered() void MainWindow::on_actionSave_triggered()
@ -153,7 +154,7 @@ void MainWindow::cleanUpEmpty()
void MainWindow::on_actionClose_triggered() void MainWindow::on_actionClose_triggered()
{ {
if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING ||
ui.InfoWidget->isEditing()) { ui.InfoWidget->isEditing()) {
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before closing the file.")); QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before closing the file."));
return; return;
@ -223,7 +224,7 @@ void MainWindow::enableDcShortcuts()
void MainWindow::on_actionDivePlanner_triggered() void MainWindow::on_actionDivePlanner_triggered()
{ {
if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING ||
ui.InfoWidget->isEditing()) { ui.InfoWidget->isEditing()) {
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to plan a dive.")); QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to plan a dive."));
return; return;
@ -250,7 +251,7 @@ void MainWindow::on_actionPreferences_triggered()
void MainWindow::on_actionQuit_triggered() void MainWindow::on_actionQuit_triggered()
{ {
if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING ||
ui.InfoWidget->isEditing()) { ui.InfoWidget->isEditing()) {
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before closing the file.")); QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before closing the file."));
return; return;
@ -286,7 +287,7 @@ void MainWindow::on_actionEditDeviceNames_triggered()
void MainWindow::on_actionAddDive_triggered() void MainWindow::on_actionAddDive_triggered()
{ {
if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING ||
ui.InfoWidget->isEditing()) { ui.InfoWidget->isEditing()) {
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to add a dive.")); QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to add a dive."));
return; return;
@ -378,15 +379,15 @@ void MainWindow::on_infoProfileSplitter_splitterMoved(int pos, int idx)
void MainWindow::on_actionViewList_triggered() void MainWindow::on_actionViewList_triggered()
{ {
beginChangeState(LIST_MAXIMIZED); beginChangeState(LIST_MAXIMIZED);
ui.listGlobeSplitter->setSizes( BEHAVIOR << EXPANDED << COLLAPSED); ui.listGlobeSplitter->setSizes(BEHAVIOR << EXPANDED << COLLAPSED);
ui.mainSplitter->setSizes( BEHAVIOR << COLLAPSED << EXPANDED); ui.mainSplitter->setSizes(BEHAVIOR << COLLAPSED << EXPANDED);
} }
void MainWindow::on_actionViewProfile_triggered() void MainWindow::on_actionViewProfile_triggered()
{ {
beginChangeState(PROFILE_MAXIMIZED); beginChangeState(PROFILE_MAXIMIZED);
ui.infoProfileSplitter->setSizes(BEHAVIOR << COLLAPSED << EXPANDED); ui.infoProfileSplitter->setSizes(BEHAVIOR << COLLAPSED << EXPANDED);
ui.mainSplitter->setSizes( BEHAVIOR << EXPANDED << COLLAPSED); ui.mainSplitter->setSizes(BEHAVIOR << EXPANDED << COLLAPSED);
redrawProfile(); redrawProfile();
} }
@ -394,7 +395,7 @@ void MainWindow::on_actionViewInfo_triggered()
{ {
beginChangeState(INFO_MAXIMIZED); beginChangeState(INFO_MAXIMIZED);
ui.infoProfileSplitter->setSizes(BEHAVIOR << EXPANDED << COLLAPSED); ui.infoProfileSplitter->setSizes(BEHAVIOR << EXPANDED << COLLAPSED);
ui.mainSplitter->setSizes( BEHAVIOR << EXPANDED << COLLAPSED); ui.mainSplitter->setSizes(BEHAVIOR << EXPANDED << COLLAPSED);
} }
void MainWindow::on_actionViewGlobe_triggered() void MainWindow::on_actionViewGlobe_triggered()
@ -411,51 +412,51 @@ void MainWindow::on_actionViewAll_triggered()
static QList<int> mainSizes; static QList<int> mainSizes;
const int appH = qApp->desktop()->size().height(); const int appH = qApp->desktop()->size().height();
const int appW = qApp->desktop()->size().width(); const int appW = qApp->desktop()->size().width();
if (mainSizes.empty()){ if (mainSizes.empty()) {
mainSizes.append( appH * 0.7 ); mainSizes.append(appH * 0.7);
mainSizes.append( appH * 0.3 ); mainSizes.append(appH * 0.3);
} }
static QList<int> infoProfileSizes; static QList<int> infoProfileSizes;
if (infoProfileSizes.empty()){ if (infoProfileSizes.empty()) {
infoProfileSizes.append( appW * 0.3 ); infoProfileSizes.append(appW * 0.3);
infoProfileSizes.append( appW * 0.7 ); infoProfileSizes.append(appW * 0.7);
} }
static QList<int> listGlobeSizes; static QList<int> listGlobeSizes;
if(listGlobeSizes.empty()){ if (listGlobeSizes.empty()) {
listGlobeSizes.append( appW * 0.7 ); listGlobeSizes.append(appW * 0.7);
listGlobeSizes.append( appW * 0.3 ); listGlobeSizes.append(appW * 0.3);
} }
QSettings settings; QSettings settings;
settings.beginGroup("MainWindow"); settings.beginGroup("MainWindow");
if (settings.value("mainSplitter").isValid()){ if (settings.value("mainSplitter").isValid()) {
ui.mainSplitter->restoreState(settings.value("mainSplitter").toByteArray()); ui.mainSplitter->restoreState(settings.value("mainSplitter").toByteArray());
ui.infoProfileSplitter->restoreState(settings.value("infoProfileSplitter").toByteArray()); ui.infoProfileSplitter->restoreState(settings.value("infoProfileSplitter").toByteArray());
ui.listGlobeSplitter->restoreState(settings.value("listGlobeSplitter").toByteArray()); ui.listGlobeSplitter->restoreState(settings.value("listGlobeSplitter").toByteArray());
if(ui.mainSplitter->sizes().first() == 0 || ui.mainSplitter->sizes().last() == 0) if (ui.mainSplitter->sizes().first() == 0 || ui.mainSplitter->sizes().last() == 0)
ui.mainSplitter->setSizes(mainSizes); ui.mainSplitter->setSizes(mainSizes);
if(ui.infoProfileSplitter->sizes().first() == 0 || ui.infoProfileSplitter->sizes().last() == 0) if (ui.infoProfileSplitter->sizes().first() == 0 || ui.infoProfileSplitter->sizes().last() == 0)
ui.infoProfileSplitter->setSizes(infoProfileSizes); ui.infoProfileSplitter->setSizes(infoProfileSizes);
if(ui.listGlobeSplitter->sizes().first() == 0 || ui.listGlobeSplitter->sizes().last() == 0) if (ui.listGlobeSplitter->sizes().first() == 0 || ui.listGlobeSplitter->sizes().last() == 0)
ui.listGlobeSplitter->setSizes(listGlobeSizes); ui.listGlobeSplitter->setSizes(listGlobeSizes);
} else { } else {
ui.mainSplitter->setSizes( mainSizes ); ui.mainSplitter->setSizes(mainSizes);
ui.infoProfileSplitter->setSizes(infoProfileSizes); ui.infoProfileSplitter->setSizes(infoProfileSizes);
ui.listGlobeSplitter->setSizes(listGlobeSizes); ui.listGlobeSplitter->setSizes(listGlobeSizes);
} }
redrawProfile(); redrawProfile();
} }
void MainWindow::beginChangeState(CurrentState s){ void MainWindow::beginChangeState(CurrentState s) {
if (state == VIEWALL && state != s){ if (state == VIEWALL && state != s) {
saveSplitterSizes(); saveSplitterSizes();
} }
state = s; state = s;
} }
void MainWindow::saveSplitterSizes(){ void MainWindow::saveSplitterSizes() {
QSettings settings; QSettings settings;
settings.beginGroup("MainWindow"); settings.beginGroup("MainWindow");
settings.setValue("mainSplitter", ui.mainSplitter->saveState()); settings.setValue("mainSplitter", ui.mainSplitter->saveState());
@ -481,8 +482,7 @@ void MainWindow::on_actionFullScreen_triggered(bool checked)
{ {
if (checked) { if (checked) {
setWindowState(windowState() | Qt::WindowFullScreen); setWindowState(windowState() | Qt::WindowFullScreen);
} } else {
else {
setWindowState(windowState() & ~Qt::WindowFullScreen); setWindowState(windowState() & ~Qt::WindowFullScreen);
} }
} }
@ -504,7 +504,7 @@ void MainWindow::on_actionAboutSubsurface_triggered()
void MainWindow::on_actionUserManual_triggered() void MainWindow::on_actionUserManual_triggered()
{ {
if(!helpView){ if (!helpView) {
helpView = new UserManual(); helpView = new UserManual();
} }
helpView->show(); helpView->show();
@ -613,7 +613,7 @@ void MainWindow::initialUiSetup()
resize(sz); resize(sz);
state = (CurrentState) settings.value("lastState", 0).toInt(); state = (CurrentState) settings.value("lastState", 0).toInt();
switch(state){ switch (state) {
case VIEWALL: on_actionViewAll_triggered(); break; case VIEWALL: on_actionViewAll_triggered(); break;
case GLOBE_MAXIMIZED : on_actionViewGlobe_triggered(); break; case GLOBE_MAXIMIZED : on_actionViewGlobe_triggered(); break;
case INFO_MAXIMIZED : on_actionViewInfo_triggered(); break; case INFO_MAXIMIZED : on_actionViewInfo_triggered(); break;
@ -693,22 +693,21 @@ void MainWindow::writeSettings()
settings.setValue("maximized", isMaximized()); settings.setValue("maximized", isMaximized());
if (!isMaximized()) if (!isMaximized())
settings.setValue("size", size()); settings.setValue("size", size());
if (state == VIEWALL){ if (state == VIEWALL)
saveSplitterSizes(); saveSplitterSizes();
}
settings.endGroup(); settings.endGroup();
} }
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING ||
ui.InfoWidget->isEditing()) { ui.InfoWidget->isEditing()) {
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before closing the file.")); QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before closing the file."));
event->ignore(); event->ignore();
return; return;
} }
if (helpView && helpView->isVisible()){ if (helpView && helpView->isVisible()) {
helpView->close(); helpView->close();
helpView->deleteLater(); helpView->deleteLater();
} }
@ -754,7 +753,7 @@ void MainWindow::file_save_as(void)
tr("Subsurface XML files (*.ssrf *.xml *.XML)")); tr("Subsurface XML files (*.ssrf *.xml *.XML)"));
if (!filename.isNull() && !filename.isEmpty()) { if (!filename.isNull() && !filename.isEmpty()) {
if(ui.InfoWidget->isEditing()) if (ui.InfoWidget->isEditing())
ui.InfoWidget->acceptChanges(); ui.InfoWidget->acceptChanges();
save_dives(filename.toUtf8().data()); save_dives(filename.toUtf8().data());
@ -771,7 +770,7 @@ void MainWindow::file_save(void)
if (!existing_filename) if (!existing_filename)
return file_save_as(); return file_save_as();
if(ui.InfoWidget->isEditing()) if (ui.InfoWidget->isEditing())
ui.InfoWidget->acceptChanges(); ui.InfoWidget->acceptChanges();
current_default = prefs.default_filename; current_default = prefs.default_filename;
@ -885,7 +884,7 @@ void MainWindow::on_actionImportDiveLog_triggered()
void MainWindow::editCurrentDive() void MainWindow::editCurrentDive()
{ {
if(information()->isEditing() || DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING){ if (information()->isEditing() || DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) {
QMessageBox::warning(this, tr("Warning"), tr("First finish the current edition before trying to do another.")); QMessageBox::warning(this, tr("Warning"), tr("First finish the current edition before trying to do another."));
return; return;
} }
@ -893,15 +892,14 @@ void MainWindow::editCurrentDive()
struct dive *d = current_dive; struct dive *d = current_dive;
QString defaultDC(d->dc.model); QString defaultDC(d->dc.model);
DivePlannerPointsModel::instance()->clear(); DivePlannerPointsModel::instance()->clear();
if (defaultDC == "manually added dive"){ if (defaultDC == "manually added dive") {
disableDcShortcuts(); disableDcShortcuts();
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); // Planner. ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); // Planner.
ui.infoPane->setCurrentIndex(MAINTAB); ui.infoPane->setCurrentIndex(MAINTAB);
DivePlannerPointsModel::instance()->loadFromDive(d); DivePlannerPointsModel::instance()->loadFromDive(d);
ui.InfoWidget->enableEdition(MainTab::MANUALLY_ADDED_DIVE); ui.InfoWidget->enableEdition(MainTab::MANUALLY_ADDED_DIVE);
} } else if (defaultDC == "planned dive") {
else if (defaultDC == "planned dive"){
disableDcShortcuts(); disableDcShortcuts();
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN);
ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); // Planner. ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); // Planner.

View file

@ -26,13 +26,14 @@ QSize DiveListDelegate::sizeHint(const QStyleOptionViewItem& option, const QMode
// Gets the index of the model in the currentRow and column. // Gets the index of the model in the currentRow and column.
// currCombo is defined below. // currCombo is defined below.
#define IDX( XX ) mymodel->index(currCombo.currRow, XX) #define IDX(_XX) mymodel->index(currCombo.currRow, (_XX))
static bool keyboardFinished = false; static bool keyboardFinished = false;
StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent): StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent):
QStyledItemDelegate(parent), QStyledItemDelegate(parent),
parentWidget(parent) parentWidget(parent)
{ {
} }
void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
@ -46,12 +47,12 @@ void StarWidgetsDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
return; return;
int rating = value.toInt(); int rating = value.toInt();
int deltaY = option.rect.height()/2 - StarWidget::starActive().height() /2 ; int deltaY = option.rect.height() / 2 - StarWidget::starActive().height() / 2 ;
painter->save(); painter->save();
painter->setRenderHint(QPainter::Antialiasing, true); painter->setRenderHint(QPainter::Antialiasing, true);
for(int i = 0; i < rating; i++) for (int i = 0; i < rating; i++)
painter->drawPixmap(option.rect.x() + i * IMG_SIZE + SPACING, option.rect.y() + deltaY, StarWidget::starActive()); painter->drawPixmap(option.rect.x() + i * IMG_SIZE + SPACING, option.rect.y() + deltaY, StarWidget::starActive());
for(int i = rating; i < TOTALSTARS; i++) for (int i = rating; i < TOTALSTARS; i++)
painter->drawPixmap(option.rect.x() + i * IMG_SIZE + SPACING, option.rect.y() + deltaY, StarWidget::starInactive()); painter->drawPixmap(option.rect.x() + i * IMG_SIZE + SPACING, option.rect.y() + deltaY, StarWidget::starInactive());
painter->restore(); painter->restore();
} }
@ -78,7 +79,7 @@ void ComboBoxDelegate::setEditorData(QWidget* editor, const QModelIndex& index)
c->setEditText(data); c->setEditText(data);
} }
struct CurrSelected{ struct CurrSelected {
QComboBox *comboEditor; QComboBox *comboEditor;
int currRow; int currRow;
QString activeText; QString activeText;
@ -129,7 +130,7 @@ void ComboBoxDelegate::testActivation(const QString& currText)
} }
// HACK, send a fake event so Qt thinks we hit 'enter' on the line edit. // HACK, send a fake event so Qt thinks we hit 'enter' on the line edit.
void ComboBoxDelegate::fakeActivation(){ void ComboBoxDelegate::fakeActivation() {
/* this test is needed because as soon as I show the selector, /* this test is needed because as soon as I show the selector,
* the first item gots selected, this sending an activated signal, * the first item gots selected, this sending an activated signal,
* calling this fakeActivation code and setting as the current, * calling this fakeActivation code and setting as the current,
@ -137,7 +138,7 @@ void ComboBoxDelegate::fakeActivation(){
* to false and be happy, because the next activation ( by click * to false and be happy, because the next activation ( by click
* or keypress) is real. * or keypress) is real.
*/ */
if(currCombo.ignoreSelection){ if (currCombo.ignoreSelection) {
currCombo.ignoreSelection = false; currCombo.ignoreSelection = false;
return; return;
} }
@ -150,7 +151,7 @@ void ComboBoxDelegate::fakeActivation(){
// we are on a QComboBox ( but not on a QLineEdit. // we are on a QComboBox ( but not on a QLineEdit.
void ComboBoxDelegate::fixTabBehavior() void ComboBoxDelegate::fixTabBehavior()
{ {
if(keyboardFinished){ if (keyboardFinished) {
setModelData(0,0,QModelIndex()); setModelData(0,0,QModelIndex());
} }
} }
@ -158,23 +159,22 @@ void ComboBoxDelegate::fixTabBehavior()
bool ComboBoxDelegate::eventFilter(QObject* object, QEvent* event) bool ComboBoxDelegate::eventFilter(QObject* object, QEvent* event)
{ {
// Reacts on Key_UP and Key_DOWN to show the QComboBox - list of choices. // Reacts on Key_UP and Key_DOWN to show the QComboBox - list of choices.
if (event->type() == QEvent::KeyPress || event->type() == QEvent::ShortcutOverride){ if (event->type() == QEvent::KeyPress || event->type() == QEvent::ShortcutOverride) {
if (object == currCombo.comboEditor){ // the 'LineEdit' part if (object == currCombo.comboEditor) { // the 'LineEdit' part
QKeyEvent *ev = static_cast<QKeyEvent*>(event); QKeyEvent *ev = static_cast<QKeyEvent*>(event);
if(ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down){ if (ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down) {
currCombo.ignoreSelection = true; currCombo.ignoreSelection = true;
currCombo.comboEditor->showPopup(); currCombo.comboEditor->showPopup();
} }
if(ev->key() == Qt::Key_Tab || ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return){ if (ev->key() == Qt::Key_Tab || ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return) {
currCombo.activeText = currCombo.comboEditor->currentText(); currCombo.activeText = currCombo.comboEditor->currentText();
keyboardFinished = true; keyboardFinished = true;
} }
} } else { // the 'Drop Down Menu' part.
else{ // the 'Drop Down Menu' part.
QKeyEvent *ev = static_cast<QKeyEvent*>(event); QKeyEvent *ev = static_cast<QKeyEvent*>(event);
if( ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return if (ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return ||
|| ev->key() == Qt::Key_Tab || ev->key() == Qt::Key_Backtab ev->key() == Qt::Key_Tab || ev->key() == Qt::Key_Backtab ||
|| ev->key() == Qt::Key_Escape){ ev->key() == Qt::Key_Escape) {
// treat Qt as a silly little boy - pretending that the key_return nwas pressed on the combo, // treat Qt as a silly little boy - pretending that the key_return nwas pressed on the combo,
// instead of the list of choices. this can be extended later for // instead of the list of choices. this can be extended later for
// other imputs, like tab navigation and esc. // other imputs, like tab navigation and esc.
@ -196,7 +196,7 @@ void ComboBoxDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionV
editor->setGeometry(defaultRect); editor->setGeometry(defaultRect);
} }
struct RevertCylinderData{ struct RevertCylinderData {
QString type; QString type;
int pressure; int pressure;
int size; int size;

View file

@ -64,7 +64,7 @@ void CleanerTableModel::setHeaderDataStrings(const QStringList& newHeaders)
CylindersModel::CylindersModel(QObject* parent): current(0), rows(0) CylindersModel::CylindersModel(QObject* parent): current(0), rows(0)
{ {
// enum{REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH}; // enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH};
setHeaderDataStrings( QStringList() << "" << tr("Type") << tr("Size") << tr("WorkPress") << tr("StartPress") << tr("EndPress") << trUtf8("O" UTF8_SUBSCRIPT_2 "%") << tr("He%") << tr("Switch at")); setHeaderDataStrings( QStringList() << "" << tr("Type") << tr("Size") << tr("WorkPress") << tr("StartPress") << tr("EndPress") << trUtf8("O" UTF8_SUBSCRIPT_2 "%") << tr("He%") << tr("Switch at"));
} }
@ -106,7 +106,7 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
break; break;
case Qt::DisplayRole: case Qt::DisplayRole:
case Qt::EditRole: case Qt::EditRole:
switch(index.column()) { switch (index.column()) {
case TYPE: case TYPE:
ret = QString(cyl->type.description); ret = QString(cyl->type.description);
break; break;
@ -166,7 +166,7 @@ cylinder_t* CylindersModel::cylinderAt(const QModelIndex& index)
void CylindersModel::passInData(const QModelIndex& index, const QVariant& value) void CylindersModel::passInData(const QModelIndex& index, const QVariant& value)
{ {
cylinder_t *cyl = cylinderAt(index); cylinder_t *cyl = cylinderAt(index);
switch(index.column()) { switch (index.column()) {
case SIZE: case SIZE:
if (cyl->type.size.mliter != value.toInt()) { if (cyl->type.size.mliter != value.toInt()) {
cyl->type.size.mliter = value.toInt(); cyl->type.size.mliter = value.toInt();
@ -194,7 +194,7 @@ bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, in
DivePlannerPointsModel::instance()->rememberTanks(); DivePlannerPointsModel::instance()->rememberTanks();
cylinder_t *cyl = cylinderAt(index); cylinder_t *cyl = cylinderAt(index);
switch(index.column()) { switch (index.column()) {
case TYPE: case TYPE:
if (!value.isNull()) { if (!value.isNull()) {
QByteArray ba = value.toByteArray(); QByteArray ba = value.toByteArray();
@ -391,7 +391,7 @@ QVariant WeightModel::data(const QModelIndex& index, int role) const
break; break;
case Qt::DisplayRole: case Qt::DisplayRole:
case Qt::EditRole: case Qt::EditRole:
switch(index.column()) { switch (index.column()) {
case TYPE: case TYPE:
ret = gettextFromC::instance()->tr(ws->description); ret = gettextFromC::instance()->tr(ws->description);
break; break;
@ -542,7 +542,7 @@ bool WeightModel::setData(const QModelIndex& index, const QVariant& value, int r
{ {
QString vString = value.toString(); QString vString = value.toString();
weightsystem_t *ws = &current->weightsystem[index.row()]; weightsystem_t *ws = &current->weightsystem[index.row()];
switch(index.column()) { switch (index.column()) {
case TYPE: case TYPE:
if (!value.isNull()) { if (!value.isNull()) {
if (!ws->description || gettextFromC::instance()->tr(ws->description) != vString) { if (!ws->description || gettextFromC::instance()->tr(ws->description) != vString) {
@ -640,7 +640,7 @@ bool WSInfoModel::insertRows(int row, int count, const QModelIndex& parent)
bool WSInfoModel::setData(const QModelIndex& index, const QVariant& value, int role) bool WSInfoModel::setData(const QModelIndex& index, const QVariant& value, int role)
{ {
struct ws_info_t *info = &ws_info[index.row()]; struct ws_info_t *info = &ws_info[index.row()];
switch(index.column()) { switch (index.column()) {
case DESCRIPTION: case DESCRIPTION:
info->name = strdup(value.toByteArray().data()); info->name = strdup(value.toByteArray().data());
break; break;
@ -665,13 +665,13 @@ QVariant WSInfoModel::data(const QModelIndex& index, int role) const
struct ws_info_t *info = &ws_info[index.row()]; struct ws_info_t *info = &ws_info[index.row()];
int gr = info->grams; int gr = info->grams;
switch(role){ switch (role) {
case Qt::FontRole : case Qt::FontRole :
ret = defaultModelFont(); ret = defaultModelFont();
break; break;
case Qt::DisplayRole : case Qt::DisplayRole :
case Qt::EditRole : case Qt::EditRole :
switch(index.column()) { switch (index.column()) {
case GR: case GR:
ret = gr; ret = gr;
break; break;
@ -698,9 +698,9 @@ WSInfoModel::WSInfoModel() : rows(-1)
{ {
setHeaderDataStrings( QStringList() << tr("Description") << tr("kg")); setHeaderDataStrings( QStringList() << tr("Description") << tr("kg"));
struct ws_info_t *info = ws_info; struct ws_info_t *info = ws_info;
for (info = ws_info; info->name; info++, rows++){ for (info = ws_info; info->name; info++, rows++) {
QString wsInfoName = gettextFromC::instance()->tr(info->name); QString wsInfoName = gettextFromC::instance()->tr(info->name);
if( wsInfoName.count() > biggerEntry.count()) if ( wsInfoName.count() > biggerEntry.count())
biggerEntry = wsInfoName; biggerEntry = wsInfoName;
} }
@ -716,9 +716,9 @@ void WSInfoModel::updateInfo()
beginRemoveRows(QModelIndex(), 0, this->rows); beginRemoveRows(QModelIndex(), 0, this->rows);
endRemoveRows(); endRemoveRows();
rows = -1; rows = -1;
for (info = ws_info; info->name; info++, rows++){ for (info = ws_info; info->name; info++, rows++) {
QString wsInfoName = gettextFromC::instance()->tr(info->name); QString wsInfoName = gettextFromC::instance()->tr(info->name);
if( wsInfoName.count() > biggerEntry.count()) if ( wsInfoName.count() > biggerEntry.count())
biggerEntry = wsInfoName; biggerEntry = wsInfoName;
} }
@ -766,7 +766,7 @@ bool TankInfoModel::insertRows(int row, int count, const QModelIndex& parent)
bool TankInfoModel::setData(const QModelIndex& index, const QVariant& value, int role) bool TankInfoModel::setData(const QModelIndex& index, const QVariant& value, int role)
{ {
struct tank_info_t *info = &tank_info[index.row()]; struct tank_info_t *info = &tank_info[index.row()];
switch(index.column()) { switch (index.column()) {
case DESCRIPTION: case DESCRIPTION:
info->name = strdup(value.toByteArray().data()); info->name = strdup(value.toByteArray().data());
break; break;
@ -791,7 +791,7 @@ QVariant TankInfoModel::data(const QModelIndex& index, int role) const
if (!index.isValid()) { if (!index.isValid()) {
return ret; return ret;
} }
if (role == Qt::FontRole){ if (role == Qt::FontRole) {
return defaultModelFont(); return defaultModelFont();
} }
if (role == Qt::DisplayRole || role == Qt::EditRole) { if (role == Qt::DisplayRole || role == Qt::EditRole) {
@ -802,7 +802,7 @@ QVariant TankInfoModel::data(const QModelIndex& index, int role) const
if (info->cuft && info->psi) if (info->cuft && info->psi)
ml = cuft_to_l(info->cuft) * 1000 / bar_to_atm(bar); ml = cuft_to_l(info->cuft) * 1000 / bar_to_atm(bar);
switch(index.column()) { switch (index.column()) {
case BAR: case BAR:
ret = bar * 1000; ret = bar * 1000;
break; break;
@ -826,7 +826,7 @@ TankInfoModel::TankInfoModel() : rows(-1)
{ {
setHeaderDataStrings( QStringList() << tr("Description") << tr("ml") << tr("bar")); setHeaderDataStrings( QStringList() << tr("Description") << tr("ml") << tr("bar"));
struct tank_info_t *info = tank_info; struct tank_info_t *info = tank_info;
for (info = tank_info; info->name; info++, rows++){ for (info = tank_info; info->name; info++, rows++) {
QString infoName = gettextFromC::instance()->tr(info->name); QString infoName = gettextFromC::instance()->tr(info->name);
if (infoName.count() > biggerEntry.count()) if (infoName.count() > biggerEntry.count())
biggerEntry = infoName; biggerEntry = infoName;
@ -1074,7 +1074,7 @@ QVariant DiveItem::data(int column, int role) const
if (role == DiveTripModel::DIVE_ROLE) { if (role == DiveTripModel::DIVE_ROLE) {
retVal = QVariant::fromValue<void*>(dive); retVal = QVariant::fromValue<void*>(dive);
} }
if(role == DiveTripModel::DIVE_IDX){ if (role == DiveTripModel::DIVE_IDX) {
Q_ASSERT(dive != NULL); Q_ASSERT(dive != NULL);
retVal = get_divenr(dive); retVal = get_divenr(dive);
} }
@ -1083,7 +1083,7 @@ QVariant DiveItem::data(int column, int role) const
Qt::ItemFlags DiveItem::flags(const QModelIndex& index) const Qt::ItemFlags DiveItem::flags(const QModelIndex& index) const
{ {
if(index.column() == NR){ if (index.column() == NR) {
return TreeItem::flags(index) | Qt::ItemIsEditable; return TreeItem::flags(index) | Qt::ItemIsEditable;
} }
return TreeItem::flags(index); return TreeItem::flags(index);
@ -1102,7 +1102,7 @@ bool DiveItem::setData(const QModelIndex& index, const QVariant& value, int role
int i; int i;
struct dive *d; struct dive *d;
for_each_dive(i, d){ for_each_dive(i, d) {
if (d->number == v) if (d->number == v)
return false; return false;
} }
@ -1215,7 +1215,7 @@ QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int
if (orientation == Qt::Vertical) if (orientation == Qt::Vertical)
return ret; return ret;
switch(role){ switch (role) {
case Qt::FontRole : case Qt::FontRole :
ret = defaultModelFont(); break; ret = defaultModelFont(); break;
case Qt::DisplayRole : case Qt::DisplayRole :
@ -1244,7 +1244,7 @@ void DiveTripModel::setupModelData()
{ {
int i = dive_table.nr; int i = dive_table.nr;
if (rowCount()){ if (rowCount()) {
beginRemoveRows(QModelIndex(), 0, rowCount()-1); beginRemoveRows(QModelIndex(), 0, rowCount()-1);
endRemoveRows(); endRemoveRows();
} }
@ -1281,7 +1281,7 @@ void DiveTripModel::setupModelData()
tripItem->children.push_back(diveItem); tripItem->children.push_back(diveItem);
} }
if (rowCount()){ if (rowCount()) {
beginInsertRows(QModelIndex(), 0, rowCount() - 1); beginInsertRows(QModelIndex(), 0, rowCount() - 1);
endInsertRows(); endInsertRows();
} }
@ -1302,7 +1302,7 @@ bool DiveTripModel::setData(const QModelIndex& index, const QVariant& value, int
{ {
TreeItem* item = static_cast<TreeItem*>(index.internalPointer()); TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
DiveItem *diveItem = dynamic_cast<DiveItem*>(item); DiveItem *diveItem = dynamic_cast<DiveItem*>(item);
if(!diveItem) if (!diveItem)
return false; return false;
return diveItem->setData(index, value, role);} return diveItem->setData(index, value, role);}
@ -1327,16 +1327,16 @@ QVariant DiveComputerModel::data(const QModelIndex& index, int role) const
DiveComputerNode node = values.at(index.row()); DiveComputerNode node = values.at(index.row());
QVariant ret; QVariant ret;
if (role == Qt::DisplayRole || role == Qt::EditRole){ if (role == Qt::DisplayRole || role == Qt::EditRole) {
switch(index.column()){ switch (index.column()) {
case ID: ret = QString("0x").append(QString::number(node.deviceId, 16)); break; case ID: ret = QString("0x").append(QString::number(node.deviceId, 16)); break;
case MODEL: ret = node.model; break; case MODEL: ret = node.model; break;
case NICKNAME: ret = node.nickName; break; case NICKNAME: ret = node.nickName; break;
} }
} }
if (index.column() == REMOVE){ if (index.column() == REMOVE) {
switch(role){ switch (role) {
case Qt::DecorationRole : ret = QIcon(":trash"); break; case Qt::DecorationRole : ret = QIcon(":trash"); break;
case Qt::ToolTipRole : ret = tr("Clicking here will remove this divecomputer."); break; case Qt::ToolTipRole : ret = tr("Clicking here will remove this divecomputer."); break;
} }
@ -1354,13 +1354,13 @@ void DiveComputerModel::update()
QList<DiveComputerNode> values = dcWorkingMap.values(); QList<DiveComputerNode> values = dcWorkingMap.values();
int count = values.count(); int count = values.count();
if(numRows){ if (numRows) {
beginRemoveRows(QModelIndex(), 0, numRows-1); beginRemoveRows(QModelIndex(), 0, numRows-1);
numRows = 0; numRows = 0;
endRemoveRows(); endRemoveRows();
} }
if (count){ if (count) {
beginInsertRows(QModelIndex(), 0, count-1); beginInsertRows(QModelIndex(), 0, count-1);
numRows = count; numRows = count;
endInsertRows(); endInsertRows();
@ -1413,7 +1413,7 @@ void DiveComputerModel::keepWorkingList()
* ################################################################ * ################################################################
*/ */
class YearStatisticsItem : public TreeItem{ class YearStatisticsItem : public TreeItem {
public: public:
enum {YEAR, DIVES, TOTAL_TIME, AVERAGE_TIME, SHORTEST_TIME, LONGEST_TIME, AVG_DEPTH, MIN_DEPTH, enum {YEAR, DIVES, TOTAL_TIME, AVERAGE_TIME, SHORTEST_TIME, LONGEST_TIME, AVG_DEPTH, MIN_DEPTH,
MAX_DEPTH, AVG_SAC, MIN_SAC, MAX_SAC, AVG_TEMP, MIN_TEMP, MAX_TEMP, COLUMNS}; MAX_DEPTH, AVG_SAC, MIN_SAC, MAX_SAC, AVG_TEMP, MIN_TEMP, MAX_TEMP, COLUMNS};
@ -1440,7 +1440,7 @@ QVariant YearStatisticsItem::data(int column, int role) const
} else if (role != Qt::DisplayRole) { } else if (role != Qt::DisplayRole) {
return ret; return ret;
} }
switch(column) { switch (column) {
case YEAR: case YEAR:
if (stats_interval.is_trip) { if (stats_interval.is_trip) {
ret = stats_interval.location; ret = stats_interval.location;
@ -1491,7 +1491,7 @@ QVariant YearlyStatisticsModel::headerData(int section, Qt::Orientation orientat
val = defaultModelFont(); val = defaultModelFont();
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
switch(section) { switch (section) {
case YEAR: val = tr("Year \n > Month / Trip"); break; case YEAR: val = tr("Year \n > Month / Trip"); break;
case DIVES: val = tr("#"); break; case DIVES: val = tr("#"); break;
case TOTAL_TIME: val = tr("Duration \n Total"); break; case TOTAL_TIME: val = tr("Duration \n Total"); break;
@ -1824,7 +1824,7 @@ void GasSelectionModel::repopulate()
QVariant GasSelectionModel::data(const QModelIndex& index, int role) const QVariant GasSelectionModel::data(const QModelIndex& index, int role) const
{ {
if(role == Qt::FontRole){ if (role == Qt::FontRole) {
return defaultModelFont(); return defaultModelFont();
} }
return QStringListModel::data(index, role); return QStringListModel::data(index, role);
@ -1844,8 +1844,8 @@ LanguageModel::LanguageModel(QObject* parent): QAbstractListModel(parent)
QSettings s; QSettings s;
QDir d(getSubsurfaceDataPath("translations")); QDir d(getSubsurfaceDataPath("translations"));
QStringList result = d.entryList(); QStringList result = d.entryList();
Q_FOREACH(const QString& s, result){ Q_FOREACH(const QString& s, result) {
if ( s.startsWith("subsurface_") && s.endsWith(".qm") ){ if ( s.startsWith("subsurface_") && s.endsWith(".qm") ) {
languages.push_back( (s == "subsurface_source.qm") ? "English" : s); languages.push_back( (s == "subsurface_source.qm") ? "English" : s);
} }
} }
@ -1855,14 +1855,14 @@ QVariant LanguageModel::data(const QModelIndex& index, int role) const
{ {
QLocale loc; QLocale loc;
QString currentString = languages.at(index.row()); QString currentString = languages.at(index.row());
if(!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
switch(role){ switch (role) {
case Qt::DisplayRole:{ case Qt::DisplayRole: {
QLocale l( currentString.remove("subsurface_")); QLocale l( currentString.remove("subsurface_"));
return currentString == "English" ? currentString : QString("%1 (%2)").arg(l.languageToString(l.language())).arg(l.countryToString(l.country())); return currentString == "English" ? currentString : QString("%1 (%2)").arg(l.languageToString(l.language())).arg(l.countryToString(l.country()));
}break; }break;
case Qt::UserRole:{ case Qt::UserRole: {
QString currentString = languages.at(index.row()); QString currentString = languages.at(index.row());
return currentString == "English" ? "en_US" : currentString.remove("subsurface_"); return currentString == "English" ? "en_US" : currentString.remove("subsurface_");
}break; }break;

View file

@ -206,7 +206,7 @@ void PreferencesDialog::syncSettings()
void PreferencesDialog::buttonClicked(QAbstractButton* button) void PreferencesDialog::buttonClicked(QAbstractButton* button)
{ {
switch(ui.buttonBox->standardButton(button)){ switch (ui.buttonBox->standardButton(button)) {
case QDialogButtonBox::Discard: case QDialogButtonBox::Discard:
restorePrefs(); restorePrefs();
close(); close();

View file

@ -2,7 +2,7 @@
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QPointF> #include <QPointF>
namespace Animations{ namespace Animations {
void hide(QObject* obj) void hide(QObject* obj)
{ {

View file

@ -27,6 +27,7 @@ void DiveCartesianAxis::setTextColor(const QColor& color)
DiveCartesianAxis::DiveCartesianAxis() : orientation(Qt::Horizontal) DiveCartesianAxis::DiveCartesianAxis() : orientation(Qt::Horizontal)
{ {
} }
DiveCartesianAxis::~DiveCartesianAxis() DiveCartesianAxis::~DiveCartesianAxis()
@ -50,8 +51,8 @@ void DiveCartesianAxis::updateTicks()
double currValue = min; double currValue = min;
// Remove the uneeded Ticks / Texts. // Remove the uneeded Ticks / Texts.
if (ticks.size() > steps){ if (ticks.size() > steps) {
while (ticks.size() > steps){ while (ticks.size() > steps) {
DiveLineItem *removedLine = ticks.takeLast(); DiveLineItem *removedLine = ticks.takeLast();
removedLine->animatedHide(); removedLine->animatedHide();
DiveTextItem *removedText = labels.takeLast(); DiveTextItem *removedText = labels.takeLast();
@ -65,21 +66,20 @@ void DiveCartesianAxis::updateTicks()
qreal end = orientation == Qt::Horizontal ? m.x2() : m.y2(); qreal end = orientation == Qt::Horizontal ? m.x2() : m.y2();
double stepSize = orientation == Qt::Horizontal ? (m.x2() - m.x1()) : (m.y2() - m.y1()); double stepSize = orientation == Qt::Horizontal ? (m.x2() - m.x1()) : (m.y2() - m.y1());
stepSize = stepSize / steps; stepSize = stepSize / steps;
for(int i = 0, count = ticks.size(); i < count; i++, currValue += interval){ for (int i = 0, count = ticks.size(); i < count; i++, currValue += interval) {
qreal childPos = begin + i * stepSize; qreal childPos = begin + i * stepSize;
labels[i]->setText(textForValue(currValue)); labels[i]->setText(textForValue(currValue));
if ( orientation == Qt::Horizontal ){ if ( orientation == Qt::Horizontal ) {
ticks[i]->animateMoveTo(childPos, m.y1() + tickSize); ticks[i]->animateMoveTo(childPos, m.y1() + tickSize);
labels[i]->animateMoveTo(childPos, m.y1() + tickSize); labels[i]->animateMoveTo(childPos, m.y1() + tickSize);
} } else {
else{
ticks[i]->animateMoveTo(m.x1() - tickSize, childPos); ticks[i]->animateMoveTo(m.x1() - tickSize, childPos);
labels[i]->animateMoveTo(m.x1() - tickSize, childPos); labels[i]->animateMoveTo(m.x1() - tickSize, childPos);
} }
} }
// Add's the rest of the needed Ticks / Text. // Add's the rest of the needed Ticks / Text.
for(int i = ticks.size(); i < steps; i++, currValue += interval){ for (int i = ticks.size(); i < steps; i++, currValue += interval) {
qreal childPos = begin + i * stepSize; qreal childPos = begin + i * stepSize;
DiveLineItem *item = new DiveLineItem(this); DiveLineItem *item = new DiveLineItem(this);
item->setPen(pen()); item->setPen(pen());
@ -90,15 +90,14 @@ void DiveCartesianAxis::updateTicks()
label->setBrush(QBrush(textColor)); label->setBrush(QBrush(textColor));
labels.push_back(label); labels.push_back(label);
if(orientation == Qt::Horizontal){ if (orientation == Qt::Horizontal) {
item->setLine(0, 0, 0, tickSize); item->setLine(0, 0, 0, tickSize);
item->setPos(scene()->sceneRect().width() + 10, m.y1() + tickSize); // position it outside of the scene item->setPos(scene()->sceneRect().width() + 10, m.y1() + tickSize); // position it outside of the scene
item->animateMoveTo(childPos, m.y1() + tickSize); // anim it to scene. item->animateMoveTo(childPos, m.y1() + tickSize); // anim it to scene.
label->setAlignment(Qt::AlignBottom | Qt::AlignHCenter); label->setAlignment(Qt::AlignBottom | Qt::AlignHCenter);
label->setPos(scene()->sceneRect().width() + 10, m.y1() + tickSize); // position it outside of the scene); label->setPos(scene()->sceneRect().width() + 10, m.y1() + tickSize); // position it outside of the scene);
label->animateMoveTo(childPos, m.y1() + tickSize); label->animateMoveTo(childPos, m.y1() + tickSize);
} } else {
else{
item->setLine(0, 0, tickSize, 0); item->setLine(0, 0, tickSize, 0);
item->setPos(m.x1() - tickSize, scene()->sceneRect().height() + 10); item->setPos(m.x1() - tickSize, scene()->sceneRect().height() + 10);
item->animateMoveTo(m.x1() - tickSize, childPos); item->animateMoveTo(m.x1() - tickSize, childPos);
@ -146,7 +145,7 @@ qreal DiveCartesianAxis::posAtValue(qreal value)
m.y2() - m.y1(); m.y2() - m.y1();
double retValue = realSize * percent; double retValue = realSize * percent;
retValue = (orientation == Qt::Horizontal) ? retValue = (orientation == Qt::Horizontal) ?
retValue + m.x1() + p.x(): retValue + m.x1() + p.x() :
retValue + m.y1() + p.y(); retValue + m.y1() + p.y();
return retValue; return retValue;
} }

View file

@ -2,4 +2,5 @@
DivePixmapItem::DivePixmapItem(QObject* parent): QObject(parent), QGraphicsPixmapItem() DivePixmapItem::DivePixmapItem(QObject* parent): QObject(parent), QGraphicsPixmapItem()
{ {
} }

View file

@ -23,8 +23,8 @@ QVariant DivePlotDataModel::data(const QModelIndex& index, int role) const
return QVariant(); return QVariant();
plot_data item = plotData[index.row()]; plot_data item = plotData[index.row()];
if (role == Qt::DisplayRole){ if (role == Qt::DisplayRole) {
switch(index.column()){ switch (index.column()) {
case DEPTH: return item.depth; case DEPTH: return item.depth;
case TIME: return item.sec; case TIME: return item.sec;
case PRESSURE: return item.pressure[0]; case PRESSURE: return item.pressure[0];
@ -33,8 +33,8 @@ QVariant DivePlotDataModel::data(const QModelIndex& index, int role) const
case USERENTERED: return false; case USERENTERED: return false;
} }
} }
if (role == Qt::BackgroundRole){ if (role == Qt::BackgroundRole) {
switch(index.column()){ switch (index.column()) {
case COLOR: return getColor((color_indice_t)(VELOCITY_COLORS_START_IDX + item.velocity)); case COLOR: return getColor((color_indice_t)(VELOCITY_COLORS_START_IDX + item.velocity));
} }
} }
@ -54,7 +54,7 @@ QVariant DivePlotDataModel::headerData(int section, Qt::Orientation orientation,
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();
switch(section){ switch (section) {
case DEPTH: return tr("Depth"); case DEPTH: return tr("Depth");
case TIME: return tr("Time"); case TIME: return tr("Time");
case PRESSURE: return tr("Pressure"); case PRESSURE: return tr("Pressure");
@ -67,7 +67,7 @@ QVariant DivePlotDataModel::headerData(int section, Qt::Orientation orientation,
void DivePlotDataModel::clear() void DivePlotDataModel::clear()
{ {
if(rowCount() != 0){ if (rowCount() != 0) {
beginRemoveRows(QModelIndex(), 0, rowCount() - 1); beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
endRemoveRows(); endRemoveRows();
} }

View file

@ -10,6 +10,7 @@
DiveProfileItem::DiveProfileItem(): QObject(), QGraphicsPolygonItem(), DiveProfileItem::DiveProfileItem(): QObject(), QGraphicsPolygonItem(),
hAxis(NULL), hDataColumn(-1), dataModel(NULL), vAxis(NULL), vDataColumn(-1) hAxis(NULL), hDataColumn(-1), dataModel(NULL), vAxis(NULL), vDataColumn(-1)
{ {
} }
void DiveProfileItem::setHorizontalAxis(DiveCartesianAxis* horizontal) void DiveProfileItem::setHorizontalAxis(DiveCartesianAxis* horizontal)
@ -54,7 +55,7 @@ void DiveProfileItem::modelDataChanged()
// is an array of QPointF's, so we basically get the point from the model, convert // is an array of QPointF's, so we basically get the point from the model, convert
// to our coordinates, store. no painting is done here. // to our coordinates, store. no painting is done here.
QPolygonF poly; QPolygonF poly;
for(int i = 0, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++){ for (int i = 0, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++) {
qreal horizontalValue = dataModel->index(i, hDataColumn).data().toReal(); qreal horizontalValue = dataModel->index(i, hDataColumn).data().toReal();
qreal verticalValue = dataModel->index(i, vDataColumn).data().toReal(); qreal verticalValue = dataModel->index(i, vDataColumn).data().toReal();
QPointF point( hAxis->posAtValue(horizontalValue), vAxis->posAtValue(verticalValue)); QPointF point( hAxis->posAtValue(horizontalValue), vAxis->posAtValue(verticalValue));
@ -70,7 +71,7 @@ void DiveProfileItem::modelDataChanged()
setBrush(QBrush(pat)); setBrush(QBrush(pat));
} }
void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget){ void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
Q_UNUSED(widget); Q_UNUSED(widget);
// This paints the Polygon + Background. I'm setting the pen to QPen() so we don't get a black line here, // This paints the Polygon + Background. I'm setting the pen to QPen() so we don't get a black line here,
@ -84,7 +85,7 @@ void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
pen.setCosmetic(true); pen.setCosmetic(true);
pen.setWidth(2); pen.setWidth(2);
// This paints the colors of the velocities. // This paints the colors of the velocities.
for(int i = 1, count = dataModel->rowCount(); i < count; i++){ for (int i = 1, count = dataModel->rowCount(); i < count; i++) {
QModelIndex colorIndex = dataModel->index(i, DivePlotDataModel::COLOR); QModelIndex colorIndex = dataModel->index(i, DivePlotDataModel::COLOR);
pen.setBrush(QBrush(colorIndex.data(Qt::BackgroundRole).value<QColor>())); pen.setBrush(QBrush(colorIndex.data(Qt::BackgroundRole).value<QColor>()));
painter->setPen(pen); painter->setPen(pen);

View file

@ -2,4 +2,5 @@
DiveRectItem::DiveRectItem(QObject* parent, QGraphicsItem* parentItem): QObject(parent), QGraphicsRectItem(parentItem ) DiveRectItem::DiveRectItem(QObject* parent, QGraphicsItem* parentItem): QObject(parent), QGraphicsRectItem(parentItem )
{ {
} }

View file

@ -29,9 +29,9 @@ void DiveTextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* opti
// //
// // if (internalAlignFlags & Qt::AlignLeft ) // // if (internalAlignFlags & Qt::AlignLeft )
// // painter->translate(); // This is the default, uneeded. // // painter->translate(); // This is the default, uneeded.
// if(internalAlignFlags & Qt::AlignHCenter) // if (internalAlignFlags & Qt::AlignHCenter)
// painter->translate(-rect.width()/2, 0); // painter->translate(-rect.width()/2, 0);
// else if(internalAlignFlags & Qt::AlignRight) // else if (internalAlignFlags & Qt::AlignRight)
// painter->translate(-rect.width(), 0); // painter->translate(-rect.width(), 0);
QGraphicsSimpleTextItem::paint(painter, option, widget); QGraphicsSimpleTextItem::paint(painter, option, widget);

View file

@ -65,9 +65,9 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
timeController->setX(sceneRect().width() - timeController->boundingRect().width()); // Position it on the right spot. timeController->setX(sceneRect().width() - timeController->boundingRect().width()); // Position it on the right spot.
// insert in the same way it's declared on the Enum. This is needed so we don't use an map. // insert in the same way it's declared on the Enum. This is needed so we don't use an map.
QList<QGraphicsItem*> stateItems; stateItems << background << profileYAxis << gasYAxis QList<QGraphicsItem*> stateItems; stateItems << background << profileYAxis << gasYAxis <<
<< timeAxis << depthController << timeController; timeAxis << depthController << timeController;
Q_FOREACH(QGraphicsItem *item, stateItems){ Q_FOREACH(QGraphicsItem *item, stateItems) {
scene()->addItem(item); scene()->addItem(item);
} }
@ -196,10 +196,10 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
// Animations // Animations
QList<QSignalTransition*> transitions; QList<QSignalTransition*> transitions;
transitions << tAddToEmpty << tAddToPlan << tAddToProfile << tEditToAdd << tEditToEmpty << tEditToPlan transitions << tAddToEmpty << tAddToPlan << tAddToProfile << tEditToAdd << tEditToEmpty << tEditToPlan <<
<< tEditToProfile << tEmptyToAdd << tEmptyToPlan << tEmptyToProfile << tProfileToAdd << tProfileToEdit tEditToProfile << tEmptyToAdd << tEmptyToPlan << tEmptyToProfile << tProfileToAdd <<
<< tProfileToEmpty << tProfileToPlan << tPlanToAdd << tPlanToEmpty << tPlanToProfile; tProfileToEdit << tProfileToEmpty << tProfileToPlan << tPlanToAdd << tPlanToEmpty << tPlanToProfile;
Q_FOREACH(QSignalTransition *s, transitions){ Q_FOREACH(QSignalTransition *s, transitions) {
s->addAnimation(backgroundYAnim); s->addAnimation(backgroundYAnim);
s->addAnimation(depthAxisAnim); s->addAnimation(depthAxisAnim);
s->addAnimation(gasAxisanim); s->addAnimation(gasAxisanim);
@ -232,7 +232,7 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
// I Know that it's a list, but currently we are // I Know that it's a list, but currently we are
// using just the first. // using just the first.
struct dive *d = dives.first(); struct dive *d = dives.first();
if(!d) if (!d)
return; return;
// Here we need to probe for the limits of the dive. // Here we need to probe for the limits of the dive.
@ -257,7 +257,7 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
timeAxis->updateTicks(); timeAxis->updateTicks();
dataModel->setDive(current_dive, pInfo); dataModel->setDive(current_dive, pInfo);
if(diveProfileItem){ if (diveProfileItem) {
//diveProfileItem->animateDelete(); //diveProfileItem->animateDelete();
scene()->removeItem(diveProfileItem); scene()->removeItem(diveProfileItem);
delete diveProfileItem; delete diveProfileItem;
@ -294,10 +294,10 @@ void ProfileWidget2::resizeEvent(QResizeEvent* event)
QGraphicsView::resizeEvent(event); QGraphicsView::resizeEvent(event);
fitInView(sceneRect(), Qt::IgnoreAspectRatio); fitInView(sceneRect(), Qt::IgnoreAspectRatio);
if(!stateMachine->configuration().count()) if (!stateMachine->configuration().count())
return; return;
if ((*stateMachine->configuration().begin())->objectName() == "Empty State"){ if ((*stateMachine->configuration().begin())->objectName() == "Empty State") {
fixBackgroundPos(); fixBackgroundPos();
} }
} }
@ -305,7 +305,7 @@ void ProfileWidget2::resizeEvent(QResizeEvent* event)
void ProfileWidget2::fixBackgroundPos() void ProfileWidget2::fixBackgroundPos()
{ {
QPixmap p = QPixmap(":background").scaledToHeight(viewport()->height()); QPixmap p = QPixmap(":background").scaledToHeight(viewport()->height());
int x = viewport()->width()/2 - p.width()/2; int x = viewport()->width() / 2 - p.width() / 2;
DivePixmapItem *bg = background; DivePixmapItem *bg = background;
bg->setPixmap(p); bg->setPixmap(p);
bg->setX(mapToScene(x, 0).x()); bg->setX(mapToScene(x, 0).x());

View file

@ -38,7 +38,7 @@ static struct graphics_context last_gc;
static double plot_scale = SCALE_SCREEN; static double plot_scale = SCALE_SCREEN;
#endif #endif
struct text_render_options{ struct text_render_options {
double size; double size;
color_indice_t color; color_indice_t color;
double hpos, vpos; double hpos, vpos;
@ -50,9 +50,10 @@ extern int evn_used;
#define TOOLBAR_POS \ #define TOOLBAR_POS \
QPoint(viewport()->geometry().width() - toolBarProxy->boundingRect().width(), \ QPoint(viewport()->geometry().width() - toolBarProxy->boundingRect().width(), \
viewport()->geometry().height() - toolBarProxy->boundingRect().height() ) viewport()->geometry().height() - toolBarProxy->boundingRect().height() )
ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent), toolTip(0) , diveId(0), diveDC(0), rulerItem(0), toolBarProxy(0) ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent),
toolTip(0) , diveId(0), diveDC(0), rulerItem(0), toolBarProxy(0)
{ {
printMode = false; printMode = false;
isGrayscale = false; isGrayscale = false;
@ -119,23 +120,23 @@ void ProfileGraphicsView::wheelEvent(QWheelEvent* event)
scrollViewTo(event->pos()); scrollViewTo(event->pos());
toolTip->setPos(mapToScene(toolTipPos)); toolTip->setPos(mapToScene(toolTipPos));
toolBarProxy->setPos(mapToScene(TOOLBAR_POS)); toolBarProxy->setPos(mapToScene(TOOLBAR_POS));
if(zoomLevel != 0){ if (zoomLevel != 0) {
toolBarProxy->hide(); toolBarProxy->hide();
}else{ } else {
toolBarProxy->show(); toolBarProxy->show();
} }
} }
void ProfileGraphicsView::contextMenuEvent(QContextMenuEvent* event) void ProfileGraphicsView::contextMenuEvent(QContextMenuEvent* event)
{ {
if(selected_dive == -1) if (selected_dive == -1)
return; return;
QMenu m; QMenu m;
QMenu *gasChange = m.addMenu(tr("Add Gas Change")); QMenu *gasChange = m.addMenu(tr("Add Gas Change"));
GasSelectionModel *model = GasSelectionModel::instance(); GasSelectionModel *model = GasSelectionModel::instance();
model->repopulate(); model->repopulate();
int rowCount = model->rowCount(); int rowCount = model->rowCount();
for(int i = 0; i < rowCount; i++){ for (int i = 0; i < rowCount; i++) {
QAction *action = new QAction(&m); QAction *action = new QAction(&m);
action->setText( model->data(model->index(i, 0),Qt::DisplayRole).toString()); action->setText( model->data(model->index(i, 0),Qt::DisplayRole).toString());
connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas())); connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas()));
@ -145,9 +146,9 @@ void ProfileGraphicsView::contextMenuEvent(QContextMenuEvent* event)
QAction *action = m.addAction(tr("Add Bookmark"), this, SLOT(addBookmark())); QAction *action = m.addAction(tr("Add Bookmark"), this, SLOT(addBookmark()));
action->setData(event->globalPos()); action->setData(event->globalPos());
QList<QGraphicsItem*> itemsAtPos = scene()->items(mapToScene(mapFromGlobal(event->globalPos()))); QList<QGraphicsItem*> itemsAtPos = scene()->items(mapToScene(mapFromGlobal(event->globalPos())));
Q_FOREACH(QGraphicsItem *i, itemsAtPos){ Q_FOREACH(QGraphicsItem *i, itemsAtPos) {
EventItem *item = dynamic_cast<EventItem*>(i); EventItem *item = dynamic_cast<EventItem*>(i);
if(!item) if (!item)
continue; continue;
QAction *action = new QAction(&m); QAction *action = new QAction(&m);
action->setText(tr("Remove Event")); action->setText(tr("Remove Event"));
@ -214,7 +215,7 @@ void ProfileGraphicsView::hideEvents()
if (QMessageBox::question(mainWindow(), TITLE_OR_TEXT( if (QMessageBox::question(mainWindow(), TITLE_OR_TEXT(
tr("Hide events"), tr("Hide events"),
tr("Hide all %1 events?").arg(event->name)), tr("Hide all %1 events?").arg(event->name)),
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok){ QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
if (event->name) { if (event->name) {
for (int i = 0; i < evn_used; i++) { for (int i = 0; i < evn_used; i++) {
if (! strcmp(event->name, ev_namelist[i].ev_name)) { if (! strcmp(event->name, ev_namelist[i].ev_name)) {
@ -246,7 +247,7 @@ void ProfileGraphicsView::removeEvent()
tr("%1 @ %2:%3").arg(event->name) tr("%1 @ %2:%3").arg(event->name)
.arg(event->time.seconds / 60) .arg(event->time.seconds / 60)
.arg(event->time.seconds % 60, 2, 10, QChar('0'))), .arg(event->time.seconds % 60, 2, 10, QChar('0'))),
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok){ QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
struct event **ep = &current_dc->events; struct event **ep = &current_dc->events;
while (ep && *ep != event) while (ep && *ep != event)
ep = &(*ep)->next; ep = &(*ep)->next;
@ -269,9 +270,9 @@ void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event)
QPoint toolTipPos = mapFromScene(toolTip->pos()); QPoint toolTipPos = mapFromScene(toolTip->pos());
scrollViewTo(event->pos()); scrollViewTo(event->pos());
if (zoomLevel == 0) if (zoomLevel == 0) {
QGraphicsView::mouseMoveEvent(event); QGraphicsView::mouseMoveEvent(event);
else{ } else {
toolTip->setPos(mapToScene(toolTipPos)); toolTip->setPos(mapToScene(toolTipPos));
toolBarProxy->setPos(mapToScene(TOOLBAR_POS)); toolBarProxy->setPos(mapToScene(TOOLBAR_POS));
} }
@ -287,7 +288,7 @@ bool ProfileGraphicsView::eventFilter(QObject* obj, QEvent* event)
// This will "Eat" the default tooltip behavior if it is not on the toolBar. // This will "Eat" the default tooltip behavior if it is not on the toolBar.
if (event->type() == QEvent::GraphicsSceneHelp) { if (event->type() == QEvent::GraphicsSceneHelp) {
if(toolBarProxy && !toolBarProxy->geometry().contains(mapToScene(mapFromGlobal(QCursor::pos())))){ if (toolBarProxy && !toolBarProxy->geometry().contains(mapToScene(mapFromGlobal(QCursor::pos())))) {
event->ignore(); event->ignore();
return true; return true;
} }
@ -328,17 +329,17 @@ void ProfileGraphicsView::clear()
{ {
resetTransform(); resetTransform();
zoomLevel = 0; zoomLevel = 0;
if(toolTip) { if (toolTip) {
scene()->removeItem(toolTip); scene()->removeItem(toolTip);
toolTip->deleteLater(); toolTip->deleteLater();
toolTip = 0; toolTip = 0;
} }
if(toolBarProxy) { if (toolBarProxy) {
scene()->removeItem(toolBarProxy); scene()->removeItem(toolBarProxy);
toolBarProxy->deleteLater(); toolBarProxy->deleteLater();
toolBarProxy = 0; toolBarProxy = 0;
} }
if(rulerItem) { if (rulerItem) {
remove_ruler(); remove_ruler();
rulerItem->destNode()->deleteLater(); rulerItem->destNode()->deleteLater();
rulerItem->sourceNode()->deleteLater(); rulerItem->sourceNode()->deleteLater();
@ -408,9 +409,9 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
if (nick.isEmpty()) if (nick.isEmpty())
nick = tr("unknown divecomputer"); nick = tr("unknown divecomputer");
if ( tr("unknown divecomputer") == nick){ if ( tr("unknown divecomputer") == nick) {
mode = PLAN; mode = PLAN;
}else{ } else {
mode = DIVE; mode = DIVE;
} }
@ -484,7 +485,7 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
} }
toolTip->readPos(); toolTip->readPos();
if(mode == PLAN){ if (mode == PLAN) {
timeEditor = new GraphicsTextEditor(); timeEditor = new GraphicsTextEditor();
timeEditor->setPlainText(d->duration.seconds ? QString::number(d->duration.seconds/60) : tr("Set Duration: 10 minutes")); timeEditor->setPlainText(d->duration.seconds ? QString::number(d->duration.seconds/60) : tr("Set Duration: 10 minutes"));
timeEditor->setPos(profile_grid_area.width() - timeEditor->boundingRect().width(), timeMarkers->y()); timeEditor->setPos(profile_grid_area.width() - timeEditor->boundingRect().width(), timeMarkers->y());
@ -572,7 +573,7 @@ void ProfileGraphicsView::plot_pp_text()
QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, m), SCALEGC(hpos, m)); QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, m), SCALEGC(hpos, m));
QPen pen(defaultPen); QPen pen(defaultPen);
pen.setColor(c); pen.setColor(c);
if ( QString::number(m).toDouble() != QString::number(m).toInt()){ if ( QString::number(m).toDouble() != QString::number(m).toInt()) {
pen.setStyle(Qt::DashLine); pen.setStyle(Qt::DashLine);
pen.setWidthF(1.2); pen.setWidthF(1.2);
} }
@ -696,7 +697,7 @@ void ProfileGraphicsView::createPPLegend(QString title, const QColor& c, QPointF
scene()->addItem(rect); scene()->addItem(rect);
scene()->addItem(text); scene()->addItem(text);
legendPos.setX(text->pos().x() + text->boundingRect().width() + 20); legendPos.setX(text->pos().x() + text->boundingRect().width() + 20);
if(printMode){ if (printMode) {
QFont f = text->font(); QFont f = text->font();
f.setPointSizeF( f.pointSizeF() * 0.7); f.setPointSizeF( f.pointSizeF() * 0.7);
text->setFont(f); text->setFont(f);
@ -1029,7 +1030,7 @@ void ProfileGraphicsView::plot_one_event(struct event *ev)
name += ": "; name += ": ";
if (he) if (he)
name += QString("%1/%2").arg((o2 + 5) / 10).arg((he + 5) / 10); name += QString("%1/%2").arg((o2 + 5) / 10).arg((he + 5) / 10);
else if(is_air(o2, he)) else if (is_air(o2, he))
name += tr("air"); name += tr("air");
else else
name += QString(tr("EAN%1")).arg((o2 + 5) / 10); name += QString(tr("EAN%1")).arg((o2 + 5) / 10);
@ -1292,9 +1293,9 @@ void ProfileGraphicsView::plot_depth_profile()
} }
/* plot the calculated ceiling for all tissues */ /* plot the calculated ceiling for all tissues */
if (prefs.profile_calc_ceiling && prefs.calc_all_tissues){ if (prefs.profile_calc_ceiling && prefs.calc_all_tissues) {
int k; int k;
for (k=0; k<16; k++){ for (k=0; k<16; k++) {
pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW)); pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW));
pat.setColorAt(1, QColor(100, 100, 100, 50)); pat.setColorAt(1, QColor(100, 100, 100, 50));
@ -1641,7 +1642,7 @@ void ToolTipItem::readPos()
QPointF value = scene()->views().at(0)->mapToScene( QPointF value = scene()->views().at(0)->mapToScene(
s.value("tooltip_position").toPoint() s.value("tooltip_position").toPoint()
); );
if (!scene()->sceneRect().contains(value)){ if (!scene()->sceneRect().contains(value)) {
value = QPointF(0,0); value = QPointF(0,0);
} }
setPos(value); setPos(value);
@ -1654,7 +1655,7 @@ QColor EventItem::getColor(const color_indice_t i)
EventItem::EventItem(struct event *ev, QGraphicsItem* parent, bool grayscale): QGraphicsPixmapItem(parent), ev(ev), isGrayscale(grayscale) EventItem::EventItem(struct event *ev, QGraphicsItem* parent, bool grayscale): QGraphicsPixmapItem(parent), ev(ev), isGrayscale(grayscale)
{ {
if(ev->name && (strcmp(ev->name, "bookmark") == 0 || strcmp(ev->name, "heading") == 0)) { if (ev->name && (strcmp(ev->name, "bookmark") == 0 || strcmp(ev->name, "heading") == 0)) {
setPixmap( QPixmap(QString(":flag")).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation)); setPixmap( QPixmap(QString(":flag")).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation));
} else { } else {
setPixmap( QPixmap(QString(":warning")).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation)); setPixmap( QPixmap(QString(":warning")).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation));
@ -1683,11 +1684,9 @@ void RulerNodeItem::recalculate()
uint16_t count = 0; uint16_t count = 0;
if (x() < 0) { if (x() < 0) {
setPos(0, y()); setPos(0, y());
} } else if (x() > SCALEXGC(data->sec)) {
else if (x() > SCALEXGC(data->sec)) {
setPos(SCALEXGC(data->sec), y()); setPos(SCALEXGC(data->sec), y());
} } else {
else {
data = pi->entry; data = pi->entry;
count=0; count=0;
while (SCALEXGC(data->sec) < x() && count < pi->nr) { while (SCALEXGC(data->sec) < x() && count < pi->nr) {
@ -1701,9 +1700,9 @@ void RulerNodeItem::recalculate()
QVariant RulerNodeItem::itemChange(GraphicsItemChange change, const QVariant &value) QVariant RulerNodeItem::itemChange(GraphicsItemChange change, const QVariant &value)
{ {
if(change == ItemPositionHasChanged) { if (change == ItemPositionHasChanged) {
recalculate(); recalculate();
if(ruler != NULL) if (ruler != NULL)
ruler->recalculate(); ruler->recalculate();
if (scene()) { if (scene()) {
scene()->update(); scene()->update();
@ -1827,7 +1826,7 @@ void GraphicsTextEditor::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
void GraphicsTextEditor::keyReleaseEvent(QKeyEvent* event) void GraphicsTextEditor::keyReleaseEvent(QKeyEvent* event)
{ {
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return){ if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
setTextInteractionFlags(Qt::NoTextInteraction); setTextInteractionFlags(Qt::NoTextInteraction);
emit editingFinished( toPlainText() ); emit editingFinished( toPlainText() );
mainWindow()->graphics()->setFocusProxy(mainWindow()->dive_list()); mainWindow()->graphics()->setFocusProxy(mainWindow()->dive_list());

View file

@ -15,13 +15,13 @@
#include "../dive.h" #include "../dive.h"
#include "mainwindow.h" #include "mainwindow.h"
class MinMaxAvgWidgetPrivate{ class MinMaxAvgWidgetPrivate {
public: public:
QLabel *avgIco, *avgValue; QLabel *avgIco, *avgValue;
QLabel *minIco, *minValue; QLabel *minIco, *minValue;
QLabel *maxIco, *maxValue; QLabel *maxIco, *maxValue;
MinMaxAvgWidgetPrivate(MinMaxAvgWidget *owner){ MinMaxAvgWidgetPrivate(MinMaxAvgWidget *owner) {
avgIco = new QLabel(owner); avgIco = new QLabel(owner);
avgIco->setPixmap(QIcon(":/average").pixmap(16,16)); avgIco->setPixmap(QIcon(":/average").pixmap(16,16));
avgIco->setToolTip(QObject::tr("Average")); avgIco->setToolTip(QObject::tr("Average"));
@ -60,8 +60,9 @@ double MinMaxAvgWidget::minimum() const
return d->minValue->text().toDouble(); return d->minValue->text().toDouble();
} }
MinMaxAvgWidget::MinMaxAvgWidget(QWidget* parent) MinMaxAvgWidget::MinMaxAvgWidget(QWidget* parent) : d(new MinMaxAvgWidgetPrivate(this))
: d(new MinMaxAvgWidgetPrivate(this)){ {
} }
MinMaxAvgWidget::~MinMaxAvgWidget() MinMaxAvgWidget::~MinMaxAvgWidget()
@ -112,7 +113,7 @@ RenumberDialog* RenumberDialog::instance()
void RenumberDialog::buttonClicked(QAbstractButton* button) void RenumberDialog::buttonClicked(QAbstractButton* button)
{ {
if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole){ if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
qDebug() << "Renumbering."; qDebug() << "Renumbering.";
renumber_dives(ui.spinBox->value()); renumber_dives(ui.spinBox->value());
} }
@ -134,7 +135,7 @@ void ShiftTimesDialog::buttonClicked(QAbstractButton* button)
{ {
int amount; int amount;
if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole){ if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
amount = ui.timeEdit->time().hour() * 3600 + ui.timeEdit->time().minute() * 60; amount = ui.timeEdit->time().hour() * 3600 + ui.timeEdit->time().minute() * 60;
if (ui.backwards->isChecked()) if (ui.backwards->isChecked())
amount *= -1; amount *= -1;

View file

@ -55,7 +55,7 @@ void StarWidget::paintEvent(QPaintEvent* event)
for(int i = current; i < TOTALSTARS; i++) for(int i = current; i < TOTALSTARS; i++)
p.drawPixmap(i * IMG_SIZE + SPACING, 0, starInactive()); p.drawPixmap(i * IMG_SIZE + SPACING, 0, starInactive());
if(hasFocus()){ if (hasFocus()) {
QStyleOptionFocusRect option; QStyleOptionFocusRect option;
option.initFrom(this); option.initFrom(this);
option.backgroundColor = palette().color(QPalette::Background); option.backgroundColor = palette().color(QPalette::Background);
@ -135,12 +135,12 @@ void StarWidget::focusOutEvent(QFocusEvent* event)
void StarWidget::keyPressEvent(QKeyEvent* event) void StarWidget::keyPressEvent(QKeyEvent* event)
{ {
if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Right){ if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Right) {
if (currentStars() < TOTALSTARS){ if (currentStars() < TOTALSTARS) {
setCurrentStars( currentStars()+1); setCurrentStars( currentStars()+1);
} }
}else if(event->key() == Qt::Key_Down || event->key() == Qt::Key_Left){ } else if (event->key() == Qt::Key_Down || event->key() == Qt::Key_Left) {
if(currentStars() > 0){ if (currentStars() > 0) {
setCurrentStars( currentStars()-1); setCurrentStars( currentStars()-1);
} }
} }

View file

@ -331,8 +331,8 @@ SubsurfaceWebServices::SubsurfaceWebServices(QWidget* parent, Qt::WindowFlags f)
void SubsurfaceWebServices::buttonClicked(QAbstractButton* button) void SubsurfaceWebServices::buttonClicked(QAbstractButton* button)
{ {
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
switch(ui.buttonBox->buttonRole(button)){ switch (ui.buttonBox->buttonRole(button)) {
case QDialogButtonBox::ApplyRole:{ case QDialogButtonBox::ApplyRole: {
clear_table(&gps_location_table); clear_table(&gps_location_table);
QByteArray url = tr("Webservice").toLocal8Bit(); QByteArray url = tr("Webservice").toLocal8Bit();
parse_xml_buffer(url.data(), downloadedData.data(), downloadedData.length(), &gps_location_table, NULL, NULL); parse_xml_buffer(url.data(), downloadedData.data(), downloadedData.length(), &gps_location_table, NULL, NULL);
@ -408,7 +408,7 @@ void SubsurfaceWebServices::downloadFinished()
uint resultCode = download_dialog_parse_response(downloadedData); uint resultCode = download_dialog_parse_response(downloadedData);
setStatusText(resultCode); setStatusText(resultCode);
if (resultCode == DD_STATUS_OK){ if (resultCode == DD_STATUS_OK) {
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true); ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
} }
reply->deleteLater(); reply->deleteLater();
@ -850,8 +850,8 @@ void DivelogsDeWebServices::uploadError(QNetworkReply::NetworkError error)
void DivelogsDeWebServices::buttonClicked(QAbstractButton* button) void DivelogsDeWebServices::buttonClicked(QAbstractButton* button)
{ {
ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
switch(ui.buttonBox->buttonRole(button)){ switch (ui.buttonBox->buttonRole(button)) {
case QDialogButtonBox::ApplyRole:{ case QDialogButtonBox::ApplyRole: {
/* in 'uploadMode' button is called 'Done' and closes the dialog */ /* in 'uploadMode' button is called 'Done' and closes the dialog */
if (uploadMode) { if (uploadMode) {
hide(); hide();

View file

@ -45,7 +45,8 @@ void TableView::setTitle(const QString& title)
ui.groupBox->setTitle(title); ui.groupBox->setTitle(title);
} }
void TableView::setModel(QAbstractItemModel *model){ void TableView::setModel(QAbstractItemModel *model)
{
ui.tableView->setModel(model); ui.tableView->setModel(model);
connect(ui.tableView, SIGNAL(clicked(QModelIndex)), model, SLOT(remove(QModelIndex))); connect(ui.tableView, SIGNAL(clicked(QModelIndex)), model, SLOT(remove(QModelIndex)));
@ -80,10 +81,12 @@ void TableView::showEvent(QShowEvent* event)
fixPlusPosition(); fixPlusPosition();
} }
void TableView::edit(const QModelIndex& index){ void TableView::edit(const QModelIndex& index)
{
ui.tableView->edit(index); ui.tableView->edit(index);
} }
QTableView *TableView::view(){ QTableView *TableView::view()
{
return ui.tableView; return ui.tableView;
} }

View file

@ -14,17 +14,15 @@ TagWidget::TagWidget(QWidget *parent) : GroupedLineEdit(parent), m_completer(NUL
qreal h, s, l, a; qreal h, s, l, a;
textColor.getHslF(&h, &s, &l, &a); textColor.getHslF(&h, &s, &l, &a);
// I use dark themes // I use dark themes
if (l <= 0.3 ){ // very dark text. get a brigth background if (l <= 0.3 ) { // very dark text. get a brigth background
addColor( QColor(Qt::red).lighter(120) ); addColor( QColor(Qt::red).lighter(120) );
addColor( QColor(Qt::green).lighter(120) ); addColor( QColor(Qt::green).lighter(120) );
addColor( QColor(Qt::blue).lighter(120) ); addColor( QColor(Qt::blue).lighter(120) );
} } else if ( l <= 0.6 ) { // moderated dark text. get a somewhat brigth background
else if ( l <= 0.6 ){ // moderated dark text. get a somewhat brigth background
addColor( QColor(Qt::red).lighter(60) ); addColor( QColor(Qt::red).lighter(60) );
addColor( QColor(Qt::green).lighter(60) ); addColor( QColor(Qt::green).lighter(60) );
addColor( QColor(Qt::blue).lighter(60) ); addColor( QColor(Qt::blue).lighter(60) );
} } else {
else{
addColor( QColor(Qt::red).darker(120) ); addColor( QColor(Qt::red).darker(120) );
addColor( QColor(Qt::green).darker(120) ); addColor( QColor(Qt::green).darker(120) );
addColor( QColor(Qt::blue).darker(120) ); addColor( QColor(Qt::blue).darker(120) );
@ -80,7 +78,7 @@ void TagWidget::highlight() {
} else if (state == FINDEND) { } else if (state == FINDEND) {
/* Found end of tag */ /* Found end of tag */
if (i > 1) { if (i > 1) {
if(text().at(i-1) != '\\') { if (text().at(i-1) != '\\') {
addBlock(start, end); addBlock(start, end);
state = FINDSTART; state = FINDSTART;
} }
@ -125,10 +123,9 @@ void TagWidget::reparse()
QAbstractItemView *popup = m_completer->popup(); QAbstractItemView *popup = m_completer->popup();
if (popup) if (popup)
popup->hide(); popup->hide();
} } else {
else
m_completer->complete(); m_completer->complete();
}
} else { } else {
m_completer->complete(); m_completer->complete();
} }
@ -141,8 +138,7 @@ void TagWidget::completionSelected(QString completion) {
if (pos.first >= 0 && pos.second > 0) { if (pos.first >= 0 && pos.second > 0) {
setText(text().remove(pos.first, pos.second-pos.first).insert(pos.first, completion)); setText(text().remove(pos.first, pos.second-pos.first).insert(pos.first, completion));
setCursorPosition(pos.first+completion.length()); setCursorPosition(pos.first+completion.length());
} } else {
else {
setText(completion.append(", ")); setText(completion.append(", "));
setCursorPosition(text().length()); setCursorPosition(text().length());
} }