Author Archives: nanzt

Qs on OMS

1. introduce something about OMS
2. if there is a generic model interface, with which, any hydrological
models can be easily plugged in the system
3. integrate models together, such as hydrological, ecological and economic
models. How to implement?
4. any example on developing DSS on top of OMS?
5. any ideas on how to build a practical SDSS?
6. how to incorporate expert system into a DSS system? its presentation,
functions, etc.

7. does OMS support graphically model composition as MMS does?
yes, but implement in a tree organization. the graphic build is
underconstruction.
8. the OMS/JavaBean framework same as the JavaBean IDE?
no. the framework is based on the IDE, with a major extension.
9. is it too complicated as a DSS?
the purpose of OMS is not to be a DSS. It provides a flexible framework to
build a hydrological model.

10. 对于模型计算过程中的状态变化,可以采用程序调试时的debug模式,将重要变量
以列表方式表示出来。很不错。OMS是这样做的。

11. How about the efficiency compiling and running under Java virtual
machine?
it’s a little bit slower than MMS. But it is affordable for current
computers.
12. How to incorporate GIS functions?
13. Is the latest version available through Internet?
No.

顺便帖两张Colorado State Univ的校园照吧,很漂亮,跟国内的大学没法子比。

Qt中的事件

Qt中的事件
giscn[at]msn[dot]com
 
1.事件的来源
来源于a)windows系统的事件,经Qt的包装(如QMouseEvent);b)Qt内置的事件(如
QTimerEvent);c)应用程序自定义的事件
 
2.处理事件的位置
2.1 重载虚拟方法
比如一个按钮,要自定义左键click时的行为,可以这样做:
a. 从一个QPushButton上派生一个子类如MyPushButton
b. 重载void MyPushButton::mousePressEvent(QMouseEvent *event)
* 一般来讲,除非要重新改写这个事件的默认行为,否则如果仅是为了扩展其功能,最好在
函数的最后call默认的父类处理方法,如QPushButton::mousePressEvent(event);
* 在调用mousePressEvent这些特定的事件前,先调用通用事件处理函数,QObject::event()
。因此,对于一些特殊情况,我们必须要重定义event(),如我们要对tab键进行重定义。默
认的tab键是将focus移到下一个widget上去。比如在一个text edit widget里,我们可能希
望tab键是向右形成一个置表位置,这时需要在text edit widget的event()进行处理。
2.2 event filter(事件过滤器)方法
一个对象的event filter的处理优先级在 该对象的 event()方法调用之前。这时,filter对
象的eventFilter()方法被调用
* 使用QCoreApplication的事件过滤,可以将任何事件在进行具体对象之前,进行处理。但
需要注意,这可能会使得整个事件处理过程变慢。
  • Reimplementing QCoreApplication::notify. This is very powerful, providing complete control; but only one subclass can be active at a time.
  • Installing an event filter on QCoreApplication::instance(). Such an event filter is able to process all events for all widgets, so it’s just as powerful as reimplementing notify(); furthermore, it’s possible to have more than one application-global event filter. Global event filters even see mouse events for disabled widgets.
  • Reimplementing QObject::event() (as QWidget does). If you do this you get Tab key presses, and you get to see the events before any widget-specific event filters.
  • Installing an event filter on the object. Such an event filter gets all the events except Tab and Shift-Tab key presses.
  • Reimplementing paintEvent(), mousePressEvent() and so on. This is the commonest, easiest and least powerful way.
3. 自定义事件
3.1 自定义事件从QEvent派出,该event number必须大于QEvent::User
3.2 使用postEvent和sendEvent方法派遣自定义事件
* postEvent实质是将事件推进事件循环(event loop),马上返回。事件的实际发送可能在稍
后的一个事件处理时钟内。
* 在某种意义上,程序可以直接调用对象的对应事件函数,而绕过postEvent。但存在不足,
a)很多事件处理函数是protected,意味着你不能直接调用;b)这种直接调用将绕过event
filter;Qt的解决方法是sendEvent。比如repaint()实质是调用了sendEvent。
* sendEvent等待事件被发送成功或失败后才返回。
* postEvent的一个好处是多个posted的event可以被压缩成单一的event,从而提高了效率。
* 可以使用QCoreApplication::sendPostedEvents强迫Qt马上进入事件循环(event loop)派
遣事件。
 
4. 事件的传播(propogation)
如果事件在目标对象上得不到处理,事件向上一层进行传播,直到最顶层的widget为止。
如果得到事件的对象,调用了accept(),则事件停止继续传播;如果调用了ignore(),事件向上一级继续传播。
Qt对自定义事件处理函数的默认返回值是accept(),但默认的事件处理函数是ingore()。因此,如果要继续向上传播,调用QWidget的默认处理函数即可。到时为止的话,不必显式调用accept()。
但在event处理函数里,返回true表示accept,返回false表示向上级传播。
* 在closeEvent是个特殊情形,accept表示quit,ignore表示取消,所以最好在closeEvent显式调用accept和ignore。
 
5. tips
5.1 使用event->type得到事件的具体类型,对之进行判断,是否是需要的类型(比如
KeyPress),然后进行相应处理
5.2 使用static_cast<specific event type *>对通用事件转换成特定类型,比如将event转
成QKeyEvent *,然后调用QKeyEvent::key()取得按下什么键。
5.3 使用sendEvent时,参数 event,必须是局部变量,因为sendEvent不负责对event的删除
。而postEvent的event参数,则必须是 new分配的heap对象,post完了后会自动删除。

台风登陆乐清

前面的台风才刚过去(叫什么来着,将我媳妇困在家里回不来单位),“麦莎”又来
了,据称在乐清登陆,风力是建国以来最大。94年我经历了一次据当地老人讲是50年难
遇一次的台风(从而导致海堤崩溃,海水倒灌淹没一层楼房),怎么这次又出来建国以
来最大的了,估计我们家又已经泡水了。这天气是怎么了?据称已经造成2人死亡!甚
念家人,不知道是否都安好。
这个气候是很异常,以前也有台风吧,但好象没有现在这么厉害,再这样下去,若干年
后温州、乐清这些沿海城市都不能再住人了。我爸老说,这个气候星象跟社会时局每每
对应,莫非也象征或者暗示着什么? 当然迷信了,不去管他。但愿家乡父老乡亲都安
好!

好东西一定要推荐给大家,picasa 2

google的一个免费相片管理软件。支持相片的多种方式组织、查找、很实用体贴的编辑(最傻瓜型的了),甚至包括酷酷的刻盘(自带slideshow)、email、形成website、直接发送到好友或blog(通过一个叫hello的程序)等功能。你一定会喜欢。
我使用它挑拣了255张照片,利用其自带的刻盘功能,刻了一张送给Richard,随便也体验一下上述的各种功能。真是很不错。
软件名叫picasa 2,下载地址见http://picasa.google.com/
下图是其自动创建的piled pic collage。

QString与printf的%s

qt 4里
QString str("hello");
printf("%s
", str.data()); //只打印出h
//这是由于在qt4里每个char存留unicode,第二字节为零
解决方法
1. printf("%s
", qPrintable(str));
//qPrintable在qt文档里没有出现,但可在其源码里发现
2. printf("%s
", str.toLatin1());
//toLatin1,toUtf8,toLocal8bit返回QByteArray,可以自动转成 char*

a NICE day

早上送走了小吴,起个大早,回来补了个觉。
下午到Sloans Lake
Park,有龙舟比赛,参赛队大概4、50只,包括游人达7万多人(没有看到官方资料,看宣传小册上的),遗憾的是DFC队老早就被淘汰下来了。意外的看
到好几个中国人组成的队。到Denver后今天是看到中国人最多的一次了,很多亚洲人的面孔。在Arts
stage又注意到一群学校的孩子在表演中国功夫(不确定,不过看样子看是中国功夫),正为中国功夫被国外接受而有点感动的时候,突然想到,在10年前中
国龙舟也时有在大陆进行比赛,很是热闹,如今呢,国人好象忙于搞现代化建设,将传统的东西搁到一边了,反而在太平洋对岸的这里又看着了如此大规模的龙舟赛
事。想起在天涯上看到一个日志,美国由不同国度来的人组成了,他们可能不爱他们自己的国家,但都拥护美国,是什么原因,难道不值得大家思考。
晚上去参加了Richard儿子的一个Potluck party,很是尽兴。跟老外混在一起有个好处,就是可以感受一些很西方的东西,这是整天跟中国人呆在一起所没有。


跟Prof Tj Zhang约好下周到mountain hiking去。
看到一个tutorist穿的t-shirt,很有意思,偷拍了一张,共享之。

pm v2.21

一个用于帮助摘录和回忆英文句子的小软件,占系统资源极小,启动极快。目的单一,就是对研究生撰写英文科技文章有帮助,帮助多少,看你自己的利用程度了,至少对于我本人来讲,很实用的东西。
没有帮助文档,没有中文界面,我只是业余抽空改改这个东西,没有计划整成一个商业的东西,sorry,这些要求概不理会,这么简单的没几个按钮,自己多试试就搞定了。
有Bug和评论的当然可以写信到 giscn_at_msn_dot_com,下载Url也请写信到此地址,自有回复。谢谢大家关心。

v2.2.1 [Jul-17-05]
# fix: when change the screen font size, an asterisk mark will show and save action activated.
# fix: the anno will save as the last line regardless of the last being
blank. Now the anno will be saved as the last non-blank line.
# fixed when closing the app with unsaved modification, clicking no will also exit the app.
# fixed search control cannot type in quote marks (")
+ added a button to adjust the font size
+ added a search functionality in the context menu
* other improvements