Skip to content
Permalink
Browse files

Use save/restoreGeometry introduced in Qt4.2 rather than saving width…

…, 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/qgis@7696 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
telwertowski
telwertowski committed Dec 1, 2007
1 parent 226494c commit 58feb4b82956c08ff80f0ff396b5c6a6e42b4095
@@ -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()
@@ -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 ///////////////

@@ -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)
@@ -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)
@@ -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 */
@@ -144,8 +144,7 @@ void QgsMeasureDialog::addPoint(QgsPoint &point)
void QgsMeasureDialog::close(void)
{
restart();
saveWindowLocation();
hide();
QDialog::close();
}

void QgsMeasureDialog::closeEvent(QCloseEvent *e)
@@ -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()
@@ -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()
@@ -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 )
@@ -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 )
@@ -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());
}

@@ -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;
@@ -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()
@@ -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" >

0 comments on commit 58feb4b

Please sign in to comment.
You can’t perform that action at this time.