Skip to content

Commit

Permalink
Use save/restoreGeometry introduced in Qt4.2 rather than saving width…
Browse files Browse the repository at this point in the history
…, height, x and y as separate parameters. The new functions support multiple monitors and will restore a window to a visible location if it was saved at a location that is no longer visible. Fix for bug #440.

git-svn-id: http://svn.osgeo.org/qgis/trunk@7696 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
telwertowski committed Dec 1, 2007
1 parent f76c0d2 commit cbaff6a
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 169 deletions.
39 changes: 4 additions & 35 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -917,47 +917,16 @@ void QgsComposer::resizeEvent ( QResizeEvent *e )

void QgsComposer::saveWindowState()
{
#ifdef QGISDEBUG
std::cout << "QgsComposer::saveWindowState" << std::endl;
#endif

QSettings settings;

QPoint p = this->pos();
QSize s = this->size();

settings.writeEntry("/Composer/geometry/x", p.x());
settings.writeEntry("/Composer/geometry/y", p.y());
settings.writeEntry("/Composer/geometry/w", s.width());
settings.writeEntry("/Composer/geometry/h", s.height());

settings.setValue("/Composer/geometry/splitter", mSplitter->saveState());

if(this->isMaximized()){
std::cout << "maximized!" << std::endl;
}
settings.setValue("/Composer/geometry", saveGeometry());
settings.setValue("/Composer/splitterState", mSplitter->saveState());
}

void QgsComposer::restoreWindowState()
{

QSettings settings;

QDesktopWidget *d = QApplication::desktop();
int dw = d->width();
int dh = d->height();
int w = settings.readNumEntry("/Composer/geometry/w", 600);
int h = settings.readNumEntry("/Composer/geometry/h", 400);
int x = settings.readNumEntry("/Composer/geometry/x", (dw - 600) / 2);
int y = settings.readNumEntry("/Composer/geometry/y", (dh - 400) / 2);
resize(w, h);
move(x, y);

//We also need to save the maximized state

//std::cout << "x: " << x << "y: " << y << "w: " << w << "h: " << h << std::endl;

mSplitter->restoreState(settings.value("/Composer/geometry/splitter").toByteArray());
restoreGeometry(settings.value("/Composer/geometry").toByteArray());
mSplitter->restoreState(settings.value("/Composer/splitterState").toByteArray());
}

void QgsComposer::on_helpPButton_clicked()
Expand Down
31 changes: 8 additions & 23 deletions src/app/qgisapp.cpp
Expand Up @@ -1381,40 +1381,25 @@ void QgisApp::saveWindowState()
// store window and toolbar positions
QSettings settings;
// store the toolbar/dock widget settings using Qt4 settings API
settings.setValue("/Geometry/state", this->saveState());
settings.setValue("/UI/state", this->saveState());

// store window geometry
QPoint p = this->pos();
QSize s = this->size();
settings.writeEntry("/Geometry/maximized", this->isMaximized());
settings.writeEntry("/Geometry/x", p.x());
settings.writeEntry("/Geometry/y", p.y());
settings.writeEntry("/Geometry/w", s.width());
settings.writeEntry("/Geometry/h", s.height());
settings.setValue("/Geometry/canvasSplitterState", canvasLegendSplit->saveState());
settings.setValue("/Geometry/legendSplitterState", legendOverviewSplit->saveState());
settings.setValue("/UI/geometry", saveGeometry());
settings.setValue("/UI/canvasSplitterState", canvasLegendSplit->saveState());
settings.setValue("/UI/legendSplitterState", legendOverviewSplit->saveState());
}

void QgisApp::restoreWindowState()
{
// restore the toolbar and dock widgets postions using Qt4 settings API
QSettings settings;
QVariant vstate = settings.value("/Geometry/state");
QVariant vstate = settings.value("/UI/state");
this->restoreState(vstate.toByteArray());

// restore window geometry
QDesktopWidget *d = QApplication::desktop();
int dw = d->width(); // returns desktop width
int dh = d->height(); // returns desktop height
int w = settings.readNumEntry("/Geometry/w", 600);
int h = settings.readNumEntry("/Geometry/h", 400);
int x = settings.readNumEntry("/Geometry/x", (dw - 600) / 2);
int y = settings.readNumEntry("/Geometry/y", (dh - 400) / 2);
resize(w, h);
move(x, y);

canvasLegendSplit->restoreState(settings.value("/Geometry/canvasSplitterState").toByteArray());
legendOverviewSplit->restoreState(settings.value("/Geometry/legendSplitterState").toByteArray());
restoreGeometry(settings.value("/UI/geometry").toByteArray());
canvasLegendSplit->restoreState(settings.value("/UI/canvasSplitterState").toByteArray());
legendOverviewSplit->restoreState(settings.value("/UI/legendSplitterState").toByteArray());
}
///////////// END OF GUI SETUP ROUTINES ///////////////

Expand Down
16 changes: 2 additions & 14 deletions src/app/qgsattributedialog.cpp
Expand Up @@ -98,13 +98,7 @@ bool QgsAttributeDialog::queryAttributes(const QgsFieldMap& fields, QgsFeature&
void QgsAttributeDialog::savePositionAndColumnWidth()
{
QSettings settings;
QPoint p = this->pos();
QSize s = this->size();
settings.writeEntry(_settingsPath+"x", p.x());
settings.writeEntry(_settingsPath+"y", p.y());
settings.writeEntry(_settingsPath+"w", s.width());
settings.writeEntry(_settingsPath+"h", s.height());

settings.setValue(_settingsPath+"geometry", saveGeometry());
}

void QgsAttributeDialog::resizeEvent(QResizeEvent *event)
Expand All @@ -122,13 +116,7 @@ void QgsAttributeDialog::moveEvent(QMoveEvent *event)
void QgsAttributeDialog::restorePositionAndColumnWidth()
{
QSettings settings;
int ww = settings.readNumEntry(_settingsPath+"w", 281);
int wh = settings.readNumEntry(_settingsPath+"h", 316);
int wx = settings.readNumEntry(_settingsPath+"x", 100);
int wy = settings.readNumEntry(_settingsPath+"y", 100);

resize(ww,wh);
move(wx,wy);
restoreGeometry(settings.value(_settingsPath+"geometry").toByteArray());
}

void QgsAttributeDialog::setAttributeValueChanged(int row, int column)
Expand Down
14 changes: 3 additions & 11 deletions src/app/qgsidentifyresults.cpp
Expand Up @@ -152,24 +152,16 @@ void QgsIdentifyResults::contextMenuEvent(QContextMenuEvent* event)
// Restore last window position/size and show the window
void QgsIdentifyResults::restorePosition()
{

QSettings settings;
QPoint pos = settings.value("/Windows/Identify/pos",
QPoint(100,100)).toPoint();
QSize size = settings.value("/Windows/Identify/size",
QSize(281,316)).toSize();
//std::cerr << "Setting geometry: " << wx << ", " << wy << ", " << ww << ", " << wh << std::endl;
resize(size);
move(pos);
restoreGeometry(settings.value("/Windows/Identify/geometry").toByteArray());
show();
//std::cerr << "Current geometry: " << x() << ", " << y() << ", " << width() << ", " << height() << std::endl;
}

// Save the current window location (store in ~/.qt/qgisrc)
void QgsIdentifyResults::saveWindowLocation()
{
QSettings settings;
settings.setValue("/Windows/Identify/pos", this->pos());
settings.setValue("/Windows/Identify/size", this->size());
settings.setValue("/Windows/Identify/geometry", saveGeometry());
}

/** add an attribute and its value to the list */
Expand Down
29 changes: 8 additions & 21 deletions src/app/qgsmeasuredialog.cpp
Expand Up @@ -144,8 +144,7 @@ void QgsMeasureDialog::addPoint(QgsPoint &point)
void QgsMeasureDialog::close(void)
{
restart();
saveWindowLocation();
hide();
QDialog::close();
}

void QgsMeasureDialog::closeEvent(QCloseEvent *e)
Expand All @@ -157,35 +156,23 @@ void QgsMeasureDialog::closeEvent(QCloseEvent *e)
void QgsMeasureDialog::restorePosition()
{
QSettings settings;
int ww = settings.readNumEntry("/Windows/Measure/w", 150);
restoreGeometry(settings.value("/Windows/Measure/geometry").toByteArray());
int wh;
if (mMeasureArea)
wh = settings.readNumEntry("/Windows/Measure/hNoTable", 70);
wh = settings.value("/Windows/Measure/hNoTable", 70).toInt();
else
wh = settings.readNumEntry("/Windows/Measure/h", 200);
int wx = settings.readNumEntry("/Windows/Measure/x", 100);
int wy = settings.readNumEntry("/Windows/Measure/y", 100);
// setUpdatesEnabled(false);
adjustSize();
resize(ww,wh);
move(wx,wy);
// setUpdatesEnabled(true);
wh = settings.value("/Windows/Measure/h", 200).toInt();
resize(width(), wh);
updateUi();
this->show();
}

void QgsMeasureDialog::saveWindowLocation()
{
QSettings settings;
QPoint p = this->pos();
QSize s = this->size();
settings.writeEntry("/Windows/Measure/x", p.x());
settings.writeEntry("/Windows/Measure/y", p.y());
settings.writeEntry("/Windows/Measure/w", s.width());
if (mMeasureArea)
settings.writeEntry("/Windows/Measure/hNoTable", s.height());
else
settings.writeEntry("/Windows/Measure/h", s.height());
settings.setValue("/Windows/Measure/geometry", saveGeometry());
const QString &key = mMeasureArea ? "/Windows/Measure/hNoTable" : "/Windows/Measure/h";
settings.setValue(key, height());
}

void QgsMeasureDialog::on_btnHelp_clicked()
Expand Down
17 changes: 2 additions & 15 deletions src/plugins/grass/qgsgrassattributes.cpp
Expand Up @@ -125,15 +125,7 @@ void QgsGrassAttributes::restorePosition()
std::cerr << "QgsGrassAttributes::restorePosition()" << std::endl;
#endif
QSettings settings;
int ww = settings.readNumEntry("/GRASS/windows/attributes/w", 250);
int wh = settings.readNumEntry("/GRASS/windows/attributes/h", 350);
int wx = settings.readNumEntry("/GRASS/windows/attributes/x", 100);
int wy = settings.readNumEntry("/GRASS/windows/attributes/y", 100);
#ifdef QGISDEBUG
std::cerr << "wx = " << wx << " wy = " << wy << std::endl;
#endif
resize(ww,wh);
move(wx,wy);
restoreGeometry(settings.value("/GRASS/windows/attributes/geometry").toByteArray());
}

void QgsGrassAttributes::saveWindowLocation()
Expand All @@ -142,12 +134,7 @@ void QgsGrassAttributes::saveWindowLocation()
std::cerr << "QgsGrassAttributes::saveWindowLocation()" << std::endl;
#endif
QSettings settings;
QPoint p = this->pos();
QSize s = this->size();
settings.writeEntry("/GRASS/windows/attributes/x", p.x());
settings.writeEntry("/GRASS/windows/attributes/y", p.y());
settings.writeEntry("/GRASS/windows/attributes/w", s.width());
settings.writeEntry("/GRASS/windows/attributes/h", s.height());
settings.setValue("/GRASS/windows/attributes/geometry", saveGeometry());
}

int QgsGrassAttributes::addTab ( const QString & label )
Expand Down
14 changes: 2 additions & 12 deletions src/plugins/grass/qgsgrassedit.cpp
Expand Up @@ -794,23 +794,13 @@ void QgsGrassEdit::markerSizeChanged()
void QgsGrassEdit::restorePosition()
{
QSettings settings;
int ww = settings.readNumEntry("/GRASS/windows/edit/w", 420);
int wh = settings.readNumEntry("/GRASS/windows/edit/h", 150);
int wx = settings.readNumEntry("/GRASS/windows/edit/x", 100);
int wy = settings.readNumEntry("/GRASS/windows/edit/y", 100);
resize(ww,wh);
move(wx,wy);
restoreGeometry(settings.value("/GRASS/windows/edit/geometry").toByteArray());
}

void QgsGrassEdit::saveWindowLocation()
{
QSettings settings;
QPoint p = this->pos();
QSize s = this->size();
settings.writeEntry("/GRASS/windows/edit/x", p.x());
settings.writeEntry("/GRASS/windows/edit/y", p.y());
settings.writeEntry("/GRASS/windows/edit/w", s.width());
settings.writeEntry("/GRASS/windows/edit/h", s.height());
settings.setValue("/GRASS/windows/edit/geometry", saveGeometry());
}

void QgsGrassEdit::updateSymb ( void )
Expand Down
14 changes: 2 additions & 12 deletions src/plugins/grass/qgsgrassregion.cpp
Expand Up @@ -480,22 +480,12 @@ void QgsGrassRegion::reject()
void QgsGrassRegion::restorePosition()
{
QSettings settings;
int ww = settings.readNumEntry("/GRASS/windows/region/w", 250);
int wh = settings.readNumEntry("/GRASS/windows/region/h", 350);
int wx = settings.readNumEntry("/GRASS/windows/region/x", 100);
int wy = settings.readNumEntry("/GRASS/windows/region/y", 100);
resize(ww,wh);
move(wx,wy);
restoreGeometry(settings.value("/GRASS/windows/region/geometry").toByteArray());
}

void QgsGrassRegion::saveWindowLocation()
{
QSettings settings;
QPoint p = this->pos();
QSize s = this->size();
settings.writeEntry("/GRASS/windows/region/x", p.x());
settings.writeEntry("/GRASS/windows/region/y", p.y());
settings.writeEntry("/GRASS/windows/region/w", s.width());
settings.writeEntry("/GRASS/windows/region/h", s.height());
settings.setValue("/GRASS/windows/region/geometry", saveGeometry());
}

14 changes: 2 additions & 12 deletions src/plugins/grass/qgsgrassselect.cpp
Expand Up @@ -109,23 +109,13 @@ void QgsGrassSelect::restorePosition()
adjustSize ();

QSettings settings;
int ww = settings.readNumEntry("/GRASS/windows/select/w", 500);
//int wh = settings.readNumEntry("/GRASS/windows/select/h", 100);
int wx = settings.readNumEntry("/GRASS/windows/select/x", 100);
int wy = settings.readNumEntry("/GRASS/windows/select/y", 100);
resize(ww,height());
move(wx,wy);
restoreGeometry(settings.value("/GRASS/windows/select/geometry").toByteArray());
}

void QgsGrassSelect::saveWindowLocation()
{
QSettings settings;
QPoint p = this->pos();
QSize s = this->size();
settings.writeEntry("/GRASS/windows/select/x", p.x());
settings.writeEntry("/GRASS/windows/select/y", p.y());
settings.writeEntry("/GRASS/windows/select/w", s.width());
settings.writeEntry("/GRASS/windows/select/h", s.height());
settings.setValue("/GRASS/windows/select/geometry", saveGeometry());
}

bool QgsGrassSelect::first = true;
Expand Down
14 changes: 2 additions & 12 deletions src/plugins/grass/qgsgrasstools.cpp
Expand Up @@ -409,24 +409,14 @@ void QgsGrassTools::closeEvent(QCloseEvent *e)
void QgsGrassTools::restorePosition()
{
QSettings settings;
int ww = settings.readNumEntry("/GRASS/windows/tools/w", 250);
int wh = settings.readNumEntry("/GRASS/windows/tools/h", 300);
int wx = settings.readNumEntry("/GRASS/windows/tools/x", 100);
int wy = settings.readNumEntry("/GRASS/windows/tools/y", 100);
resize(ww,wh);
move(wx,wy);
restoreGeometry(settings.value("/GRASS/windows/tools/geometry").toByteArray());
show();
}

void QgsGrassTools::saveWindowLocation()
{
QSettings settings;
QPoint p = this->pos();
QSize s = this->size();
settings.writeEntry("/GRASS/windows/tools/x", p.x());
settings.writeEntry("/GRASS/windows/tools/y", p.y());
settings.writeEntry("/GRASS/windows/tools/w", s.width());
settings.writeEntry("/GRASS/windows/tools/h", s.height());
settings.setValue("/GRASS/windows/tools/geometry", saveGeometry());
}

void QgsGrassTools::emitRegionChanged()
Expand Down
4 changes: 2 additions & 2 deletions src/ui/qgsidentifyresultsbase.ui
Expand Up @@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>231</width>
<height>542</height>
<width>281</width>
<height>316</height>
</rect>
</property>
<property name="windowTitle" >
Expand Down

0 comments on commit cbaff6a

Please sign in to comment.