Skip to content

Commit 49cf5a9

Browse files
author
jef
committed
apply (slightly modified) #3512
git-svn-id: http://svn.osgeo.org/qgis/trunk@15225 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 08f207f commit 49cf5a9

File tree

6 files changed

+161
-100
lines changed

6 files changed

+161
-100
lines changed

src/app/qgstip.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/***************************************************************************
2-
* Copyright (C) 2007 by Tim Sutton *
3-
* tim@linfiniti.com *
2+
* Copyright (C) 2007 by Tim Sutton *
3+
* tim@linfiniti.com *
44
* *
55
* This program is free software; you can redistribute it and/or modify *
66
* it under the terms of the GNU General Public License as published by *
@@ -25,15 +25,15 @@
2525
#include <QString>
2626

2727
/** \ingroup app
28-
* \brief An QgsTip represents a tip generated by the
28+
* \brief An QgsTip represents a tip generated by the
2929
* QgsTipFactory factory class to serve up tips to the user.
3030
* Tips can be generic, in which case they make no mention of
3131
* gui dialogs etc, or gui-secific in which case they may allude
3232
* to features of the graphical user interface.
3333
* @see also QgsTipOfTheDay, QgsTipFactory
3434
*/
3535

36-
class QgsTip
36+
class QgsTip
3737
{
3838
public:
3939
/** Constructor */
@@ -47,14 +47,14 @@ class QgsTip
4747
QString title() {return mTitle;};
4848
/** Get the tip content */
4949
QString content() {return mContent;}
50-
50+
5151
//
5252
// Mutators
5353
//
5454
/** Set the tip title */
55-
void setTitle(QString theTitle) {mTitle = theTitle;};
55+
void setTitle( QString theTitle ) {mTitle = theTitle;};
5656
/** Set the tip content*/
57-
void setContent(QString theContent) {mContent = theContent;};
57+
void setContent( QString theContent ) {mContent = theContent;};
5858
private:
5959
QString mTitle;
6060
QString mContent;

src/app/qgstipfactory.cpp

Lines changed: 88 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/***************************************************************************
2-
* Copyright (C) 2007 by Tim Sutton *
3-
* tim@linfiniti.com *
2+
* Copyright (C) 2007 by Tim Sutton *
3+
* tim@linfiniti.com *
44
* *
55
* This program is free software; you can redistribute it and/or modify *
66
* it under the terms of the GNU General Public License as published by *
@@ -27,66 +27,66 @@
2727

2828
QgsTipFactory::QgsTipFactory() : QObject()
2929
{
30-
// Im just doing this in a simple way so
30+
// I'm just doing this in a simple way so
3131
// its easy for translators...later
3232
// it its worth the time Ill move this data
3333
// into a sqlite database...
3434
QgsTip myTip;
35-
myTip.setTitle(tr("Quantum GIS is open source"));
36-
myTip.setContent(tr("Quantum GIS is open source software."
37-
" This means that the software source code can be freely viewed "
38-
" and modified. The GPL places a restriction that any modifications "
39-
" you make must be made available to the Quantum GIS project, and "
40-
" that you can not create a new version of Quantum GIS under a "
41-
" 'closed source' license. Visit <a href=\"http://qgis.org\">"
42-
" the QGIS home page (http://qgis.org)</a> for more"
43-
" information."));
44-
addGenericTip(myTip);
35+
myTip.setTitle( tr( "Quantum GIS is open source" ) );
36+
myTip.setContent( tr( "Quantum GIS is open source software."
37+
" This means that the software source code can be freely viewed "
38+
" and modified. The GPL places a restriction that any modifications "
39+
" you make must be made available to the Quantum GIS project, and "
40+
" that you can not create a new version of Quantum GIS under a "
41+
" 'closed source' license. Visit <a href=\"http://qgis.org\">"
42+
" the QGIS home page (http://qgis.org)</a> for more"
43+
" information." ) );
44+
addGenericTip( myTip );
4545
//
46-
myTip.setTitle(tr("QGIS Publications"));
47-
myTip.setContent(tr("If you write a scientific paper or any other article"
48-
" that refers to QGIS we would love to include your work"
49-
" in the <a href=\"http://www.qgis.org/en/community/qgis-case-studies.html\">case studies section</a> of"
50-
" the Quantum GIS home page (http://http://www.qgis.org/en/community/qgis-case-studies.html)."
51-
));
52-
addGenericTip(myTip);
53-
myTip.setTitle(tr("Become an QGIS translator"));
54-
myTip.setContent(tr("Would you like to see QGIS"
55-
" in your native language? We are looking for more translators"
56-
" and would appreciate your help! The translation process is "
57-
" fairly straight forward - instructions are available in the "
58-
" QGIS wiki"
59-
" <a href=\"http://www.qgis.org/wiki/GUI_Translation\">translator's page (http://www.qgis.org/wiki/GUI_Translation).</a>"
60-
));
61-
addGuiTip(myTip);
62-
myTip.setTitle(tr("QGIS Mailing lists"));
63-
myTip.setContent(tr("If you need help using QGIS"
64-
" we have a 'users' mailing list where users help each other with issues"
65-
" related to using our sofware. We also have a 'developers' mailing list."
66-
" for those wanting help and to discuss things relating the the QGIS code base."
67-
" Details on how to subscribe are in the <a href=\"http://www.qgis.org/en/community/mailing-lists.html\">community section</a> of"
68-
" the QGIS home page (http://www.qgis.org/en/community/mailing-lists.html)."
69-
));
70-
addGuiTip(myTip);
71-
myTip.setTitle(tr("Is it 'QGIS' or 'Quantum GIS'?"));
72-
myTip.setContent(tr("Both are correct. For articles we suggest you write 'Quantum GIS (QGIS) is ....'"
73-
" and then refer to it as QGIS thereafter."
74-
));
75-
addGenericTip(myTip);
76-
myTip.setTitle(tr("How do I refer to Quantum GIS?"));
77-
myTip.setContent(tr("QGIS is spelled in all caps."
78-
" We have various subprojects of the QGIS project "
79-
" and it will help to avoid confusion if you refer to each by"
80-
" its name:"
81-
"<ul>"
82-
"<li>QGIS Library - this is the C++ library that contains"
83-
" the core logic that is used to build the QGIS user interface and other applications.</li>"
84-
"<li>QGIS Application - this is the desktop application that you know and love so much :-).</li>"
85-
"<li>QGIS Mapserver - this is a server-side application based on the QGIS Library"
86-
" that will serve up your .qgs projects using the WMS protocol.</li>"
87-
"</ul>"
88-
));
89-
addGenericTip(myTip);
46+
myTip.setTitle( tr( "QGIS Publications" ) );
47+
myTip.setContent( tr( "If you write a scientific paper or any other article"
48+
" that refers to QGIS we would love to include your work"
49+
" in the <a href=\"http://www.qgis.org/en/community/qgis-case-studies.html\">case studies section</a> of"
50+
" the Quantum GIS home page (http://http://www.qgis.org/en/community/qgis-case-studies.html)."
51+
) );
52+
addGenericTip( myTip );
53+
myTip.setTitle( tr( "Become an QGIS translator" ) );
54+
myTip.setContent( tr( "Would you like to see QGIS"
55+
" in your native language? We are looking for more translators"
56+
" and would appreciate your help! The translation process is "
57+
" fairly straight forward - instructions are available in the "
58+
" QGIS wiki"
59+
" <a href=\"http://www.qgis.org/wiki/GUI_Translation\">translator's page (http://www.qgis.org/wiki/GUI_Translation).</a>"
60+
) );
61+
addGuiTip( myTip );
62+
myTip.setTitle( tr( "QGIS Mailing lists" ) );
63+
myTip.setContent( tr( "If you need help using QGIS"
64+
" we have a 'users' mailing list where users help each other with issues"
65+
" related to using our sofware. We also have a 'developers' mailing list."
66+
" for those wanting help and to discuss things relating the the QGIS code base."
67+
" Details on how to subscribe are in the <a href=\"http://www.qgis.org/en/community/mailing-lists.html\">community section</a> of"
68+
" the QGIS home page (http://www.qgis.org/en/community/mailing-lists.html)."
69+
) );
70+
addGuiTip( myTip );
71+
myTip.setTitle( tr( "Is it 'QGIS' or 'Quantum GIS'?" ) );
72+
myTip.setContent( tr( "Both are correct. For articles we suggest you write 'Quantum GIS (QGIS) is ....'"
73+
" and then refer to it as QGIS thereafter."
74+
) );
75+
addGenericTip( myTip );
76+
myTip.setTitle( tr( "How do I refer to Quantum GIS?" ) );
77+
myTip.setContent( tr( "QGIS is spelled in all caps."
78+
" We have various subprojects of the QGIS project "
79+
" and it will help to avoid confusion if you refer to each by"
80+
" its name:"
81+
"<ul>"
82+
"<li>QGIS Library - this is the C++ library that contains"
83+
" the core logic that is used to build the QGIS user interface and other applications.</li>"
84+
"<li>QGIS Application - this is the desktop application that you know and love so much :-).</li>"
85+
"<li>QGIS Mapserver - this is a server-side application based on the QGIS Library"
86+
" that will serve up your .qgs projects using the WMS protocol.</li>"
87+
"</ul>"
88+
) );
89+
addGenericTip( myTip );
9090
/* Template for adding more tips
9191
myTip.setTitle(tr(""));
9292
myTip.setContent(tr(""
@@ -100,48 +100,65 @@ QgsTipFactory::~QgsTipFactory()
100100

101101
}
102102
//private helper method
103-
void QgsTipFactory::addGuiTip(QgsTip theTip)
103+
void QgsTipFactory::addGuiTip( QgsTip theTip )
104104
{
105105
mGuiTips << theTip;
106106
mAllTips << theTip;
107107
}
108108
//private helper method
109-
void QgsTipFactory::addGenericTip(QgsTip theTip)
109+
void QgsTipFactory::addGenericTip( QgsTip theTip )
110110
{
111111
mGenericTips << theTip;
112112
mAllTips << theTip;
113113
}
114114
QgsTip QgsTipFactory::getTip()
115115
{
116-
srand(QTime::currentTime().msec());
116+
srand( QTime::currentTime().msec() );
117117
int myRand = rand();
118-
int myValue = static_cast<int> (myRand % mAllTips.count()); //range [0,(count-1)]
119-
QgsTip myTip = mAllTips.at(myValue);
118+
int myValue = static_cast<int>( myRand % mAllTips.count() ); //range [0,(count-1)]
119+
QgsTip myTip = mAllTips.at( myValue );
120120
return myTip;
121121
}
122-
QgsTip QgsTipFactory::getTip(int thePosition)
122+
QgsTip QgsTipFactory::getTip( int thePosition )
123123
{
124-
QgsTip myTip = mAllTips.at(thePosition);
124+
QgsTip myTip = mAllTips.at( thePosition );
125125
return myTip;
126126
}
127127
QgsTip QgsTipFactory::getGenericTip()
128128
{
129-
srand(QTime::currentTime().msec());
129+
srand( QTime::currentTime().msec() );
130130
int myRand = rand();
131-
int myValue = static_cast<int> (myRand % mGenericTips.count()); //range [0,(count-1)]
132-
QgsTip myTip = mGenericTips.at(myValue);
131+
int myValue = static_cast<int>( myRand % mGenericTips.count() ); //range [0,(count-1)]
132+
QgsTip myTip = mGenericTips.at( myValue );
133133
return myTip;
134134
}
135135
QgsTip QgsTipFactory::getGuiTip()
136136
{
137-
srand(QTime::currentTime().msec());
137+
srand( QTime::currentTime().msec() );
138138
int myRand = rand();
139-
int myValue = static_cast<int> (myRand % mGuiTips.count()); //range [0,(count-1)]
140-
QgsTip myTip = mGuiTips.at(myValue);
139+
int myValue = static_cast<int>( myRand % mGuiTips.count() ); //range [0,(count-1)]
140+
QgsTip myTip = mGuiTips.at( myValue );
141141
return myTip;
142142
}
143-
int QgsTipFactory::randomNumber(int theMax)
143+
int QgsTipFactory::randomNumber( int theMax )
144144
{
145145
return 0;
146146
}
147147

148+
int QgsTipFactory::position( QgsTip tip )
149+
{
150+
for ( int i = 0; i < mAllTips.count(); ++i )
151+
{
152+
QgsTip myTip = mAllTips.at( i );
153+
if ( myTip.title() == tip.title() )
154+
{
155+
return i;
156+
}
157+
}
158+
return -1;
159+
}
160+
161+
int QgsTipFactory::count()
162+
{
163+
return mAllTips.count();
164+
}

src/app/qgstipfactory.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/***************************************************************************
2-
* Copyright (C) 2007 by Tim Sutton *
3-
* tim@linfiniti.com *
2+
* Copyright (C) 2007 by Tim Sutton *
3+
* tim@linfiniti.com *
44
* *
55
* This program is free software; you can redistribute it and/or modify *
66
* it under the terms of the GNU General Public License as published by *
@@ -32,9 +32,9 @@
3232
* @see also QgsTipOfTheDay, QgsTip
3333
*/
3434

35-
class QgsTipFactory : public QObject
35+
class QgsTipFactory : public QObject
3636
{
37-
Q_OBJECT; //used for tr() so we dont need to do QObject::tr()
37+
Q_OBJECT //used for tr() so we dont need to do QObject::tr()
3838
public:
3939
/** Constructor */
4040
QgsTipFactory();
@@ -45,13 +45,13 @@ class QgsTipFactory : public QObject
4545
*/
4646
QgsTip getTip();
4747
/** Get a specific tip (generic or gui-centric).
48-
* @param thePosition The tip returned will be based on the
48+
* @param thePosition The tip returned will be based on the
4949
* number passed in as thePosition. If the
50-
* position is invalid, an empty string will be
50+
* position is invalid, an empty string will be
5151
* returned.
5252
* @return An QgsTip containing the tip
5353
*/
54-
QgsTip getTip(int thePosition);
54+
QgsTip getTip( int thePosition );
5555
/** Get a random generic tip
5656
* @return An QgsTip containing the tip
5757
*/
@@ -61,10 +61,13 @@ class QgsTipFactory : public QObject
6161
*/
6262
QgsTip getGuiTip();
6363

64+
int position( QgsTip );
65+
int count();
66+
6467
private:
65-
void addGenericTip(QgsTip);
66-
void addGuiTip(QgsTip);
67-
int randomNumber(int theMax);
68+
void addGenericTip( QgsTip );
69+
void addGuiTip( QgsTip );
70+
int randomNumber( int theMax );
6871
//@TODO move tipts into a sqlite db
6972
QList <QgsTip> mGenericTips;
7073
QList <QgsTip> mGuiTips;

src/app/qgstipgui.cpp

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
/* $Id$ */
1818

1919
#include <QSettings>
20+
#include <QPushButton>
21+
2022
#include "qgstipgui.h"
2123
#include "qgsapplication.h"
2224
#include <qgstip.h>
@@ -46,16 +48,51 @@ void QgsTipGui::init()
4648
qgisIcon->setPixmap( icon );
4749
QgsTipFactory myFactory;
4850
QgsTip myTip = myFactory.getTip();
49-
lblTitle->setText(myTip.title());
50-
txtTip->setHtml(myTip.content());
51+
mTipPosition = myFactory.position( myTip );
52+
lblTitle->setText( myTip.title() );
53+
txtTip->setHtml( myTip.content() );
54+
55+
QPushButton *pb;
56+
pb = new QPushButton( tr( "&Previous" ) );
57+
connect( pb, SIGNAL( clicked() ), this, SLOT( prevClicked() ) );
58+
buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
5159

60+
pb = new QPushButton( tr( "&Next" ) );
61+
connect( pb, SIGNAL( clicked() ), this, SLOT( nextClicked() ) );
62+
buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
5263
}
5364

54-
void QgsTipGui::on_cbxDisableTips_toggled(bool theFlag)
65+
void QgsTipGui::on_cbxDisableTips_toggled( bool theFlag )
5566
{
5667
QSettings settings;
57-
//note the ! below as when the cbx is checked (true) we want to
68+
//note the ! below as when the cbx is checked (true) we want to
5869
//change the setting to false
5970
settings.setValue( "/qgis/showTips", !theFlag );
6071
hide();
6172
}
73+
74+
void QgsTipGui::nextClicked()
75+
{
76+
mTipPosition += 1;
77+
QgsTipFactory myFactory;
78+
if ( mTipPosition >= myFactory.count() )
79+
{
80+
mTipPosition = 0;
81+
}
82+
QgsTip myTip = myFactory.getTip( mTipPosition );
83+
lblTitle->setText( myTip.title() );
84+
txtTip->setHtml( myTip.content() );
85+
}
86+
87+
void QgsTipGui::prevClicked()
88+
{
89+
mTipPosition -= 1;
90+
QgsTipFactory myFactory;
91+
if ( mTipPosition < 0 )
92+
{
93+
mTipPosition = myFactory.count() - 1;
94+
}
95+
QgsTip myTip = myFactory.getTip( mTipPosition );
96+
lblTitle->setText( myTip.title() );
97+
txtTip->setHtml( myTip.content() );
98+
}

src/app/qgstipgui.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ class QgsTipGui : public QDialog, private Ui::QgsTipGuiBase
3030
private:
3131
void init();
3232

33+
int mTipPosition;
34+
3335
private slots:
34-
void on_cbxDisableTips_toggled(bool theFlag);
36+
void on_cbxDisableTips_toggled( bool theFlag );
37+
void prevClicked();
38+
void nextClicked();
3539
};
3640

3741
#endif

0 commit comments

Comments
 (0)